Home Code LCD4884 and temperature example

LCD4884 and temperature example

by shedboy71

In this example we connect an LCD4884 shield to our Arduino and then we connect a DS18B20 temperature sensor to Pin 9 and we will display the temperature in celsius and fahrenheit.

lcd4884

lcd4884

Code

Here is the code

You need to download and install various libraries and copy them into your Arduino libraries folder.

Dallas 18b20 Temperature Library
“1-Wire” Library

and the LCD4884 library

[c]

#include “LCD4884.h”
#include “Arduino.h”
#include “Wire.h”
#include “OneWire.h”
#include “DallasTemperature.h”

#define DS18B20 9
//for the temperature values
float tempC;
float tempF;
char tempstringC[10];
char tempstringF[10];

//dallas temperature sensor related
int TEMPERATURE_PRECISION=9;
OneWire ourWire(DS18B20);
DallasTemperature sensors(&ourWire);
int numberOfDevices;                          // Number of temperature devices found
DeviceAddress tempDeviceAddress;

#define MENU_X  10      // 0-83
#define MENU_Y  1       // 0-5

int counter = 0;
char string[10];

void setup()
{
lcd.LCD_init();
lcd.LCD_clear();
init_MENU();
Serial.begin(9600);
sensors.begin(); // Start up the OneWire library
delay(100);
//debugging
numberOfDevices = sensors.getDeviceCount();  // Get a count of sensors on the bus
for(int xyz=0;xyz<numberOfDevices; xyz++)  // Loop through each device, print out address
{
if(sensors.getAddress(tempDeviceAddress, xyz))    // Search the wire for address
{
Serial.print(“Found Sensor “);
Serial.print(xyz, DEC);
Serial.print(” with address: “);;
Serial.println();
Serial.print(“Setting resolution to “);
Serial.println(TEMPERATURE_PRECISION,DEC);
delay(100);
sensors.setResolution(tempDeviceAddress, TEMPERATURE_PRECISION);  // set the sensor resolution
}
}
}

void init_MENU(void)
{
byte i;
lcd.LCD_clear();
lcd.LCD_write_string(MENU_X, MENU_Y, “Temperature”, MENU_HIGHLIGHT );
}

void loop()
{
sensors.requestTemperatures();            //issue global request for each temp sensor on network to return a temp
if(sensors.getAddress(tempDeviceAddress, 0))
{
tempC=(sensors.getTempC(tempDeviceAddress));
tempF=(sensors.getTempF(tempDeviceAddress));
itoa(tempC,tempstringC,10);
lcd.LCD_write_string(10, 3, tempstringC, MENU_NORMAL);
lcd.LCD_write_string(30, 3, “c” , MENU_NORMAL);
itoa(tempF,tempstringF,10);
lcd.LCD_write_string(10, 4, tempstringF, MENU_NORMAL);
lcd.LCD_write_string(30, 4, “f” , MENU_NORMAL);
delay(10);
}
else
{
lcd.LCD_write_string(10, 3, “UNAVAILABLE”, MENU_NORMAL);
delay(10);
}

}

[/c]

Links

 
DFRobot – Graphic LCD4884 Shield for (For Arduino)

Share

You may also like