Go Down

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

Bigginger61

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
works.

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;



DHT dht(DHTPIN, DHTTYPE);
rgb_lcd lcd;

// Set Up


void setup()
{

  // set up the serial monitor for debugging

  Serial.begin(9600);
  Serial.println("DHTxx test!");
  dht.begin();

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


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(counter);
  Serial.println("----------------------- ");
  Serial.println(" ");

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

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

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

  Serial.println(" ");

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

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

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

  Serial.println(" ");
  delay(readingInterval);
}

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 ");
  lcd.print(currentTemp);
  delay(100);
}

pylon

Quote
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!

Bigginger61

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

Go Up