I've added a sound sensor and LED that lights up when it hears a sound. I've tried the sound sensor code only and it works but when i add the code to the others, it stops working.
#include <dht.h>
#include <Servo.h>
#define DHT11_PIN 2
#define DHTTYPE DHT11
Servo servo;
dht DHT;
//Servo
int moto = 8;
int angle = 0;
int tempe = 40;
//Sound
int soundpin=6;
int ledpin=7;
void setup() {
// put your setup code here, to run once:
//Sound
pinMode(ledpin,OUTPUT);
pinMode(soundpin,INPUT);
Serial.begin(9600);
servo.attach(moto);
}
void loop() {
// put your main code here, to run repeatedly:
//Sound Sensor
int statusSensor = digitalRead(soundpin);
if(statusSensor == 1)
{
digitalWrite(ledpin,HIGH);
}
else{
digitalWrite(ledpin,LOW);
}
//Humidity Sensor
int chk = DHT.read11(DHT11_PIN);
Serial.print("Temperature = ");
Serial.println(DHT.temperature);
Serial.print("Humidity = ");
Serial.println(DHT.humidity);
delay(2000);
//Servo Motor
if(DHT.temperature >= tempe)
{
for(angle = 10; angle < 180; angle++)
{
servo.write(angle);
delay(10);
}
}
}