Chapter 01: Moving In

Dim the Lights! (Potentiometers & Pusle Width Modulation)

Power Management Crisis

The bunker's emergency lights cast harsh shadows across your workstation as you study the power consumption readings. Three weeks into your underground survival, the battery management system you built is working perfectly—too perfectly. The photoresistor detects ambient light, the charging circuit responds accordingly, and the warning system alerts you when power runs low. But there's a problem you didn't anticipate.

Your lights are burning through battery power faster than expected. The LEDs you installed are blazing at full brightness, designed for maximum visibility during the chaos of the initial apocalypse. But now, settled into your routine, you realize you don't need aircraft-landing-strip illumination to read your technical manuals or work on electronics projects.

The warning beeps have been sounding more frequently, cutting into your precious work time as the system shuts down to preserve battery life. You need a solution—a way to dial down the power consumption without losing functionality. In the scattered electronics supplies, you find a small, promising component: a potentiometer. This simple analog control could be the key to extending your battery life and keeping your sanctuary operational through the long nights ahead.

Time to add some finesse to your power system. Instead of crude on-off control, you'll implement variable brightness—giving your battery management system the efficiency upgrade it desperately needs. The survival of your underground operation may well depend on mastering this delicate balance between power and performance.

What You'll Learn

When you finish this lesson, you'll be able to:

  • Wire and read analog input from a potentiometer to create user-controllable settings
  • Implement Pulse Width Modulation (PWM) to control LED brightness with precise analog-like output
  • Use the map() function to convert between different value ranges seamlessly
  • Combine analog input with PWM output to create responsive dimmer controls
  • Integrate variable power consumption into your battery management system
  • Debug analog circuits using Serial Monitor plotting to visualize real-time data

Understanding Potentiometers and PWM

A potentiometer is like a volume knob for electricity. Inside that small component is a resistive track—imagine a straight road made of material that resists electrical flow. At one end of this road sits the full voltage (like a mountain), at the other end sits ground (sea level). A wiper contact moves along this road as you turn the knob, essentially choosing where along the voltage mountain you want to tap into the signal.

Turn the knob fully counterclockwise, and the wiper sits at ground—you get zero volts. Turn it fully clockwise, and the wiper reaches the peak—you get the full supply voltage. Every position in between gives you a proportional voltage level. Your HERO Board's analog-to-digital converter reads this voltage and converts it to a number between 0 and 1023.

But here's the problem: LEDs don't understand partial voltages the way our eyes understand dimness. Send an LED half voltage, and it might flicker unpredictably or produce uneven brightness. This is where Pulse Width Modulation (PWM) becomes crucial.

PWM is a clever trick that rapidly switches power fully on and fully off. If you flash the LED on for half the time and off for half the time—thousands of times per second—your eye perceives this as half brightness. Flash it on for 25% of the time and off for 75%, and it appears at quarter brightness. The HERO Board can generate these precisely timed pulses on specific pins, giving you smooth analog-like control using purely digital switching.

Wiring the Dimmer Control

Wiring diagram showing potentiometer and components
  1. Connect the potentiometer's left terminal to Ground (GND) - this establishes your voltage floor
  2. Connect the potentiometer's right terminal to 5V power - this creates your voltage ceiling
  3. Connect the middle terminal (wiper) to analog pin A9 - this reads the variable voltage
  4. Ensure your LED connects to pin 44 (a PWM-capable pin) through its current-limiting resistor
  5. Verify your button and photoresistor connections from previous lessons remain intact

The potentiometer acts as a voltage divider. As you turn the knob, you're physically moving a contact along a resistive path, changing the ratio of resistance above and below the wiper connection. This creates a smooth, predictable voltage change that your microcontroller can measure.

Complete Code