Arduino · Einsteiger · Stufe 4 / 40
Digital Inputs: Buttons, Switches and Decisions
Read switches reliably and make programs react with conditions and modes.
Einsteiger freischalten · CHF 9.90 Stufen 1–13, einmalig, kein Abo
10 Lektionen in dieser Stufe
- Reading a Push Button with digitalRead
Configure a pin as input and read its logic level. · Lab: Wire a button to 5 V with a pull-down resistor and mirror its state on an LED. - Floating Inputs and the Pull-Down Resistor
Explain why an unconnected input gives random readings and how a resistor fixes it. · Lab: Remove the pull-down, watch the LED flicker when you move your hand near the wire, then restore it. - INPUT_PULLUP and Inverted Logic
Use the internal pull-up and handle a button that reads LOW when pressed. · Lab: Rewire the button to GND with no external resistor and adapt the sketch. - Decisions with if, else and Comparison Operators
Branch program flow using conditions and comparisons. · Lab: Light a green LED while a button is released and a red one while it is pressed. - Boolean Variables and Logical Operators
Combine conditions with and, or and not and store results in bool variables. · Lab: Require two buttons pressed together to switch on an LED, then either one of them. - Detecting a Press Edge Instead of a Held Level
Remember the previous state to react once per press. · Lab: Count button presses and blink the count back after a pause. - Contact Bounce and a First Software Debounce
Recognise bounce as multiple false edges and suppress it with a short wait. · Lab: Show miscounts from a bouncing button, then add a debounce and compare. - Toggling and Cycling Modes with One Button
Use a counter variable to step through several behaviours. · Lab: Make one button cycle an LED through off, on and blink. - Slide, Tilt and Reed Switches as Inputs
Wire other switch types and understand they are all just contacts. · Lab: Build a tilt alarm LED and a magnet-operated door indicator. - Selecting Behaviour with switch-case
Replace long if chains with a switch statement and avoid fall-through mistakes. · Lab: Rewrite the mode lamp with switch-case and add a fourth mode.
Abschlussprojekt
A pedestrian crossing with a request button plus a lamp whose three modes are cycled by one debounced button.
Teile für diese Stufe
- 1 × UNO-compatible board
- 1 × USB cable matching the board
- 1 × Solderless breadboard 830 points
- 1 × Jumper wire set male-male
- 4 × Tactile push button
- 4 × Resistor 10 kilohm
- 6 × Resistor 220 ohm
- 6 × LED 5 mm assorted
- 1 × Slide switch
- 1 × Tilt switch
- 1 × Reed switch with magnet
In jeder Lektion legst du die passenden Teile direkt in den Warenkorb. Arduino-kompatibel →
Voraussetzung: Levels 1–3: digital outputs, variables, loops and functions.