0

members

Easy Basics: Project 072b DS1307 RTC module, SD or micro SD card module, DHT 11 21 22 module

of Acoptex.com in UNO

Basics: Project 072b

Project name: DS1307 RTC module, SD or micro SD card module, DHT 11 21 22 module

Tags: Arduino Uno, DS1307 RTC Module, AT24C32 Real Time Clock, RTC, DS1307 Real Time Clock (RTC) module, I2C, DHT 11 21 22 module, temperature, humidity, temperature and humidity sensor, SD or micro SD card module

Attachments: sketch1, library3,library4library5

In this project, you needed these parts (Dear visitors. You can support our project buy clicking on the links of parts and buying them or donate us to keep this website alive. Thank you):

1.Arduino Uno R3 (you can also use the other version of Arduino)

2. DS1307 Real Time Clock (RTC) module  1pc

3.Arduino IDE ( you can download it from here  )

4.Jumper cables M-M, F-M

5. Lithium Ion battery LIR2032 3.6 VDC or CR12203VDC or CR2032 3VDC (depends on battery holder and module) 1pc

6. DHT11 21 22 Humidity and temperature module 1 pc

7. Resistor 1 pc (10 KOhm)

8. SD card or Micro SD card module 1 pc

or 

9. Micro SD card with SD card adapter 1 pc

 

General

We will learn how to connect DS1307 Real Time Clock (RTC) module, SD or micro SD card module and DHT 11/21/22 module to Arduino board and use them.

We will use the DHT11 to measure temperature and humidity; the real time clock (RTC) module to take date and time; the SD card module to save the data on the SD card.

Understanding the SD card module

You can read more about it here.

Understanding the DHT module

You can read more about them here.

Understanding the DS1307 Real Time Clock (RTC) module

You can read more about them here.

Signals and connections of the DHT module

There are two different versions of the DHT11 you might come across. One type has four pins, and the other type has three pins and is mounted to a small PCB. The PCB mounted version is nice because it includes a surface mounted 10K Ohm pull up resistor for the signal line. Here are the pin outs for both versions:

Signals and connections of the SD card module

Note: depending on the module you’re using, the pins may be in a different order.

VCC (5V)  - connect to 5V pin Arduino Uno. If it is just VCC pin and no 3V3 pin connect VCC to 3.3V pin of Arduino Board

3V3 (or 3.3V) - connect to 3.3V pin Arduino Uno

CS (or SS or D3) (Chip Select or Slave Select) - the pin on each device that the master can use to enable and disable specific devices

MOSI (or DI or SI or CMD) (Master Out Slave In) - The Master line for sending data to the peripherals

CLK (or SCK) (Serial Clock) - The clock pulses which synchronize data transmission generated by the master

MISO (or DO or SO) (Master In Slave Out) - The Slave line for sending data to the master

GND (or G) - ground

CD - this is the Card Detect pin. It shorts to ground when a card is inserted. You should connect a pull up resistor (10K or so) and wire this to another pin if you want to detect when a card is inserted. 

Signals and connections of the DS1307 Real Time Clock (RTC) module

GND - ground pin.

VCC - power supply pin 5V or 3.3V.

SDA - I2C interface data pin.

SCL - I2C interface clock pin.

Wiring

SD or micro SD card module uses SPI communication. Different Arduino boards have different SPI pins. If you’re using another Arduino board, check the Arduino SPI documentation.

DS1307 Real Time Clock (RTC) module uses I2C communication. This means that it communicates with the Arduino using just 2 pins. For Arduino Uno - Serial Data Line (SDA) (Arduino Uno SDA or Analog pin A4) and Serial Clock Line (SCL) (Arduino Uno SCL or Analog pin A5).

If you’re using other Arduino board rather than the Uno, check out what are their SCL and SDA pins.

  • Nano: SDA (A4); SCL(A5)
  • MEGA: SDA (20); SCL(21)
  • Leonardo: SDA (20); SCL(21)

The following picture shows the needed connections with the Arduino Uno 

