ARDUINO LCD THERMOMETER PART 1
Hey Everybody! A few days ago I was going through all my spare components and I went - "Hey! Why don't I build an electronic thermometer! I've got all the pieces lying around - why not!"
And so that's what I've done. I've built the thermometer, and it works pretty well, but it's still just a breadboard circuit, so over the next few days I'll solder everything up, and then post a part 2. But seeing as its functionally done, I thought why wait.
Here is what I've done so far -
The breadboard version of my electronics thermometer |
COMPONENTS -
- An Arduino - I use and Arduino Nano for this (Actually, it is a Chinese rip-off. Shame on me, I know, but at the crazy price of $4, it was a steal. A search on eBay for "Arduino Nano" yields tons of results)
- An LM335Z Temperature Sensor - A 3 pin temperature sensors module. Available on Digikey - LM335Z Temperature Sensor
- An LCD Display - In this case, I used the Nokia 5110 LCD, which is again available on eBay for a dollar or two. You don't HAVE to use this display - I use it because it is cheap, but also because there are great libraries out there to help you use the display and to make it easy to get things to... well, display!
- A 1.9K resistor - It's important to get this right. I used a 10K resistor to begin with, and I was wondering why I was getting crazy temperatures, like -10 degrees C, for instance. While it definitely gets a bit chilly here in Australia, I can promise that it wasn't that cold :).
- A 9V power supply. Again, very important. I was getting readings of +39 degrees C over a 5V USB connection, which definitely incorrect. But changing from a 5V to a 9V power supply seemed to fix everything - The readings dropped from ~39 degrees to a comfortable 20 or so. Much better :).
That's pretty much it. After that, all you need are some jumper wires, a computer to program the Arduino, and a breadboard and you're all set!
REMEMBER - 9V power supply!!!
REMEMBER - 9V power supply!!!
Here is the serial output with a 5V power supply |
And here is output from EXACTLY the same program, but this time with a 9V power supply |
Here is the Fritzing diagram of the circuit - as you can see, it is pretty simple. All you really need to do is wire everything directly to the Arduino, and then add the 1.9K resistor, which goes across from A0 to 5V. If you are using a 9V battery instead of a 9V DC power supply like me, simply switch out the two wires for the power jack with the two for the battery snap, with ground( black ) going to ground, and red (+V) going to VCC.
Now that the you've assembled the circuit, we need to upload the code.... right? Well, we will get to that soon, but first, there are two libraries which we need to add. These libraries are both used to interact with the LCD display, and make displaying text much easier.
Adafruit-PCD8544-Nokia-5110-LCD-library
Adafruit-GFX-Library
To install these libraries, you need to first download them (duh), then open up the Arduino IDE.
From there, you need to go to Sketch (in the bar up the top), then Import Library -> Add library, and then select the two libraries, and press open. I don't know about you, but I found that I needed to rename the two libraries (This is on an Ubuntu PC). So if you find the libraries don't seem to be installing, then try renaming the two files that you downloaded, and trying again.
If the importing did work, then under files->examples there should be a new tab, called something like Adafruit-Pcd8544-blahblahblah whatever, click on that and you should see pcdtest come up. Run that, and if you wired everything up correctly, then it should give you something to look at on the LCD! Yay! If that worked, then continue. If it didn't, make sure the USB cable is plugged in, you've selected the correct board and port, and everything is wired up correctly.
If pcdtest works and you see stuff on your LCD (things like lines, triangles, flowers and stuff. Not just fuzz, or a few pixels lighting up), then your ready to upload the code -
ArduinoTempAndLCD.ino - Displays Temp In CELSIUS(C)
ArduinoTempFAHRENHEITAndLCD.ino - Displays Temp In FAHRENHEIT(F)
And there you have it - If everything is wired correctly, the temperature should be getting displayed on the LCD. As a sort of test, you can put your thumb and index finger on the LM335Z, and you should see the temperature go up.
Code Explanation -
The code is in fact very simple. First, we import the libraries we installed. Then we store the pin for the LM335Z in a variable and initialize the display. Then, during the setup() function, we briefly print out the word "Thermometer" onto the LCD, and then we go straight into reading and displaying the temperature onto the LCD.
If you want to change the size of the text, just find the line with display.setTextSize() on it, and change the number in the brackets. The bigger the number, the bigger the text. Bear in mind there are two instances of display.setTextSize(). One in setup(), and one in loop(). Changing the line in setup() will change the size of the word Temperature, and changing the one in loop() will change the size of the displayed temperature.
Well, I hope you enjoyed this, and possibly even built your own thermometer! Thanks for reading! Stay tuned for part 2!
No comments:
Post a Comment
Please post constructive comments. Spam will not be tolerated. Thanks.