Categories

Temperature and humidity on a LCD4884 shield

In this example we connect a DHT11 sensor our Arduino, again we will display the temperature and this time the humidity as well on our LCD4884 shield. In this example we connected the data pin of the DHT11 to Pin 9. VCC and GND were derived from the shield.

Here’s a picture of the shield used

 

lcd4884

lcd4884

and here is the DHT11 breakout board, this simplifies things as it contains the necessary resistor already fitted otherwise you need to fit a 4k7 between Vcc and the data pin. You can also plug this into either a breadboard or simple connect dupont cables from the shield to the breakout

dht11 breakout

dht11 breakout

Code

You’ll need the LCD4884 library and the you will need the DHT11 library from the DHT library.

Download, extract and copy this to your Arduino libraries folder location


//required header files
#include <Wire.h>
#include "LCD4884.h"
#include <dht11.h>

//DHT11 sensor settings
dht11 DHT;
#define DHT11_PIN 9
int check;

//variables for readings from sensor
float tempC;
char tempstringC[10];
float humid;
char tempHumid[10];

void setup()
{
lcd.LCD_init();
lcd.LCD_clear();
init_MENU();
//debugging functionality
Serial.begin(9600);
Serial.print("DHT11 STATUS – \t");
}

void init_MENU(void)
{
//clear LCD and display initial display
lcd.LCD_clear();
lcd.LCD_write_string(10, 1, "Temperature", MENU_HIGHLIGHT );
lcd.LCD_write_string(10, 3, "Humidity", MENU_HIGHLIGHT );
}

void display_READINGS(void)
{
//get the temperature and humidity readings
tempC=DHT.temperature;
itoa(tempC,tempstringC,10);
humid=DHT.humidity;
itoa(humid,tempHumid,10);
//display values on LCD
lcd.LCD_write_string(10, 2, tempstringC, MENU_NORMAL);
lcd.LCD_write_string(22, 2, " (c)", MENU_NORMAL);
lcd.LCD_write_string(10, 4, tempHumid, MENU_NORMAL);
lcd.LCD_write_string(22, 4, " %", MENU_NORMAL);
delay(2000);
}

void loop()
{
//read and convert values
check = DHT.read(DHT11_PIN);
//check status - this is useful for debugging the sensor
switch (check)
{
case DHTLIB_OK:
Serial.print("OK\n");
display_READINGS();
break;
case DHTLIB_ERROR_CHECKSUM:
Serial.print("Checksum error\n");
lcd.LCD_clear();
lcd.LCD_write_string(10, 1, "Checksum error", MENU_HIGHLIGHT );
break;
case DHTLIB_ERROR_TIMEOUT:
Serial.print("Timeout error\n");
lcd.LCD_clear();
lcd.LCD_write_string(10, 1, "Timeout error", MENU_HIGHLIGHT );
break;
default:
Serial.print("Unknown error\n");
lcd.LCD_clear();
lcd.LCD_write_string(10, 1, "Unknown error", MENU_HIGHLIGHT );
break;
}

}

Links

DFRobot – Graphic LCD4884 Shield for (For Arduino)

DHT11 Digital Temperature and Humidity Sensor Module For Arduino

Share

LCD4884 and temperature example

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


#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);
}

}

Links

 
DFRobot – Graphic LCD4884 Shield for (For Arduino)

Share

LCD4884 counting example

A simple example to count to 10000 and display this on an LCD4884 shield
Code


#include "LCD4884.h"

#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();
}

void init_MENU(void)
{

byte i;
lcd.LCD_clear();
lcd.LCD_write_string(MENU_X, MENU_Y, "Counter", MENU_HIGHLIGHT );
}

void loop()
{

if(++counter < 10000)
{
itoa(counter,string,10);
lcd.LCD_write_string(MENU_X, MENU_Y + 1, string, MENU_NORMAL);
}
else
{
counter = 0,init_MENU();
}
delay(10);

}

Links

 
Graphic LCD4884 Shield for (For Arduino)

Share