Microcontroller-based automatic night light circuit
10,350
While discussing an all-linear automatic night light circuit, it was mentioned that an MCU-based Automatic Night Light Controller (ANLC) was being tested. The firmware has been tweaked since then. Recently, the sensor was installed outdoors and connected to control 220VAC loads. The circuit was misled when clouds moved in around 2 AM, reflecting city lights and streetlights, causing the MCU to mistakenly think it was dawn and switch off the load. This occurred because the software algorithm interprets a 10-bit ADC change of just 0x00A from the average dark ambient light level as dawn. The firmware includes a condition to turn the load back on if the light level drops back to the average dark level. Some time later, the load did return to dark level conditions. A Sonalert buzzer is temporarily connected to sound when the load (perimeter security lights) is off, and the next time the load was switched off by the circuit was around 5 AM, which is true dawn. Earlier that evening, while monitoring the voltage output of the sensor ("LDR" in the schematic) with a digital multimeter (DMM), it was observed that the numbers were climbing rapidly. The output had settled at approximately 20 mV but then increased quickly within minutes, peaking at about 310 mV. Upon looking out the window, it was confirmed that the ambient light level was indeed rising due to the sky turning bright orange from cloud cover. The circuit did not turn off the load because the firmware was using a different hysteresis value at that time. Only after the load has been on for six hours does it use the hysteresis value of ten (the previously mentioned 10-bit ADC value). By 2 AM, this six-hour period had already elapsed. To minimize the effect of artificial lights, the light sensor circuit is located on the roof, with the LDR facing directly up (zenith) and housed in a translucent plastic box. The box is shielded on the sides to prevent interference from streetlights and nearby building lights. The very high impedance output of the sensor necessitates a unity gain buffer. The LDR has a resistance greater than 30 MΩ in complete darkness. On the main control board, a low-pass filter consisting of RLPF and CLPF (cut-off frequency = 1/(2πRC) = 1/(6.28*100K*0.1uF) = 16 Hz) attenuates high-frequency noise, particularly from electromagnetic interference (EMI) such as lightning. A unity gain buffer is employed to provide a low impedance signal for the MCU. A high-value load resistor (RL) is used to prevent the input of the LPF and buffer from floating in the event of a cable break to the sensor. In such a case, RL grounds the input, causing the MCU to assume it is nighttime and activate the load, alerting the user to a malfunction during the day. The push button (PB) is utilized to select the light level at which the load will be turned on. The user waits until the ambient light level reaches the desired point for the load to activate, then presses PB. The circuit stores this light level in EEPROM and uses it until changed. Pressing and holding PB for a second resets the value to its minimum (arbitrarily set to ADC value 0x064), meaning the load will only turn on when it is genuinely dark. The LED indicator (LY) for PB flashes briefly when PB is pressed (falling edge detected) and blinks on and off for 1.5 seconds when the trip level has been reset to the minimum. A debouncing routine is implemented to debounce PB, detect falling/rising edges, and monitor how long PB has been pressed. REL1 and REL2 are mini relays with a 24VAC coil.
The automatic night light circuit described operates using a microcontroller (MCU) that processes inputs from a light-dependent resistor (LDR) to control the activation of outdoor lighting based on ambient light levels. The LDR serves as the primary sensor, detecting changes in light intensity and providing a variable resistance that the MCU interprets through an analog-to-digital converter (ADC). The firmware logic includes thresholds for determining when to turn the lights on or off, incorporating hysteresis to avoid rapid cycling due to transient light changes.
The physical setup of the sensor is crucial for accurate readings; positioning the LDR on the roof with a zenith orientation minimizes interference from artificial light sources. The translucent housing protects the LDR while allowing sufficient light penetration for accurate measurements. The use of a unity gain buffer ensures that the high impedance output of the LDR is transformed into a low impedance signal suitable for processing by the MCU, which is essential for maintaining signal integrity and avoiding noise interference.
The low-pass filter implemented on the control board plays a vital role in filtering out high-frequency noise that could disrupt the ADC readings, particularly in environments prone to electromagnetic interference. The design choice of including a high-value load resistor (RL) acts as a fail-safe mechanism, ensuring the circuit behaves predictably in the event of a sensor cable failure.
User interaction is facilitated through a push button (PB) that allows manual setting of the light activation threshold. This feature, combined with EEPROM storage, enables the user to customize the light level at which the circuit will activate the load, enhancing the versatility of the night light system. The indicator light (LY) provides visual feedback during the configuration process, ensuring the user is informed of the current settings.
Overall, the circuit design emphasizes reliability, user configurability, and adaptability to varying ambient conditions, making it suitable for outdoor lighting applications where accurate light sensing is critical.While discussing an all-linear automatic night light circuit I mentioned that I was testing an MCU-based ANLC. Well, I`ve been tweaking the firmware since. The other day I installed the sensor outdoors and have connected the circuit to control 220VAC loads.
Last night the circuit got fooled when clouds moved in at around 2am and reflected sufficie nt city lights and streetlights that the MCU thought it was already the beginning of dawn and switched off the load. This is because the software algorithm is such that a 10-bit ADC change of just 0x00A from the average dark ambient light level is interpreted as dawn.
Competent programmer that I am, the firmware also includes a conditional which turns the load back on again should the light level drop back to the average dark level. And some half hour or an hour later (not sure because I went back to sleep before waking up again some time later) it did actually did return to dark level conditions.
A sonalert buzzer is temporarily hooked up such that it sounds when the load (perimeter security lights) is off and as far as I know (sleepy head that I am) the next time the load was switched off by the circuit was around 5am-true dawn. Earlier that same evening at around midnight while remotely monitoring the voltage output of the sensor ("ldr" in the schematic) with a DMM I was surprised to see the numbers climbing rapidly.
The output had already settled at ~20mV but then increased quickly within minutes and peaked at ~310mV. I had to look out the window just to make sure I wasn`t witnessing a circuit glitch but that in fact ambient light level was shooting up.
And true enough the sky had turned orange and bright-from the cloud cover. The circuit did not turn the load off because the firmware was using a different hysteresis value at that time. Only after the load has been on for six hours does it use the hysteresis value of ten (the 10-bit ADC value mentioned above).
By 2am this six hours had already elapsed. Because of the detection sensitivity used, the light sensor circuit is located on the roof to minimize being affected by artificial lights. The LDR faces directly up (zenith) and is housed in a translucent plastic box. The box is shielded on the sides to prevent streetlights and lights from nearby buildings and billboards from unduly affecting the sensor.
The very high impedance output of the sensor requires a unity gain buffer. The LDR used has a resistance of >30Mohms in complete darkness. On the main control board, a low pass filter comprised of RLPF and CLPF (cut off frequency = 1/(2 RC) = 1/(6. 28*100K*0. 1uF) = 16Hz) attenuates high frequency noise which could be caused by EMI particularly those from lightning.
A unity gain buffer is used to provide a low impedance signal for the MCU. High value load resistor RL is used because in the event that the cable to the sensor breaks, the input of the LPF and buffer will not be left floating. In such an event RL grounds the input, fooling the MCU to think that it`s nighttime and thus turning on the load.
This serves to alert the user (in the daytime) of a malfunction. PB is used to select the light level at which load will be turned on. The user waits until the ambient light level is at the point where s/he wants the load switched on. At that moment PB is pressed. The circuit stores the light level in EEPROM and uses this value until it is changed. Pressing and holding down PB for a second resets the value to its minimum (I arbitrarily set it ADC value 0x064)-meaning load will be turned on only when it`s really dark. LY is the indicator light for PB. It flashes briefly when PB is pressed (falling edge detected) and it blinks on and off for 1. 5s when the trip level has been reset to minimum. A debouncing routine is used to, well, debounce PB, detect falling/rising edges, and monitor how long PB has been depressed.
Calculate magnification, input resistance, and output resistance circuit.
This circuit is designed to calculate the magnification, input resistance, and output resistance of a given electronic system. The magnification refers to the ratio of the output signal to the input signal,...
This is a straightforward circuit for an emergency light that can be assembled with relative ease. The components include two transistors, a transformer, a 20 Watt fluorescent tube, a 6V battery, and several resistors and potentiometers. The transformer in...
A block diagram of the stereo-TV decoder illustrates the overall relationships between the distinct sections of the circuit, while additional details of each subsection are provided. The decoder section is centered around TCI, a standard 4.5-MHz audio demodulator. The...
This Low Dropout Voltage (LDO) solar charge controller utilizes a straightforward differential amplifier combined with a series P-channel MOSFET linear regulator, ensuring compatibility and efficiency in solar energy applications.
The Low Dropout Voltage (LDO) solar charge controller is designed to...
This document outlines the installation process for a SPY5000 two-way motorcycle alarm on a 1998 Honda CB250 Nighthawk motorcycle.
The SPY5000 two-way motorcycle alarm system is designed to enhance the security of motorcycles by providing features such as remote...
The TDA1521A amplifier circuit is designed for high-fidelity applications with minimal external components. It is suitable for powering Walkman devices or transforming low-powered computer speakers. The TDA1521A comes in a nine-pin single in-line plastic package and offers output power...
We use cookies to enhance your experience, analyze traffic, and serve personalized ads.
By clicking "Accept", you agree to our use of cookies.
Learn more