7. Night-light

Background

A pot is used to set the triggering threshold for a series of LEDs, thereby creating a cheap nightlight.

We’ll use 2 analog channels, the LDR and the pot thus we have an excuse to use the multiplexer.

The circuit constructed on a breadboard

Hardware Connections

  • 8 LED’s with current-limiting resistors on PORTB
  • Potentiometer on PC3
  • Voltage divider consisting of LDR on top half and a 10k on the bottom. Middle connects to PC0.

The Software

In main.c, we configure and read the ADC and illuminate the LEDs when the threshold is exceeded.

Setting the mux bits

For other modes, you don’t need to worry about changing the multiplexer on the fly. However, in free-running mode, we need to change the channel before we perform an ADC conversion. This involves setting and clearing bits.

The Showcase