How to Build a Night Light Circuit with a NAND Gate Chip

How to Build a Night Light Circuit with a NAND Gate Chip


Night light


In this project, we will build a night light circuit using a NAND gate chip.

A night light circuit is a circuit in which a light will turn on when the environment becomes dark.

It is a popular commercial product that is used in many places such as for backyard lights for when it gets dark for automatic illumination.

The circuit is very basic. The component that will allow us to detect light is a photoresistor. We will use a photoresistor's light-sensing ability to detect whether the circuit is exposed to darkness or bright light. How this works is that a photoresistor's resistance changes in proportion to the amount of light it is exposed to. In darkness, it has very high resistance. In bright light, its resistance drops dramatically. If placed in a voltage divider circuit with a fixed resistor, we can exploit this resistance-altering behavior so that when connected to a NAND gate, we can produce a HIGH output when the photoresistor is exposed to bright light and a LOW output when the photoresistor is exposed to darkness. All of this will be explained in detail below how exactly this works. But realize that a photoresistor's resistance-changing ability allows us to distinctly know whether it is exposed to darkness or bright light. Knowing this, we can effectively build a night light circuit.


Components Needed

  • 4011 Quad NAND Gate Chip
  • GL5537 Photoresistor
  • 33KΩ Resistor
  • LED
  • 330Ω Resistor


The 4011 chip can be obtained very cheaply from a number of online retailers for just a few cents. One place it can be obtained from is Tayda Electronics at the following link: Tayda Electronics- 4011 Quad 2-Input NAND Gate IC. However, it is a very popular chip and many electronics parts suppliers have them.

The 4011 is a quad NAND gate chip. It is a chip that is made up of 4 independent NAND gates.

The pinout of the 4011 quad NAND gate chip is shown below, so that you can see how to connect it in the circuit.

4011 NAND gate pinout

Each NAND gate has input pins and 1 output pin.

The following chart shows NAND gate logic, which shows what output a NAND gate chip will produce for a set of given inputs.

NAND Gate Logic
Inputs Output
0 0 1
0 1 1
1 0 1
1 1 0


This means that if one of the inputs are a 0, the NAND gate will output a logic HIGH at its output, which means the output will be drawn up to VCC and the load will be powered. If both inputs feeding into the NAND gate are a 1, only then will the NAND gate output a logic LOW at its output, which means the output will be drawn down to GND, and the load will not be powered.

In our circuit, we will use both of these cases.

The other components we need are the LED and the 330Ω resistor in series to limit current to the LED so that it doesn't burn out.

Night Light Circuit Using a NAND Gate

The schematic diagram of the night light circuit using a 4011 NAND gate chip is shown below.

Night light circuit with NAND gate

Below is the breadboard schematic version of the above circuit so that you can see the exact wiring of the circuit to the 4011 chip.

Night light circuit with NAND gate chip

First and foremost, we must give power to the 4011 NAND gate chip. We will feed it 5V of power, so we give +5V to pin 14 and we connect pin 7 to GND. This establishes power to the chip.

The circuit is very basic. The component that allows us to detect light is a photoresistor. We set up a voltage divider circuit composed of a photoresistor and a 33KΩ fixed resistor. In a voltage divider circuit, voltage is distributed across the components in direct proportion to the amount of resistance each component offers. The more resistance a component offers in relation to the other, the more voltage that will fall across that component. This is shown in the ohm's law formula, V= IR. You can see the direct relationship between voltage and resistance in the formula. The greater the resistance a component offers, the more voltage that falls across it. Conversely, the less resistance a component offers, the less voltage that falls across it.

When a photoresistor is exposed to either room lighting or bright, it offers very low resistance. With this lighting condition, the resistance it offers will be lower than the 33KΩ of resistance that the fixed resistor offers. Therefore, most of the voltage in the voltage divider circuit will fall across the fixed resistor rather than the photoresistor. With more than half of the supply voltage falling across the fixed resistor and this junction being connected to the inputs of the NAND gate, a logic level of HIGH (or 1) will be interpreted by the NAND gate. Since the inputs are tied together, they will be both be logic 1s, so the output will be LOW (or 0). Therefore, with bright lighting, the LED will not be powered on.

However, when the photoresistor is exposed to darkness, it has very high resistance, in the order of a few megohms (MΩ). With resistance this high, most of the voltage from the power supply falls across the photoresistor, with very little voltage falling across the 33KΩ fixed resistor. Thus, when connected to the inputs of NAND gate, with voltage so low, the NAND gate will essentially interpret the voltage divider as if it were LOW (or 0). When the voltage feeding the inputs of a NAND gate is less than half of the power supply voltage, it will interpret it as a LOW value. Since we will tie both inputs together, the NAND gate will interpret this as two zeros, so it will output a logic value of 1 (or HIGH), which means the output will be drawn up to VCC and the load, the LED, will be powered on.

Remember, NAND gate logic, two 1s gives a 0. This is the only time we get an output value of 0 in NAND gate logic. If a 0 is present anywhere in the inputs, including twice, the NAND gate will output a 1.

So you can see how this voltage divider circuit allows us to get 2 different logic levels produced by the NAND gate chip in different lighting conditions.

To see how this circuit works in real life, see the video below.





Related Resources

How to Build a Night Light Circuit with an LM741 Op Amp

HTML Comment Box is loading comments...