Introduction: Home Digital Thermometer W/ Arduino

Hi, my name is Rishi Jogia. In this instructable, I will be going through my project, a home digital thermometer. I get the temperature and humidity from the humiture detector, then print it on the LCD. Depending on the temperature, a certain LED turns on which shows whether the temperature is stable, too hot, or too cold.

Supplies




  • 3x LEDs (Red, Green, Blue)



And of course you will need some wires, regular ones and male/female for the humiture sensor and LCD display

Step 1: Reasearch

I knew I wanted to do an arduino project with code for this project as I have more fun with them and I feel like it has more of a purpose than something like a 4-bit adder. The problem was, that I had no clue what to make. I looked at lots of examples on instructables, but none of them really appealed to me much. After 2 days of trying to find something, I found an instructable using a humiture detector, but for cooking purposes.


I liked the idea of detecting temperature, so I took inspiration from that project and put my own spin on it. From there, I decided on a home digital thermometer, using an LCD display.

Step 2: Wiring

The picture on the left was a work in progress photo when I wired the Humiture sensor and LCD display, but I didn't know what I wanted to do with the LEDs. The picture on the left is how the completed circuit looks inside of the box.


The first thing you need to do is connect power and ground to the breadboard to power the humiture sensor, LCD display, and LEDs. I used 5V in my circuit from the Arduino Uno.


Then, you have to wire the Humiture sensor and LCD display using male/female wires. You could also put a wire into one end of a female/female wire if you don't have male/female wires.


The humiture sensor has 3 pins; VCC (power), GND (ground), and SIG (signal to connect to pin). VCC and GND go to 5V and GND on the Arduino, and I connected signal to pin 7.


The LCD display has 4 pins; VCC, GND, SDA (Serial Data Line), and SCL (Serial Clock Line). I wired SDA to pin A4 and SCL to pin A5, which are both input pins.


The 3 LEDs are all wired the same, but I soldered the blue led because it's legs were a bit too short. The long leg, which is positive (anode) goes to the Arduino pins, and the short leg, which is negative (cathode) is connected to ground through a 330 Ohm resistor. I connected the red LED to pin 3, the green LED to pin 5, and the blue led to pin 6 in the Arduino. I connected them all to PWN pins (the pin numbers with '~' in front of it) so that I can make the LEDs blink with analogWrite.

Step 3: Code

I coded this project on the Arduino app, and uploaded it to the Arduino Uno. I will go step-by-step on the important sections of the code. You can download the code file I linked to see the code more in-depth and be able to use it for your own project.


Step 4: Code - Libraries & Variables

  • Libraries

The 3 libraries needed for this project are:

  • #include <dht.h> (for the Humiture sensor)
  • #include <LiquidCrystal_I2C.h> (for LCD display)
  • #include <Wire.h> (used to communicate with the SDA and SCL pins on LCD)

<Wire.h> was already downloaded on the Arduino software, but I had to download <LiquidCrystal_I2C.h> and <dht.h> onto the Arduino software from this website. Click on where it says 'Get Started' and follow the instructions on the website to download it.


  • Variables

const int DHT11_PIN= 7;


These variables are needed to give the pins names of the component which is wired to it.


Step 5: Code - Setup

In the picture above is the setup of the component, declaring whether they're an input or output. The LCD and Humiture sensor are a bit different than usual, as the setup for the LCD is initializing it and turning on the backlight. We don't need to declare the SDA and SCL pins on the LCD as anything as they are already declared as inputs since they are in the A4 and A5 pins. For the Humiture sensor, we don't need to include DHT11_PIN in the setup. The LEDs are the only components in this project that need to be declared as an input or output, and you can see that I declared them as outputs.

Step 6: Functions

As you can see in the screenshot above, I have 2 functions in my code, void displayTemp and void led.


DHT.temperature and DHT.humidity are important parts of both functions, as it's what is used to store the temperature in Celsius and the humidity %.


  • Void displayTemp

void displayTemp is the main function, with it's purpose being to get the temperature and humidity from the Humiture sensor, and print it everything that is on the LCD. This includes; "Tem:", "Hum", the signs for Celsius and percentage, and the actual temperature and humidity that it gets from DHT.temperature and DHT.humidity.


  • Void led

void LED, as you may have guessed, contains the code for the LEDs, controlling when they turn on and the blinking of the LED. As you can see in the screenshot, I used if and else if statements to dictate which LED should be on depending on the temperature and print on the serial monitor whether it's too hot, too cold, or stable temperature. I coded it so that if the temperature is 20°C or higher, the red LED blinks, if the temperature is between 20°C and 25°C, the green LED blinks, and if the temperature is 20°C or below, the blue LED turns on.

Step 7: Code - Void Loop

The void loop is where everything in the code runs.


At the top of the function is a switch case. It checks for any issues in the Humiture or the LCD and displays what the issue is. So far in my testing, I haven't ran into any of these issues so I think it only comes in effect when the physical component itself is faulty.


After the switch case, I called both functions (void displayTemp, void led) in the void loop to run the main part of my project.

I chose to put these in a function instead of dumping all the code in the void loop as it looks cleaner and easier to read, and I find that I can find errors easier if everything is organized into separate functions rather than when it's all cluttered in one function.


If you have done everything correct, your digital thermometer should work!


Link to demo video here

Step 8: Common Mistakes & Conclusion

While making this project, I made a lot of mistakes, some of which took more time than it should have to fix them. I hope this guide was detailed enough so that you don't have any errors, but I will list some of the errors I had or some common ones in general in case you are stuck:


  • Not downloading the libraries:

You need to download the libraries <dht.h> and <LiquidCrystal_I2C.h> for this code to work. This is an issue I had myself, and I spent a lot of time just figuring out how to download it. I already mentioned this before, but you have to go to this website and go to "Get Started" to download the files, then scroll down to see different methods of downloading the libraries.


  • Writing DHT.temperature wrong, causing LEDs to not work

If you look at the void displayTemp function, you would see that there's a 1 at the end of DHT.temperature, written as DHT.temperature,1. I thought the 1 was supposed to be there in every situation, but it turned out that it was just for the LCD, and you were not supposed to include it in the if statements for the LEDs. I wasn't able to spot this issue as this was my first time using these coding statements and these components, but my teacher was able to find this issue to fix my problem with the LEDs.


Conclusion:

Dear reader, I hope this Instructable helped you out with your project, even if it was a little bit. I had a lot of fun in the process of making this project, from problem solving to learning new things about components I've never used like the Humiture sensor and the LCD display. I wish you luck in this project, and future projects you try to figure out. Goodbye for now!