GeneralSpud
Published © GPL3+

Toggle Switch

I wanted to figure out how to use a toggle switch with Arduino! I looked around online and compiled a few different things to get this.

BeginnerProtip64,014
Toggle Switch

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Gikfun MTS102 2 Position 3 Pins Mini Toggle Switch for Arduino (Pack of 10pcs) EK2021
×1
Resistor 1k ohm
Resistor 1k ohm
×2
5 mm LED: Green
5 mm LED: Green
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
Solder Wire, Lead Free
Solder Wire, Lead Free

Story

Read more

Schematics

Toggle Switch Wiring

A Fritzing Diagram for the wiring.

Switch Solder

A closer look at the soldered toggle switch.

Code

Toggle Switch Code

Arduino
The basic code. It uses the digital pins on the board.
int switch_pin = 4;
int led_pin = 5;

byte leds = 0;

void setup() {
  pinMode(switch_pin, INPUT);
  pinMode(led_pin, OUTPUT);
}

void loop() {
  if(digitalRead(switch_pin) == HIGH){
    digitalWrite(led_pin, LOW);
  }
  if(digitalRead(switch_pin) == LOW){
    digitalWrite(led_pin, HIGH);
  }

}

Credits

GeneralSpud

GeneralSpud

0 projects • 3 followers

Comments