Go Down

Topic: Grove LCD interfering with DHR11 sensor (Read 340 times) previous topic - next topic


I have an Arduino Leonard with Grove Base Sheild. I wrote code to read the sensors temperatire and humidity readings and read them via the serial monitor.

Seperate to that I obtained the Grove LCD panel and succesfully ran the "Hellow World" code. Howver when I combine the code the sensor readings are not taken, If I rematk out the LCD related code the sensor

The grove DHT11 sensor is connected to a D2 port on the shiled and the LCD to one of the I2c ports.

I combined code is below, can anyone please guide me towards a solution.

// Code to read a temperature and humidity sensor and send the reading to the serial monitor and an LCD
// Ultimately I want to control a heater via a relay.

// Load in the DHT library

#include "DHT.h"
#define DHTPIN 2     // what pin we're connected to
#define DHTTYPE DHT11   // DHT 11 - identify the type of sensor

#include <Wire.h>
#include "rgb_lcd.h"

// Define Global variabals

float maxTemp = 0;
float minTemp = 200; // start reading
float maxHumidity = 0;
float minHumidity = 200;  // start reading
float currentTemp = 0;
float currentHumidity = 0;
float triggerTemp = 0; // The temp and which the relay needs to be tripped
long readingInterval = 2000;  //Sensor reading interval 1000 = 1 second
long counter = 0;
const int colorR = 255;
const int colorG = 0;
const int colorB = 0;

rgb_lcd lcd;

// Set Up

void setup()

  // set up the serial monitor for debugging

  Serial.println("DHTxx test!");

  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
  lcd.setRGB(colorR, colorG, colorB);


// Main Loop

void loop()

  GetTemp();                //Get the temperature and humidity readings
  UpdateMaxMin();           //Update Max Min temps
  MinTempAlarm();           //Check for low temp
  PrintToMonitor ();        //Print dat in the serail monitior

void GetTemp() {

  // Get the readings from the sensor

  float h = dht.readHumidity();
  float t = dht.readTemperature();

  // transfer the value of the local variable h and t to global varaiables
  // to make them avaialble in the other sub routines

  currentTemp = t;
  currentHumidity = h;


void PrintToMonitor() {

  // Print the readings to the serial monitor

  Serial.println(" ");
  Serial.print("Reading Number: ");
  Serial.println("----------------------- ");
  Serial.println(" ");

  Serial.print("Curr Humidity : ");
  Serial.println(" %\t");

  Serial.print("Max  Humidity : ");
  Serial.println(" %\t");

  Serial.print("Min  Humidity : ");
  Serial.println(" %\t");

  Serial.println(" ");

  Serial.print("Curr Temp     : ");
  Serial.println(" *C");

  Serial.print("Max  Temp     : ");
  Serial.println(" *C");

  Serial.print("Min  Temp     : ");
  Serial.println(" *C");

  Serial.println(" ");

void UpdateMaxMin() {

  //Update the max and min temps and humidity readings

  if (currentTemp >= maxTemp) {
    maxTemp = currentTemp;

  if (currentTemp <= minTemp) {
    minTemp = currentTemp;

  if (currentHumidity >= maxHumidity) {
    maxHumidity = currentHumidity;

  if (currentHumidity <= minHumidity) {
    minHumidity = currentHumidity;

  counter = counter + 1;


void MinTempAlarm() {

  if (minTemp <= triggerTemp) {
    Serial.println("Turn the bloody heater on!!!");

void PrintToLED() {

  // set the cursor to column 0, line 1

  lcd.setCursor(0, 0);
  //print the current temperature

  lcd.print("Current Temp ");


The grove DHT11 sensor is connected to a D2 port on the shiled and the LCD to one of the I2c ports.
D2 is internally connected to SDA on the Leonardo. Use another pin for the DHT sensor!


Thanks Pylon, I switched Pin 4 and it as all working now.

Go Up