Three-way switch
Two SPDT slide switches joined by two traveler wires turn one LED on and off from either end, on a 12 V stand-in supply that models the idea and is not house wiring. There is no microcontroller in it: the simulator solves the 4 parts as a circuit, so it runs the moment you press Run, and nothing needs compiling.
Teaching? Assign it to your class in one click.
Beginner About 15 minutes to build and run. Runs in your browser. Free, and no account needed.
The parts retail for about $5.45. On Mokxi they're free.
What you'll learn
- Lights
- School
- Choosing and reading a resistor
- How an LED lights and why it needs a resistor
- Difficulty: Beginner
- Time: About 15 minutes
- Parts: 6
How it works
Two SPDT slide switches joined by two traveler wires turn one LED on and off from either end, on a 12 V stand-in supply that models the idea and is not house wiring.
There is no code. The simulator solves Slide switch, Resistor, 1k Ω, LED, red as it is wired, so change a value in the editor and watch the result.
Parts list
6 parts, plus the jumper wires. They retail for about $5.45; on Mokxi they're free.
- 1 × Full-size breadboard
- 1 × Power, 12 V
- 2 × Slide switchIn Logic Lab Kit, Spaceship Panel Kit.
- 1 × Resistor, 1k ΩIn Starter Kit, Claw Machine Kit, Halloween Prop Kit.
- 1 × LED, redIn Starter Kit, Halloween Prop Kit, Logic Lab Kit.
Kits that can build it
This starter kit has every part in the circuit. Each kit's page lists what else it can build.
Wiring table
Every connection, pin by pin, read from the circuit itself. Each row joins the pin on the left to the pin on the right, by a jumper wire or a breadboard strip.
| Part and pin | Connects to |
|---|---|
| Slide switch (1) pin 2 | 12 V |
| LED, red pin C | Ground |
| Slide switch (2) pin 1 | Slide switch (1) pin 1 |
| Slide switch (2) pin 3 | Slide switch (1) pin 3 |
| Resistor, 1k Ω pin 1 | Slide switch (2) pin 2 |
| LED, red pin A | Resistor, 1k Ω pin 2 |
The notes that come with it
There is no microcontroller in this one, so nothing is compiled: the simulator solves the circuit itself. The file in the editor is the notes that come with it.
// A three-way switch: two switches, one light, flip either one.
//
// There is no microcontroller here. Press Run and the simulator solves the
// circuit. This is a teaching model on a 12 V stand-in supply, not house
// wiring: never connect it to mains or to a building's circuits.
//
// HOW IT IS WIRED. Both switches are SPDT (single pole, double throw): one
// common terminal and two throws. The slide switch's pins are 1, 2 and 3,
// and pin 2 is the common.
//
// 12 V --> switch 1 COMMON (hot, in from the source)
// switch 1 pin 1 --- traveler A --- switch 2 pin 3
// switch 1 pin 3 --- traveler B --- switch 2 pin 1
// switch 2 COMMON (the load side) --> 1 k resistor --> LED --> ground
//
// WHY IT WORKS. Switch 1 sends the hot to one traveler or the other. Switch
// 2 listens to one traveler or the other. The light is on only when switch
// 2 is listening to the traveler that switch 1 is feeding. Flip either switch
// and the match changes, so the light toggles. With the toggles both up the
// light is off, and every flip of either one swaps it: off, on, off, on.
//
// switch 1 switch 2 light
// up up off
// up down on
// down up on
// down down off
//
// ("up" is the slide switch's position 0, "down" is position 1.)
//
// THINGS TO TRY. Cut a traveler (delete one wire) and watch which two
// positions still light the lamp. A 4-way adds a reversing switch between
// these two that swaps the travelers; see the four-way code project.
Troubleshooting
The usual mistakes with this circuit, and the fix for each.
- The input reads random values in one position. Slide switch
A switch only connects or disconnects. Add a pull-up or pull-down resistor, or use INPUT_PULLUP, so the pin has a defined level when the switch is open. - The load never turns on when the switch is flipped. Slide switch
Use the center (common) leg and one outer leg. The unused outer leg goes nowhere. Check that the switch is in series with the load. - The LED is dim, burns out, or the pin reads wrong because the resistor value is off. Resistor
Read the color bands again. A 220 ohm to 330 ohm resistor suits a typical LED on 5 V. 10k is a common pull-up or pull-down value. Check with a multimeter if unsure. - A pull-up or pull-down resistor is missing, so the input floats and reads random values. Resistor
Tie the input to 5 V or ground through about 10k. Or use INPUT_PULLUP and wire the switch to ground. - The LED does not light, or it lights once and then dies. LED
LEDs have polarity. The longer leg (anode) goes toward the positive side. Always add a series resistor, about 220 ohms to 1 k ohm on a 5 V pin. - A blue or white LED stays dark on 3.3 V. LED
Blue and white LEDs drop about 3 V, so 3.3 V leaves almost nothing for the resistor. Use a 5 V supply, or a smaller resistor and a red or green LED.
Change it and keep it
Open it in the editor, change the circuit or the code, and keep your version in a free account.