Project tutorial
Simple Information System for Beginners

Simple Information System for Beginners © CC BY-NC-SA

An easy to build information-system that can show time and date, as well as the current temperature.

  • 1,246 views
  • 0 comments
  • 5 respects

Components and supplies

Apps and online services

About this project

After this tutorial, you are able to display the current time and date from your Arduino to an LCD display. And with the press of a button, the temperature and humidity are shown. This project is intended for beginners and also explains how to set up all of the components.

If you want to start directly, jump to the end where you will find the code, as well as the schematic on how to connect all of the parts.

Hardware

To follow this project, you will need the following components:

  • Arduino Uno
  • DHT22 sensor
  • 16x2 LCD with pre-soldered i2c-controller
  • RTC DS3231 module
  • 10 kOhm resistor
  • a button
  • breadboard
  • jumper wires
  • USB-A to B cable

Software

You need to install the Arduino IDE found here: https://www.arduino.cc/en/Main/Software

When you first connect your Arduino, you will be automatically prompted to install the required drivers.

Then, install the following libraries from the library manager inside the Arduino IDE:

  • Adafruit Unified Sensor
  • DHT sensor library
  • LiquidCrystal I2C

Guidance on how to install libraries can be found here: https://www.arduino.cc/en/Guide/Libraries

Find out the hardware address of the LCD

To use the LCD for displaying your information, it is needed to find out its hardware address. To do that, connect the pins of the LCD to the Arduino like that:

  • VCC -> 5V
  • GND -> GND
  • SDA -> A4
  • SCL -> A5

Now that the display is connected, it won't take long and you will have its address. To identify it, open up the Arduino IDE and paste the following code there. Then click on 'upload'.

#include <Wire.h>
void setup() {
Serial.begin (115200);
// Leonardo: wait for serial port to connect
while (!Serial)
{
}
Serial.println ();
Serial.println ("I2C scanner. Scanning ...");
byte count = 0;
Wire.begin();
for (byte i = 8; i < 120; i++)
{
Wire.beginTransmission (i);
if (Wire.endTransmission () == 0)
{
Serial.print ("Found address: ");
Serial.print (i, DEC);
Serial.print (" (0x");
Serial.print (i, HEX);
Serial.println (")");
count++;
delay (1); // maybe unneeded?
} // end of good response
} // end of for loop
Serial.println ("Done.");
Serial.print ("Found ");
Serial.print (count, DEC);
Serial.println (" device(s).");
} // end of setup
void loop() {}

Now open the serial monitor as shown below:

Make sure that the baud rate is set to 115200 in the right corner. Then you should see an output similar to this:

In my case, it found 3 devices, but if you only connected the LCD before, the only shown address is the one from your LCD (in my case it is 0x27). Note that address because we will need it later.

Set up the RTC-Module

You will need an additional library to work with the RTC-module. I used the library from here: http://www.rinkydinkelectronics.com/library.php?id=73

Download the file named DS3231.zip and import it inside the IDE. A guide for importing libraries can be found here: https://www.arduino.cc/en/Guide/Libraries

First, connect the pins of the clock-module to the following pins of the Arduino:

  • VCC -> 5V
  • GND -> GND
  • SDA -> SDA
  • SCL -> SCL
  • SQW -> unused
  • 32K -> unused

The following code gives you the ability to initially set the time of the clock.

#include <DS3231.h>
// Init the DS3231 using the hardware interface
DS3231  rtc(SDA, SCL);
void setup()
{
 // Setup Serial connection
 Serial.begin(115200);
 // Uncomment the next line if you are using an Arduino Leonardo
 //while (!Serial) {}
 // Initialize the rtc object
 rtc.begin();
 // The following lines can be uncommented to set the date and time
 rtc.setDOW(FRIDAY);     // Set Day-of-Week to SUNDAY
 rtc.setTime(12, 00, 0);     // Set the time to 12:00:00 (24hr format)
 rtc.setDate(1, 5, 2020);   // Set the date to May 1st, 2020
}
void loop()
{
 // Send Day-of-Week
 Serial.print(rtc.getDOWStr());
 Serial.print(" ");
 // Send date
 Serial.print(rtc.getDateStr());
 Serial.print(" -- ");
 // Send time
 Serial.println(rtc.getTimeStr());
 // Wait one second before repeating :)
 delay (1000);
}

Copy it inside the Arduino IDE. Then insert your current time and date into lines 13 - 15 as explained in the comments there. Now upload the code to your Arduino and the time is set. After you've done that, comment these three lines and upload the code again, to make sure that the set time won't get overwritten. Now you can open the serial monitor and should be able to see an output similar to this one:

Put all parts together

Now the time has come to get some results and therefore we will assemble all of the parts together. The schematic at the end shows exactly, where you have to put all of the wires. When you've done that, copy the code found at the end inside the IDE and insert the hardware address of the LCD into the following line of the code (0x27 is replaced by your address):