Step by Step instruction

  1. Most SD cards work right out of the box, but it's possible you have one that was used in a computer or camera and it cannot be read by the SD library. Formatting the card will create a file system that the Arduino can read and write to. It's not desirable to format SD cards frequently, as it shortens their life span. You’ll need a SD reader and computer to format your card. The library supports the FAT16 and FAT32 filesystems, but use FAT16 when possible. See additional info here.
  2. Format the SD card as FAT16 or FAT32. Insert the SD card in your computer. Go to My Computer and right click on the SD card. Select Format...  
  3. A new window pops up. Select FAT32, press Start to initialize the formatting process and follow the onscreen instructions.
  4. Insert the formatted SD card in the SD card module.
  5. Connect the SD card module to the Arduino Uno board.
  6. Solder some header pins if your DS1307 Real Time Clock (RTC) module doesn't have them.
  7. Install backup battery. It will be Lithium Ion battery LIR2032 3.6 VDC or CR12203VDC or CR2032 3VDC (depends on battery holder and module). This allows the module to retain the time, even when it’s not being powered up by the Arduino. This way, every time you turn on and off your module, the time doesn’t reset.
  8. Do wiring. 
  9. Open Arduino IDE.
  10. Plug your Adruino Uno board into your PC and select the correct board and com port
  11. Verify and upload the the sketch to your Adruino Uno
  12. Open serial monitor at 9600 bps.
  13. Let this project run for a few hours to gather a decent amount of data, and when you’re happy with the data logging period, shut down the Arduino and remove the SD from the SD card module.
    Insert the SD card on your computer, open it, and you should have a DATA.txt file with the collected data.
    Run this project run for a few hours to gather a decent amount of data, and when you are happy to stop - shut down the Arduino and remove the SD from the SD card module.
  14. Insert the SD card to your computer, open it, and you should have a DATA.txt file with the collected data.
  15. You can open the data with a text editor, or use a spreadsheet to analyse and process your data.
  16. The data is separated by commas, and each reading is in a new line. In this format, you can easily import data to Excel or other data processing software.

Code

In this code we create a loggingTime() function and a loggingTemperatureHumidity() function that we call in the loop() to log the date, time,temperature and humidity to the DATA.txt file in the SD card.

Summary

We learnt how to connect DS1307 Real Time Clock (RTC) module, SD or micro SD card module and DHT 11/21/22 module to Arduino board and use them.

Libraries:

  • All libraries attached on the begining of the project description.
  • SPI library included in your Arduino IDE.
  • RTClib library. Download, unzip  and add to libraries in our PC, for example C:\Users\toshiba\Documents\Arduino\libraries. This link you can find in Preferences of Adruino IDE program which installed in your PC. You can read about it here.
  • Adafruit_Sensor library included.Download, unzip  and add to libraries in our PC, for example C:\Users\toshiba\Documents\Arduino\libraries. This link you can find in Preferences of Adruino IDE program which installed in your PC. 
  • DHT-sensor library included. You will need to unzip and add the DHT-sensor-library-master library to libraries in your PC, for example C:\Users\toshiba\Documents\Arduino\libraries OR You can install it in Arduino IDE too: select Sketch-> Include library->Manage your libraries->type DHT in Filter your search line and you will see DHT sensor library by Adafruit->More info->select version->install. If it will be problem with compilation - remove 2 files from the library - DHT_U.cpp and DHT_U.h.

Sketch:

  • See attachment on the begining of this project


Other projects of Acoptex.com
Medium Basics: Project 083w Sipeed Maixduino board - Using PlatformIO IDE of Acoptex.com in Sipeed Maixduino 08-08-2019
Medium Basics: Project 083e Sipeed Maixduino board - Uploading MaixPy of Acoptex.com in Sipeed Maixduino 04-08-2019
Medium Basics: Project 083f Sipeed Maixduino board - Using MycroPython of Acoptex.com in Sipeed Maixduino 04-08-2019

Published at 30-05-2018
Viewed: 6244 times