Raspberry Pi Pico LDR Sensor:
Raspberry Pi Pico LDR sensor for Day and Night Detection– In this article, I will show you how to make the day and night detection system. This is really an important example as I will be explaining how to use an LDR Light sensor and a relay module for controlling a 110/220Vac Light Bulb. This Light sensor is designed in a way that it only gives 1 or 0 as the output signal which makes it really easy to use. The light intensity level can be adjusted using this blue color potentiometer. Now, let’s go ahead and take a look at the circuit diagram.
Other Tools and Components:
*Please Note: These are affiliate links. I may make a commission if you buy the components through these links. I would appreciate your support in this way!
Raspberry Pi Pico Day and Night Detection Circuit:
The VCC and GND pins of the LDR module are connected with 3.3Volts and GND pins of the Raspberry Pi Pico while the D0 pin of the LDR module is connected with the GP14. This LDR module is slightly different from the one I will be using. This LDR module also gives analog output. While the one I am using gives only digital output.
The one channel relay module is controlled using the GP28 pin of the Raspberry Pi Pico. You can follow these connections if you want to make your own Relay module or you can use a readymade relay module. The 2n2222 NPN transistor and a10k ohm resistor makes the driver. I have a very detailed video on how to design your own driver circuit for different types of relays. I will add a link in the description.
Anyway, the Neutral wire from the 110/220Vac is directly connected with the light and the live wire from the supply is connected with the other contact of the light through this relay. So, that’s all about the connections.
Raspberry Pi Pico Day and Night Detection Code:
from machine import Pin import time relay = Pin(28, Pin.OUT) ldr = Pin(14, Pin.IN, Pin.PULL_DOWN) while True: if ldr.value(): relay.value(1) time.sleep(0.5) else: relay.value(0) time.sleep(0.5)
I defined two pins and I am going to call these as relay and ldr. As relay is an output device so that’s why I set it as output and as you know LDR sensor is an input device so that’s why I set it as input. Finally, we use an if condition to check if the output on the LDR sensor module is high or Low. So, if the Pico board detects a high signal then the Relay is turned ON, else the relay is turned OFF. Now, let’s go ahead and run this code.
When there is light falling on the LDR sensor then the light remains OFF.
When the light on the LDR sensor falls below a preset value then the light turns ON. Using these few electronic components you can make yourself a fully automatic street lights control system or Lawn lights control system, etc.