Home Digital Thermometer W/ Arduino
by 707580 in Circuits > Arduino
188 Views, 1 Favorites, 0 Comments
Home Digital Thermometer W/ Arduino
![IMG-1799.jpg](/proxy/?url=https://content.instructables.com/FJ5/O9D0/LJ1FUUSY/FJ5O9D0LJ1FUUSY.jpg&filename=IMG-1799.jpg)
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
![IMG-1732.jpg](/proxy/?url=https://content.instructables.com/FTY/MFEK/LJ1FUUTK/FTYMFEKLJ1FUUTK.jpg&filename=IMG-1732.jpg)
- 1x Arduino Uno
- 1x LCD Display
- 3x LEDs (Red, Green, Blue)
- 1x Breadboard
And of course you will need some wires, regular ones and male/female for the humiture sensor and LCD display
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.
Wiring
![IMG-1718.jpg](/proxy/?url=https://content.instructables.com/FAP/YRU6/LJ1FUUU8/FAPYRU6LJ1FUUU8.jpg&filename=IMG-1718.jpg)
![IMG-1805.jpg](/proxy/?url=https://content.instructables.com/FM8/M3SA/LJ1FUUUE/FM8M3SALJ1FUUUE.jpg&filename=IMG-1805.jpg)
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.
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.
Downloads
Code - Libraries & Variables
![Capture.PNG](/proxy/?url=https://content.instructables.com/F3S/5IAW/LJ2V9TG1/F3S5IAWLJ2V9TG1.png&filename=Capture.PNG)
- 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.
Code - Setup
![Capture2.PNG](/proxy/?url=https://content.instructables.com/FWG/BW1K/LJ2V9TGJ/FWGBW1KLJ2V9TGJ.png&filename=Capture2.PNG)
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.
Functions
![Capture3.PNG](/proxy/?url=https://content.instructables.com/FVD/CMI9/LJ2V9TIZ/FVDCMI9LJ2V9TIZ.png&filename=Capture3.PNG)
![Capture4.PNG](/proxy/?url=https://content.instructables.com/FR8/L8RE/LJ2V9TK1/FR8L8RELJ2V9TK1.png&filename=Capture4.PNG)
![Capture5.PNG](/proxy/?url=https://content.instructables.com/FJ1/AU1S/LJ2V9TK2/FJ1AU1SLJ2V9TK2.png&filename=Capture5.PNG)
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.
Code - Void Loop
![Capture6.PNG](/proxy/?url=https://content.instructables.com/FDM/QJMO/LJ2V9TKL/FDMQJMOLJ2V9TKL.png&filename=Capture6.PNG)
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
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!