problem in program I need your help

good morning
I have a problem with the program which I have made for controlling home appliances I have LDR, PIR, SOUND and TEMP DHT11 (3 pin) and 4 relay with Arduino Leonardo
first problem I cant see the temp value in the serial monitor
second it is working in the opposite way when it should be high it is low and the opposite correct so I made it opposite to work good and the temp relay it stay on only, please could you help me to correct the code.

final_LDR___PIR_ok__sound_and_temp.ino (1.74 KB)


Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Thanks..Tom... :)

it is so difficult but I will do

it takes some time


#include <dht11.h>
dht11 DHT11;

#define LDR A0
#define PIR 2
#define SOUND A1
#define DHT11PIN 7


  • AnalogReadSerial
  • Reads an analog input pin 1 and prints the result to the serial monitor
  • Click on the serial monitor button to open it.

#define RELAY_1 3
#define RELAY_2 4
#define RELAY_3 5
#define RELAY_4 6

int pirState;
int sensorValue;
int ldrValue;

void setup() {
Serial.println(“Virtuabotix DHT11 FAN & Heater CONTROL”);
pinMode(RELAY_1, OUTPUT);
pinMode(RELAY_2, OUTPUT);
pinMode(RELAY_3, OUTPUT);
pinMode(RELAY_4, OUTPUT);
digitalWrite(RELAY_4, LOW);//turn off the relay
pinMode(PIR, INPUT);
digitalWrite(RELAY_1, HIGH);
pinMode(SOUND, INPUT);


void loop(){
ldrValue = analogRead(LDR);
//Serial.print("Analog reading = ");

if (ldrValue <= 512) { // dark
digitalWrite(RELAY_2, LOW);
else { // light
digitalWrite(RELAY_2, HIGH);
pirState = digitalRead(PIR);
if (pirState == LOW) {
digitalWrite(RELAY_1, HIGH);
else {
digitalWrite(RELAY_1, LOW);
sensorValue = analogRead(SOUND);
Serial.println(sensorValue, DEC);
if (sensorValue <= 5) {
digitalWrite(RELAY_3, HIGH);
else {
digitalWrite(RELAY_3, LOW);


int chk =;
Serial.print("Read sensor: ");
switch (chk)

Serial.print("Temperature (C): ");
Serial.println(DHT11.temperature, DEC);
if(DHT11.temperature < 30)//change to match your threshold in C.

digitalWrite(heatrelaypin, HIGH);//turn on the heater


digitalWrite(heatrelaypin, LOW);



    switch (chk)Why switch and no cases ?

:) should I delete it ?


Almawali: ok

Full marks for brevity :)