Hi guys,
Please, could someone help me with this? I am receiving a zero (0) reading for temperature and humidity from my DHT11 sensor. I am using a Leonardo board, powered on the usb 5v source. There is also a soil moisture sensor with controller pinned in the same board. I am using the DHTlib library provided by Rob Tillaart (thanks!) and the code is the following above. My objective is just show in the serial monitor the output from both sensors. I will appreciate all kind of help!
#include <dht.h>
#define dataPin 8
dht DHT; // creates a DHT object
const int moistureAO = 0;
int AO = 0;
int tmp = 0;
int buzzPin = 11;
int LED = 13;
void setup() {
Serial.begin(9600);
Serial.print("Soil moisture sensor");
pinMode(moistureAO, INPUT);
pinMode(buzzPin, OUTPUT);
pinMode(LED, OUTPUT);
}
void loop () {
tmp = analogRead( moistureAO );
if ( tmp != AO ) {
AO = tmp;
Serial.print("A = ");
Serial.println(AO);
}
delay (1000);
if (analogRead(0) > 900) {
digitalWrite(buzzPin, HIGH);
digitalWrite(LED, HIGH);
delay(1000);
digitalWrite(buzzPin, LOW);
digitalWrite(LED,HIGH);
}
else {
digitalWrite(buzzPin, LOW);
digitalWrite(LED, LOW);
}
int readData = DHT.read22(dataPin); // Reads the data from the sensor
float t = DHT.temperature; // Gets the values of the temperature
float h = DHT.humidity; // Gets the values of the humidity
// Printing the results on the serial monitor
Serial.print("Temperature = ");
Serial.print(t);
Serial.print(" *C ");
Serial.print(" Humidity = ");
Serial.print(h);
Serial.println(" % ");
delay(2000); // Delays 2 secods, as the DHT22 sampling rate is 0.5Hz
}