Lights
Dimmer lamp
Turn a dial and an LED goes from off to full brightness, like the dimmer on a bedside lamp.
- Easy
- about 20 min
- Arduino Uno
- No soldering
- 7 parts
- 6 wires
- 14 lines of code
Opens this circuit, already wired, with the sketch loaded. Free, nothing to install.
Idea
The Arduino reads how far the dial is turned and sets the LED to match. It is the smallest project that reads something from the world and changes something in it.
What you learn
Reading a range with analogRead(), scaling it with map(), and dimming with analogWrite().
How it works
input
Dial (potentiometer)
decides
Arduino Uno
output
LED
Powered with 5 V from the Uno's USB cable. No battery and no soldering.
This circuit and sketch are run in the ManuStem simulator before the pack is published. Real parts vary between makers: follow the labels printed on your own module, not its position in the picture.
Parts
0 of 7 ready
No prices here: they change by shop and by week. Buy each part by its name and the note beside it.
You also need
A computer with Arduino IDE 2 installed (free)
3D wiring
One jumper per step. Unplug the USB cable while you wire.
Step 0 of 6
Lay out the parts
Push the small parts into the breadboard as shown. Nothing is connected yet.
All connections
dial-lamp.ino
// Dimmer lamp
// ManuStem Build Pack: https://stem.manusignal.com/packs/dial-lamp
const int LED_PIN = 9;
const int DIAL_PIN = A0;
void setup() {
pinMode(LED_PIN, OUTPUT);
}
void loop() {
int reading = analogRead(DIAL_PIN);
int brightness = map(reading, 0, 1023, 0, 255);
analogWrite(LED_PIN, brightness);
}
Libraries
None. It uses only what the Arduino IDE has built in.
Uploading
- Open the sketch in Arduino IDE.
- Plug the Uno in with the USB cable.
- Tools > Board > Arduino Uno, then Tools > Port and choose the board's port.
- Press Upload (the arrow). Wait for “Done uploading”.