hi guys,
i am really stuck in merging 2 codes, could anyone please help.
the thing is my main code is about up loading data (temperature and humidity; analog pir sensors) to thingspeak (it work just well)
the other part is 2 digital pir sensors which turn on the led when the dark time (combine with photoresistor). this part work well if i run it separately
int led = 13; // the pin that the LED is atteched to
int sensor111 = 2; // the pin that the sensor is atteched to
int sensor222 = 3; // the pin that the sensor is atteched to
int state111 = LOW; // by default, no motion detected
int val11 = 0; // variable to store the sensor status (value)
int val22 = 0; // variable to store the sensor status (value)
const int ldrPin = A0; //the number of the LDR pin
void setup() {
pinMode(led, OUTPUT); // initalize LED as an output
pinMode(sensor111, INPUT); // initialize sensor as an input
pinMode(sensor222, INPUT); // initialize sensor as an input
pinMode(ldrPin, INPUT); //initialize the LDR pin as an input
Serial.begin(9600); // initialize serial
}
void loop(){
val11 = digitalRead(sensor111); // read sensor value
val22 = digitalRead(sensor222); // read sensor value
int ldrStatus = analogRead(ldrPin); //read the status of the LDR value
Serial.println(ldrStatus);
if ((val11 == HIGH || val22 == HIGH) && ldrStatus <=700) { // check if the sensor is HIGH
digitalWrite(led, HIGH); // turn LED ON
delay(100); // delay 100 milliseconds
if (state111 == LOW) {
Serial.println("Motion detected!");
state111 = HIGH; // update variable state to HIGH
Serial.println( "LDR is DARK, LED is ON");
}
}
else {
digitalWrite(led, LOW); // turn LED OFF
delay(200); // delay 200 milliseconds
if (state111 == HIGH){
Serial.println("Motion stopped!");
state111 = LOW; // update variable state to LOW
}
}
}
when i try to merge the code, the light not turn on anymore. when i checked the code: i tried to remove 1 by 1 each function in the void loop. i realised that the Inital() and upload_to_Gateway() is the 2 parts which make the led code not working when combining.
could anyone please help me check and how to fix it.
thank you very much
below is my full code:
final_client.ino (12.1 KB)