cowboydaniel
Published © CC BY-NC

Arduino Temperature Display V1

A functional and accurate project that is perfect for beginners, and displays the current temperature and light levels.

BeginnerFull instructions provided292
Arduino Temperature Display V1

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
DFRobot DS18B20
×1
DFRobot I2C LCD
×1
LDR Module
×1
DFRobot Mini Breadboard
×1
DFRobot M/M Jumper Leads
×1
DFRobot 4.7k resistor
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Schematc

Code

TemperatureDisplay.ino

Arduino
This is the code for the temperature display.
#include <OneWire.h>                       // library to access DS18B20
#include <DallasTemperature.h>             // library to support DS18B20
#include <Wire.h>                          // library for communicating to I2C devices
#include <hd44780.h>                       // main hd44780 library
#include <hd44780ioClass/hd44780_I2Cexp.h> // i2c expander i/o class library

hd44780_I2Cexp lcd; // declare lcd object: auto locate & auto configure expander chip

OneWire oneWire(2); // tell the library to use the digital pin the DS18B20 is connected to

DallasTemperature sensors(&oneWire); // tell the library to compute temp on the oneWire pin

int IOL; // initialize the LDR pin name as a 16-bit value

void setup() {
  Serial.begin(9600); // setup Serial for debug
  sensors.begin(); // start DS18B20
  IOL = analogRead(A0); // initialize LDR as analog pin 0 - read only
  lcd.begin(16, 2); // initialize lcd as 16 columns, 2 rows
  lcd.clear(); // clear any old data on the lcd
  // if there is lots of ambient light, turn on the lcd backlight
  if (IOL < 500) {
    lcd.backlight();
  }
  // if the ambient light is low, turn off the backlight
  if (IOL >= 500) {
    lcd.noBacklight();
  }
}

void loop() {
  IOL = analogRead(A0); // initialize LDR as analog pin 0 - read only
  // if there is lots of ambient light, turn on the lcd backlight
  if (IOL < 500) {
    lcd.backlight();
  }
  // if the ambient light is low, turn off the backlight
  if (IOL >= 500) {
    lcd.noBacklight();
  }

  sensors.requestTemperatures(); // send data asking for temperature to DS18B20
  lcd.setCursor(0, 0); // set the lcd cursor for celsius temperature
  lcd.print("Temp C: "); // print explanation of following data
  lcd.print(sensors.getTempCByIndex(0)); // print the degrees in celsius
  lcd.print("       "); // print spaces to blank out any remanants of data
  lcd.setCursor(0, 1); // set the lcd for farenheit temperature
  lcd.print("Temp F: "); // print explanation of following data
  lcd.print(DallasTemperature::toFahrenheit(sensors.getTempCByIndex(0))); // Convert tempC to Fahrenheit and print it
  lcd.print("       "); // print spaces to blank out any remanants of data

/*
  sensors.requestTemperatures(); // send data asking for temperature to DS18B20
  lcd.setCursor(0, 0); // set the lcd cursor for celsius temperature
  lcd.print(F("Temp: ")); // print explanation of following data from program storage
  lcd.print(sensors.getTempCByIndex(0)); // print the degrees in celsius
  lcd.print(F(" ")); // print space from program storage
  lcd.print((char)223); // print degrees symbol
  lcd.print(F("C")); // print celsius abbreviation
  lcd.print("       "); // print spaces to blank out any remanants of data
  lcd.setCursor(0, 1); // set the lcd for light levels
  lcd.print(F("Light Level: ")); // print explanation of following data
  lcd.print(IOL); // print light levels
  lcd.print("       "); // print spaces to blank out any remanants of data
*/
}

Credits

cowboydaniel

cowboydaniel

2 projects • 1 follower
Got my first Uno in 2020. I am 16 years old.

Comments