Through an introduction to electronics course, I was able to learn the basics of a night light circuit and went through the prototyping process using a breadboard and the soldering process that brought the circuit to life.
What is a Goodnight Light Circuit?
A Goodnight Light Circuit, also known as the night light circuit, senses the environment's light intensity and turns an LED on when it is relatively dark in the surroundings.
The photoresistor used in the circuit is responsible for detecting the light intensity. It reports different resistance readings, with high resistance as dark and lower resistance as bright.
To convert the photoresistor readings from resistance to a voltage value, we utilize the characteristic of voltage dividers in a circuit. When two resistors are connected in series and a wire is plugged in between the two resistors, making them parallel, the voltage going out from the wire would be the second resistor's resistance divided by the sum of the two resistances.
This is useful because by placing the photoresistor at the R2 position, we could derive a voltage output that can be compared.
To compare the voltage derived by our voltage divider for the photoresistor to a threshold that indicates bright and dark, we need to use an Op-Amp (operational amplifier).
While an op-amp could have multiple usages such as applying different math equations to electronic signals or amplifying signals, we here uses it as a comparator. When the non-inverting input of the op-amp exceeds the inverting input, the output voltage will equal the positive voltage input of the op-amp.
Knowing this logic, we could set the non-inverting input as our threshold, while the inverting input can be the actual voltage that has been derived from the photoresistor's resistance value.
When it senses smaller resistance (it's bright enough), the resulting voltage is smaller than the threshold; the LED gets no voltage input (since V- is the ground), and vice versa.
The whole goodnight light circuit looks like the one above.
Breadboard Prototyping
Before designing the schematic and the actual PCB, prototyping is a good way for us to understand how the circuit should be wired to serve the function of the goodnight light.
An interesting fact I have learned about resistors is that the resistance can be read from the stripes and colors on the resistor itself. The first few bands are the significant figures of the resistance, and the second-to-last band is the multiplier, while the last band is the tolerance.
Otherwise, done by measuring with a multimeter (which is usually faster), reading the resistance from the color may help you identify some really common resistances like 10 kΩ and can help you identify resistors that have the same values easily too.
My final circuit looks like the one above. After finishing the prototype, I began to wonder how it translates to an actual circuit and what each pin on the op-amps represents.
That led me to look up the datasheet for the op-amp that we used: LM358-N. I first tried to draw out the circuit and figure out which pin corresponds to which. To my surprise, my initial evaluation was right, and that gave me a great sense of accomplishment.
Then, I tried to draw out the circuit of the prototype that I built, and it connected to how circuits are read on the breadboard since it was in a completely different configuration. The calculated threshold and the dark and bright conditions for the photoresistor made sense, as the threshold is in between the bright and dark values.
To help myself understand better what the breadboard circuit looks like, I spent some time drawing out the board in Tinkercad based on my memory and refined it to fit the prototype.
Converting into Schematic and PCB Layout
The next step is to convert the breadboard prototype into a KiCad schematic layout that is later used to convert to the actual PCB layout.
A few differences were noted while converting. First of all, the battery header is required as part of the circuit because we have to tell the circuit where our power will be coming from. The power flags are the indications for where the battery wires will connect.
The next difference I have noticed is how the op-amp is divided into different units to display in the schematic instead of the normal op-amp display with 5 pins. This is because the LM358 op-amp we are using has 8 pins and has an A and B op-amp within, each providing 3 pins, while the V+ and V- pins are shared between the two (marked as Unit C).
Since we only used the A pins, only unit A and unit C of the op-amp are required. Unit C connects to V+, which in this case is the 9V battery, while V- connects to the ground. I have noted that a diode is required here because it helps prevent the circuit from crashing if the battery is accidentally plugged backwards. The forward-biased diode only allows current to flow when the anode is more positive than the cathode, which current only flows through if the anode is 9V in this case (connected correctly).
Additionally, a capacitor is needed between the 9V and the ground, especially closer to the battery source. This is a decoupling capacitor that helps cope with sudden surges in voltage demand when lighting up the LED. The charge inside the capacitor (charged to 9V at steady state) will discharge to meet the demands first to prevent damage to the battery.
I then convert the finished schematic into the PCB layout editor and lay it out after assigning footprints (how the actual component looks in PCB layout) to each component.
The steps are as follows:
- Set the boundaries of the PCB to 1 inch x 1 inch
- Arrange the components inside the schematic (put the LED further away from the photoresistor to avoid a "while true" loop, and put the decoupling capacitor closer to the battery)
- Reference the schematic layout to know which components are connected to which
- Connect the wires between components (leave ground and power source)
- Fill the top layer as +9V, and the bottom layer as GND
- Do the final wiring of the GND using vias to the second layer
- Run DRC and fix any warnings and errors
Unfortunately, since there are PCB boards and components provided by the course, and there are usually minimum order requirements for manufacturing, my own layout wouldn't be used for final soldering.
Soldering and Testing
As instructed, I started with the surface-mounted components first, which are the resistors, the op-amp, the capacitor, and the diode.
I first started with the resistors. Since it's my first time soldering, I haven't quite grasped the sequence of applying solder to the components, and some of the "surface-mounted" resistors look like they're floating in the air.
After several attempts and trial and error (the solder is easy to fix by reheating it), I finished the resistors and moved on to the op-amp.
The op-amp has 8 very close pins, and the op-amp itself is also super close to other resistors. While soldering the op-amp, I alternated between sides and made sure that the pen was only touching one pin at a time. A resistor near an op-amp was once moved and turned because I accidentally touched a soldered resistor with the pen while soldering the op-amp, but it was an easy fix, as I reheated the resistor connection points and reapplied solder.
For the diode, instead of applying solder onto the component and the plate, I was taught to apply solder onto the plate first to provide a base for the diode to better connect to the board, as the pads for diodes were small.
Through-hole components were soldered using a different method. I had to heat up the holes first and push the solder into the hole to fill it up. It created a little volcano shape around the wires, indicating a successful solder with just the right amount of solder used.
Not surprisingly, the circuit did NOT work on the first try, as the LED wouldn't light up. With the help of the TAs, we investigated each connection using a multimeter to identify where the circuit might not have been completed, but we found none.
It came out to be the LED that was broken because by touching another LED to the board, it lighted up perfectly. I first attempted to remove the solder from the holes by heating it up and removing it a little by little, but it couldn't be fully cleared, and the LED still remained in place.
Collaborating with one of the TAs, we cut the LED down to only the wires and pulled the wires out while heating up the solder. Then we used a desoldering pump to suck out the solder from the holes, leaving us with a clean hole to place a new LED inside.
The final result was successful!!
The whole process, from understanding a circuit, building a prototype for the circuit, and finally soldering an actual circuit, allowed me to gain a lot of knowledge and experience. I really hope to carry the experience forward to making larger and larger projects in the future.






































