How to turn off the lights if it is daytime and turn on when its night?

Hello All,

I’m trying to create a project of emergency lights which will turn on lights when there is a power failure. By default I set the lights GPIO Pin to high, so that as soon as there is a power failure, it will immediately turn on the light and when power comes back the lights will be turned off.

Currently I’m having trouble in setting up the time for my emergency lights. I don’t want it to turn on during the day time, if there is a power failure. How can I achieve that using ESP8266-01 and Blynk.


I guess there are a number of ways…

  1. Have a light sensor that checks the light level in the area that you want to light. Just be sure to structure your code so that turning the lights on doesn’t cause the sensor to immediately turn them off again, because its detected that it’s now light. This system won’t turn the lights off when it gets light outside, unless your sensor isn’t being affected by the internal emergency lights.

  2. Make an API call to service that provides sunrise and sunset times, such as Of course, this assumes that you still have internet connectivity when the power goes off, and that you can parse the data that is returned to calculate whether to turn the lights on or not. If you don’t have internet connectivity then make sure that Blynk code running on your ESP doesn’t block your other code from running.

  3. If you’re running a local Blynk server then you could also run your own run a library such as Suncalc to calculate whether it’s dark or not (using sunset/sunrise).


1 Like

Yeah, I’ll have my wifi working, so ESP8266 will connect to internet.

Your issue is not really Blynk specific, so Google for various code and sensors to do what you need, then merge that into your Blynk project… that is where we can really assist.

A basic LDR (Light Dependent Resistor) will do the trick if it can monitor the light outside… but since the ESP has only 1 ADC you might be better off looking for a full sensor that integrates circuitry to supply a simple digital ON/OFF with adjustable sensitivity.

1 Like