Hi guys,
I've tried to merge 3 sketches together and I'm getting conflicting declarations. I know what I am doing wrong but I don't have the experience or knowledge to rectify it. I'm very very new to Arduino so please excuse my ignorance.
This is my sketch here:
#include <dht.h>
#define dht_apin A0 // Analog Pin sensor is connected to
int ledPin = 13; // choose the pin for the LED
int inputPin = 2; // PIR input pin (for PIR sensor)
int pirState = LOW; // we start, assuming no motion detected
int val = 0; // variable for reading the pin status
int sensorPin=7; // microphone input pin
boolean val =0;
int tempPin=A0; // Temperature input pin
boolean val =0;
dht DHT;
void setup() {
pinMode(ledPin, OUTPUT); // declare LED as output
pinMode(inputPin, INPUT); // declare PIR sensor as input
pinMode(sensorPin, INPUT); // declare microphone input
pinMode(tempPin, INPUT);
Serial.begin(9600);
delay(500); //Delay to let system boot
Serial.println("DHT11 Humidity & temperature Sensor\n\n");
delay(1000); //Wait before accessing Sensor
Serial.begin(9600);
}
void loop(){
// Start of PIR sensor
val = digitalRead(inputPin); // read input value
if (val == HIGH) { // check if the input is HIGH
digitalWrite(ledPin, HIGH); // turn LED ON
if (pirState == LOW) {
// we have just turned on
Serial.println("Motion detected!");
// We only want to print on the output change, not state
pirState = HIGH;
}
} else {
digitalWrite(ledPin, LOW); // turn LED OFF
if (pirState == HIGH){
// we have just turned of
Serial.println("Motion ended!");
// We only want to print on the output change, not state
pirState = LOW;
}
}
// Start of Mic program
val =digitalRead(sensorPin);
Serial.println (val);
// when the sensor detects a signal above the threshold value, LED flashes
if (val==HIGH) {
digitalWrite(ledPin, HIGH);
}
else {
digitalWrite(ledPin, LOW);
//Start of Temp Program
val =digitalRead(tempPin);
Serial.println (val);
// when the sensor detects a signal above the threshold value, LED flashes
if (val==HIGH) {
digitalWrite(ledPin, HIGH);
}
else {
digitalWrite(ledPin, LOW);
}
DHT.read11(dht_apin);
Serial.print("Current humidity = ");
Serial.print(DHT.humidity);
Serial.print("% ");
Serial.print("temperature = ");
Serial.print(DHT.temperature);
Serial.println("C ");
delay(5000);//Wait 5 seconds before accessing sensor again.
//Fastest should be once every two seconds.
}
}
I'm really struggling with this so any help, even if it is just a minor little tweak to set me on my way would be great.
I'm wanting the project to read the digital signal from the PIR and Microphone and if detected, output for 5 seconds and then turn off. The temperature is just there to monitor and will not control any outputs.
It conflicts immediately at the 'boolean val'... I can see my error but I don't know what to change it to. Really struggling so any help would be great. Thanks