I know my code will not be great and this is very basic code, however this is my first (and last) time ever coding for a project, I have very little knowledge of code. The aim of my code is to make a LED light turn on when the humidity reaches above 70 using a DHT11 sensor. My sensor used to work before I changed the code somehow and now it does not, and also the LED has never turned on as my if statements intend it to. How do I need to adjust/redo my code for it to work and to achieve my aim?
#include <SimpleDHT.h>
// for DHT11,
// VCC: 5V or 3V
// GND: GND
// DATA: 2
int pinDHT11 = 2;
SimpleDHT11 dht11;
const int ledPin = 13; // We will use the internal LED
void setup() {
Serial.begin(9600);
pinMode(ledPin, OUTPUT); // Set the LED Pin as an output
}
void loop() {
// start working...
Serial.println("=================================");
Serial.println("Sample DHT11...");
float h = SimpleDHT.readHumidity();
// read without samples.
byte temperature = 0;
byte humidity = 0;
int err = SimpleDHTErrSuccess;
if (h >= 70) {{
digitalWrite(ledPin,HIGH); //Turn the LED off
else {
digitalWrite(ledPin,LOW);
} else if ((err = dht11.read(pinDHT11, &temperature, &humidity, NULL)) != SimpleDHTErrSuccess) {
Serial.print("uh oh not working ! :( "); Serial.println(err);delay(1000);
return;
}
Serial.print("Sample OK: ");
Serial.print((int)temperature); Serial.print(" *C, ");
Serial.print((int)humidity); Serial.println(" H");
// DHT11 sampling rate is 1HZ.
delay(1500);
}