Use a microswitch with an Arduino
FunduinoPublished on
Eine LED über einen Mikroschalter schalten
You need this
Mini slide switch - breadboard-compatible, 2.54 mm pitch
0,74 € *Item no. F23106707About the product — Mini slide switch - breadboard-compatible, 2.54 mm pitch
Funduino UNO R3 Microcontroller - ATmega328P, 16 MHz, for Arduino
11,12 € *Item no. F23107480About the product — Funduino UNO R3 Microcontroller - ATmega328P, 16 MHz, for Arduino
830-point Breadboard - solderless breadboard for Arduino
2,90 € *Item no. FUN-1010553About the product — 830-point Breadboard - solderless breadboard for Arduino
Breadboard Cables Male-to-Male - 40 Pieces, 20 cm
1,74 € *Item no. FUN-1010558About the product — Breadboard Cables Male-to-Male - 40 Pieces, 20 cm
LED 5 mm - 100 Pieces, 5 Colors, 2 V
1,97 € *Item no. F23107316About the product — LED 5 mm - 100 Pieces, 5 Colors, 2 V
Resistor Assortment 100 Pieces - 5 Values 100 Ω to 10 kΩ, 0.5 W
1,72 € *Item no. F23107216About the product — Resistor Assortment 100 Pieces - 5 Values 100 Ω to 10 kΩ, 0.5 W
All 6 parts together 20,19 € *Ready to ship immediately · Delivery time: 1-3 business days
* All prices include statutory VAT, plus shipping costs.
The microswitch
Build the circuit
1 / 2
The program
Switch LED via the microswitch
int Sensor = 7;
int Wert;
int LED = 6;
void setup()
{
pinMode(Sensor, INPUT);
pinMode(LED, OUTPUT);
}
void loop ()
{
Wert = digitalRead(Sensor);
if (Wert == 0)
{
// the microswitch was pressed
digitalWrite (LED, HIGH);
}
else
{
// the microswitch was released
digitalWrite (LED, LOW);
}
}Rate the instructions