I was doing a basic light controller with 2 node mcu boards.
Inside the main loop, I have decided to use deep sleep function when the sunlight exists. I am going to use some external function with a LDR for waking up the mcu.
However, when I try that idea in IDE, code is not working at all. The code is given below. I don't see any outputs either in hardware or in the serial monitor.
Thanks,
dea
void loop() {
Serial.println(sleep_state);
if(digitalRead(uyku_modu)== HIGH && ligth_state == 0){
sleep_state = 1;
Serial.println(sleep_state);
ESP.deepSleep(0);
delay(20);
}
else {
Serial.println("devam1");
// Clears the trigPin
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
// Sets the trigPin on HIGH state for 10 micro seconds
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Reads the echoPin, returns the sound wave travel time in microseconds
duration = pulseIn(echoPin, HIGH);
// Calculate the distance
distanceCm = duration * SOUND_VELOCITY/2;
Serial.println(distanceCm);
if (distanceCm < 5.53){
if(man_state == 0){
man_state = 1;
}
else{
man_state = 0;
}
}
else{
man_state = man_state;
}
//man_state = digitalRead(manuel_on_off);
if ((prev_on_signal != on_signal) && ligth_state == 0)
{
//digitalWrite(relay1, HIGH);
servo.write(120); //150 ac
ligth_state = 1;
}
else if ((prev_on_signal != on_signal) && ligth_state == 1)
{
//digitalWrite(relay1, LOW);
servo.write(60); //30 kapa
ligth_state = 0;
}
else if ((man_state != prev_manuel_on_off) && ligth_state == 0)
{
//digitalWrite(relay1, HIGH);
servo.write(120); //150 ac
ligth_state = 1;
}
else if ((man_state != prev_manuel_on_off) && ligth_state == 1)
{
//digitalWrite(relay1, LOW);
servo.write(60); //30 kapa
ligth_state = 0;
}
else
{
Serial.println("SW states are stable");
}
prev_on_signal = on_signal;
prev_manuel_on_off = man_state;
delay(500);
}