Arduino Temperature Display V1
A functional and accurate project that is perfect for beginners, and displays the current temperature and light levels.
Components and supplies
1
M/M Jumper Leads
1
Mini Breadboard
1
Arduino UNO
1
I2C LCD
1
4.7k resistor
1
LDR Module
1
DS18B20
Apps and platforms
1
Arduino IDE
Project description
Code
TemperatureDisplay.ino
arduino
This is the code for the temperature display.
1#include <OneWire.h> // library to access DS18B20 2#include <DallasTemperature.h> // library to support DS18B20 3#include <Wire.h> // library for communicating to I2C devices 4#include <hd44780.h> // main hd44780 library 5#include <hd44780ioClass/hd44780_I2Cexp.h> // i2c expander i/o class library 6 7hd44780_I2Cexp lcd; // declare lcd object: auto locate & auto configure expander chip 8 9OneWire oneWire(2); // tell the library to use the digital pin the DS18B20 is connected to 10 11DallasTemperature sensors(&oneWire); // tell the library to compute temp on the oneWire pin 12 13int IOL; // initialize the LDR pin name as a 16-bit value 14 15void setup() { 16 Serial.begin(9600); // setup Serial for debug 17 sensors.begin(); // start DS18B20 18 IOL = analogRead(A0); // initialize LDR as analog pin 0 - read only 19 lcd.begin(16, 2); // initialize lcd as 16 columns, 2 rows 20 lcd.clear(); // clear any old data on the lcd 21 // if there is lots of ambient light, turn on the lcd backlight 22 if (IOL < 500) { 23 lcd.backlight(); 24 } 25 // if the ambient light is low, turn off the backlight 26 if (IOL >= 500) { 27 lcd.noBacklight(); 28 } 29} 30 31void loop() { 32 IOL = analogRead(A0); // initialize LDR as analog pin 0 - read only 33 // if there is lots of ambient light, turn on the lcd backlight 34 if (IOL < 500) { 35 lcd.backlight(); 36 } 37 // if the ambient light is low, turn off the backlight 38 if (IOL >= 500) { 39 lcd.noBacklight(); 40 } 41 42 sensors.requestTemperatures(); // send data asking for temperature to DS18B20 43 lcd.setCursor(0, 0); // set the lcd cursor for celsius temperature 44 lcd.print("Temp C: "); // print explanation of following data 45 lcd.print(sensors.getTempCByIndex(0)); // print the degrees in celsius 46 lcd.print(" "); // print spaces to blank out any remanants of data 47 lcd.setCursor(0, 1); // set the lcd for farenheit temperature 48 lcd.print("Temp F: "); // print explanation of following data 49 lcd.print(DallasTemperature::toFahrenheit(sensors.getTempCByIndex(0))); // Convert tempC to Fahrenheit and print it 50 lcd.print(" "); // print spaces to blank out any remanants of data 51 52/* 53 sensors.requestTemperatures(); // send data asking for temperature to DS18B20 54 lcd.setCursor(0, 0); // set the lcd cursor for celsius temperature 55 lcd.print(F("Temp: ")); // print explanation of following data from program storage 56 lcd.print(sensors.getTempCByIndex(0)); // print the degrees in celsius 57 lcd.print(F(" ")); // print space from program storage 58 lcd.print((char)223); // print degrees symbol 59 lcd.print(F("C")); // print celsius abbreviation 60 lcd.print(" "); // print spaces to blank out any remanants of data 61 lcd.setCursor(0, 1); // set the lcd for light levels 62 lcd.print(F("Light Level: ")); // print explanation of following data 63 lcd.print(IOL); // print light levels 64 lcd.print(" "); // print spaces to blank out any remanants of data 65*/ 66} 67
TemperatureDisplay.ino
arduino
This is the code for the temperature display.
1#include <OneWire.h> // library to access DS18B20 2#include <DallasTemperature.h> // library to support DS18B20 3#include <Wire.h> // library for communicating to I2C devices 4#include <hd44780.h> // main hd44780 library 5#include <hd44780ioClass/hd44780_I2Cexp.h> // i2c expander i/o class library 6 7hd44780_I2Cexp lcd; // declare lcd object: auto locate & auto configure expander chip 8 9OneWire oneWire(2); // tell the library to use the digital pin the DS18B20 is connected to 10 11DallasTemperature sensors(&oneWire); // tell the library to compute temp on the oneWire pin 12 13int IOL; // initialize the LDR pin name as a 16-bit value 14 15void setup() { 16 Serial.begin(9600); // setup Serial for debug 17 sensors.begin(); // start DS18B20 18 IOL = analogRead(A0); // initialize LDR as analog pin 0 - read only 19 lcd.begin(16, 2); // initialize lcd as 16 columns, 2 rows 20 lcd.clear(); // clear any old data on the lcd 21 // if there is lots of ambient light, turn on the lcd backlight 22 if (IOL < 500) { 23 lcd.backlight(); 24 } 25 // if the ambient light is low, turn off the backlight 26 if (IOL >= 500) { 27 lcd.noBacklight(); 28 } 29} 30 31void loop() { 32 IOL = analogRead(A0); // initialize LDR as analog pin 0 - read only 33 // if there is lots of ambient light, turn on the lcd backlight 34 if (IOL < 500) { 35 lcd.backlight(); 36 } 37 // if the ambient light is low, turn off the backlight 38 if (IOL >= 500) { 39 lcd.noBacklight(); 40 } 41 42 sensors.requestTemperatures(); // send data asking for temperature to DS18B20 43 lcd.setCursor(0, 0); // set the lcd cursor for celsius temperature 44 lcd.print("Temp C: "); // print explanation of following data 45 lcd.print(sensors.getTempCByIndex(0)); // print the degrees in celsius 46 lcd.print(" "); // print spaces to blank out any remanants of data 47 lcd.setCursor(0, 1); // set the lcd for farenheit temperature 48 lcd.print("Temp F: "); // print explanation of following data 49 lcd.print(DallasTemperature::toFahrenheit(sensors.getTempCByIndex(0))); // Convert tempC to Fahrenheit and print it 50 lcd.print(" "); // print spaces to blank out any remanants of data 51 52/* 53 sensors.requestTemperatures(); // send data asking for temperature to DS18B20 54 lcd.setCursor(0, 0); // set the lcd cursor for celsius temperature 55 lcd.print(F("Temp: ")); // print explanation of following data from program storage 56 lcd.print(sensors.getTempCByIndex(0)); // print the degrees in celsius 57 lcd.print(F(" ")); // print space from program storage 58 lcd.print((char)223); // print degrees symbol 59 lcd.print(F("C")); // print celsius abbreviation 60 lcd.print(" "); // print spaces to blank out any remanants of data 61 lcd.setCursor(0, 1); // set the lcd for light levels 62 lcd.print(F("Light Level: ")); // print explanation of following data 63 lcd.print(IOL); // print light levels 64 lcd.print(" "); // print spaces to blank out any remanants of data 65*/ 66} 67
Downloadable files
Schematc
Schematc

Comments
Only logged in users can leave comments