Ronald P. Kessler
Published © GPL3+

Introduction to Home Automation: Arduino Weather Station Lab

Here is your chance to learn how to read temperature, humidity, and light level and display the results on an LCD.

BeginnerShowcase (no instructions)4 hours1,147
Introduction to Home Automation: Arduino Weather Station Lab

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
I am using version 1.8.12 so make sure you always use the latest Integrated Development Environment (IDE ) for your projects.
DFRobot I2C 20x4 Arduino LCD Display Module
Wiring: Vcc = Power (Red Wire on this setup) Ground = Black Yellow = SDA and connects to Arduino Pin A4 Green = SCL and connects to Arduino Pin A5
Small Solderless Breadboard Kit
Digilent Small Solderless Breadboard Kit
Male/Male Jumper Wires
These are used to connect the Arduino to the breadboard
Male/Female Jumper Wires
Male/Female Jumper Wires
These will connect the LCD to the breadboard
DHT11 Temperature & Humidity Sensor (4 pins)
DHT11 Temperature & Humidity Sensor (4 pins)
LDR, 5 Mohm
LDR, 5 Mohm
Resistor 10k ohm
Resistor 10k ohm
These are marked with Brown-Black-Orange stripes. You can use 1/4 or 1/2 watt resistors.
Resistor 4.75k ohm
Resistor 4.75k ohm
These 4700 ohm resistors are marked with Yellow-Violent-Red stripes. You can use 1/4 or 1/2 watt resistors.

Software apps and online services

Arduino IDE
Arduino IDE
Be sure to use the DHT-11 & LiquidCrystal_I2C libraries from my website ( See the link below in the "Story" section.

Hand tools and fabrication machines

Plier, Long Nose
Plier, Long Nose
I often use these to help push resistors into the breadboard.
Wire Cutter / Stripper, 5.25 " Overall Length
Wire Cutter / Stripper, 5.25 " Overall Length
You need to trim the resistor leads. Any type of wire cutter will work.


Read more


Photo of the breadboard version

Notice how i wired the resistors for the LCD using the Green and Yellow wires I described above. One end of each resistor is connected to 5V on the breadboard. The other ends connect the green & yellow wires from the LCD to the green & yellow wires going to the Arduino.

Wiring Layout for Arduino Weather Station

Photo of the wiring

Close up of the wiring

Closeup of LCD Wiring

SCL (Green) connects to A5 on Arduino and SDA (Yellow) connects to A4. I use Red for Vcc (power) and Black for Ground.


Arduino Sketch Code

        //CS198 Home Automation & Networking Fundamentals
        //LAB 2: Weather Station Demo Using an LCD
        //Ron Kessler
        //Created 7/16/2015
        //Updated 7/29/2020
        //  Uses the V1.2 LCD from DFRobot and the updated Library.
        //Updated 7/27/2015  Made note about pull-ups and changed row/column assignments on setCursor method. Also
        //      made humidity display as an integer instead of a float. See note below.
        //Adapted from Home Automation with Arduino by Marco Swartz
        //When wiring the LCD, add 4.7K pull-up resistors on the SCL and SDA pins (A4 and A5 on Arduino)

        // Code to measure data & display it on the LCD screen
        //the correct liquidcrystal lib is in c\progfiles\arduino\libs
        // import these Libraries  See the README for details!
        #include <Wire.h> 
        #include <LiquidCrystal_I2C.h>    // for the LCD using ver 1.2 as of 7/28/2020
        #include <DHT.h>                  //the temp/humidity sensor
        // DHT sensor setup
        #define DHTPIN 7 
        #define DHTTYPE DHT11
        // LCD display instance
        LiquidCrystal_I2C lcd(0x20,20,4);   //make sure the lcd address is 0x20. It shows 0x27 in the book and will never work!

        // create a DHT instance
        DHT dht(DHTPIN, DHTTYPE);
        void setup()
          // Initialize the lcd 
          // Print a message to the LCD.
          lcd.print("CS198: Arduino Lab 2");
          lcd.print("Weather Station");
          // Init DHT to start reading data
          // Clear LCD
        //---Our main loop
        void loop()
          // Measure from DHT
          float temperature = dht.readTemperature();
          float humidity = dht.readHumidity();
          // Measure light level
          float sensor_reading = analogRead(A0);
          float light = sensor_reading/1024*100; //the Arduino A/D converter uses 10 bits. 2^10 =1024 so divide raw data by 1024 and * by 100 to get %
          // Display temperature
          lcd.setCursor(0,0);                       //col 0 row 0    setCursor is zero-based
          lcd.print("Temp.: ");
          //lcd.print((float)temperature,1);          //celsius with 1 decimal
          //--my C2F function (see below)
          lcd.print((float)C2F(temperature),1);   //Fahrenheit to 1 decimal.  Leave out the ,1 if you want a whole number
          lcd.print((char)223);                   //the little degree symbol
           // Display humidity
          lcd.setCursor(0,1);                     //col 0 row 1
          lcd.print("Humidity: ");
          lcd.print((int)humidity);               //cast to a float if you want decimal places. I was happy with integer!
          // Display light level
          lcd.setCursor(0,2);                    //col 0 row 2
          lcd.print("Light: ");

          // Wait 2 seconds
          delay(2000);                            //wait 2 seconds before updating again


        /* *************HELPER FUNCTIONS *************** */
        //Celsius to Fahrenheit conversion
        float C2F(float celsius)
          return 1.8 * celsius + 32;

        /*  END OF CODE  */


Ronald P. Kessler

Ronald P. Kessler

2 projects • 4 followers
I am a retired Computer Science, Robotics, & Home Automation instructor. I have loved electronics since I was in Jr. High School.