LiquidCrystal_I2C lcd(0x27,16,2); // Init the display as "lcd"

Now it is time to upload the code found below and enjoy the project you just completed. To make it look a bit nicer, I build a case out of lego bricks for my system. So feel free to stay creative and modify this project as you want to.

Code

Code for the final systemArduino
/*Connections (see schematic for more details):
 * 
 * LCD-Display:
 * VCC -> 5V
 * GND -> GND
 * SDA -> A4
 * SCL -> A5
 * 
 * RTC-DS3231:
 * VCC -> 5V
 * GND -> GND
 * SDA -> SDA
 * SCL -> SCL
 * SQW -> unused
 * 32K -> unused
 * 
 * DHT22:
 * + -> 5V
 * - -> GND
 * out -> Digital 2
 * 
 * Button:
 * One end to 5V
 * Other end to Digital Pin 12 and GND via 10K resistor
 */

#include <Wire.h>
#include <DS3231.h> //Library for the rtc-module from RinkyDinkElectronics.com
#include <LiquidCrystal_I2C.h>
#include <DHT.h>

#define DHTPIN 2 //Temperature sensor is connected to PIN 2   
#define DHTTYPE DHT22 // Type of the sensor is DHT22 (AM2302)

DS3231  rtc(SDA, SCL); // Init the DS3231 as "rtc" using the hardware interface
LiquidCrystal_I2C lcd(0x27,16,2); // Init the display as "lcd"
DHT dht(DHTPIN, DHTTYPE); // Init the temperature sensor as "dht"

char inputButtonState; // Variable for button value

void setup() {
  rtc.begin(); // Initialize the rtc object
  lcd.init(); // Initialize the LCD
  lcd.backlight(); // Turn on the backlight (lcd.noBacklight(); turns it off)
  dht.begin(); // Initialize the temperature sensor
  pinMode(12,INPUT); // Initialize Arduino Digital Pin 12 as input for connecting Pushbutton
  lcd.setCursor(0,0); // Set cursor to character one, row one (lcd.setCursor(character,row);)
  lcd.print("Starting... v1"); // Display characters on the LCD
  delay(2000); // Delay for 2 seconds (2000 millisec)
}

void loop() {

  inputButtonState = digitalRead(12); // Read the Pushbutton state from digital pin 12, values are either HIGH or LOW

  lcd.clear(); // Make sure that LCD is clear
  
  do{
    //Clock and Date
    lcd.setCursor(4,0);
    lcd.print(rtc.getTimeStr()); // Display time
    lcd.setCursor(1,1);
    lcd.print(rtc.getDOWStr(1)); // Display Day-of-Week
    lcd.setCursor(7,1);
    lcd.print(rtc.getDateStr(1)); // Display date    
    delay(1000); // Delay until refresh of values (1 sec)
    inputButtonState = digitalRead(12); // Read the Pushbutton state again
    
  }while(inputButtonState != HIGH); // Repeat the retrieval of time and date until button is pressed
  

  lcd.clear(); // Clear the display before new content
  
  do{
    //Temperature and Humidity
    float temp = dht.readTemperature(); // Save the temperature from the sensor in the variable "temp"
    float hum = dht.readHumidity(); // Save the humidity from the sensor in the variable "hum"

    // The following code is similar to the clock section, but now temperature and humidity are displayed
    lcd.setCursor(1,0);
    lcd.print("Temp:");
    lcd.setCursor(8,0);
    lcd.print(temp);
    lcd.setCursor(14,0);
    lcd.print("C");
    lcd.setCursor(1,1);
    lcd.print("Hum :");
    lcd.setCursor(8,1); 
    lcd.print(hum);
    lcd.setCursor(14,1);
    lcd.print("%");
    delay(2000);
    inputButtonState = digitalRead(12);
      
  }while(inputButtonState != HIGH);
}

Schematics

Schematic
Every connection you will need
Schematic uc3bsxekr4

Comments

Similar projects you might like

Simple Arduino Digital Clock Without RTC

Project in progress by Annlee Fores

  • 131,456 views
  • 33 comments
  • 121 respects

Arduino 101 Home BLE System

Project tutorial by Alexis Santiago Allende

  • 3,941 views
  • 1 comment
  • 14 respects

Simple Alarm Clock with DS1302 RTC

Project tutorial by SurtrTech

  • 24,796 views
  • 17 comments
  • 28 respects

Simple Clock with LED Matrix

Project tutorial by LAGSILVA

  • 8,917 views
  • 13 comments
  • 26 respects

Arduino Irrigation System

Project tutorial by smana_00

  • 7,076 views
  • 0 comments
  • 24 respects

Minimal parts simple word clock

Project tutorial by garysat

  • 1,733 views
  • 1 comment
  • 3 respects
Add projectSign up / Login