Use A Push Button With Arduino 2023 - Little Bird Australia
Use A Push Button With Arduino 2023 - Little Bird Australia
Sign In
Deals New Releases Arduino Micro:Bit Raspberry Pi Pico Adafruit SparkFun DFRobot Pololu Waveshare
Difficulty Easy
Steps 8
Introduction
Push button switches are inexpensive and versatile components that have
many uses.
In this guide, we will learn how to use a push button switch together with an
Arduino, to turn an LED on and off. The circuit we will be building, uses a Little
Bird Uno R3, a fully compatible Arduino development board. A mini
pushbutton switch, a 5mm LED, jumper wires, and a mini breadboard is also
required.
Other uses for push buttons are in custom gamepads, DIY radio buttons, MIDI
controllers with push buttons that in conjunction with LEDs would light up
when pressed, and many more!
This resistor will be used to limit the current going to our LED.
Be sure to really push down on the push button so that the bottom of the push
button is flush with the breadboard (this will feel like you're pushing too hard).
void loop()
{
int digitalVal = digitalRead(buttonPin); // Take a reading
if(HIGH == digitalVal)
{
digitalWrite(ledPin,LOW); //Turn the LED off
}
else
{
digitalWrite(ledPin,HIGH);//Turn the LED on
}
}
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT_PULLUP);
}
void loop() {
buttonState = digitalRead(buttonPin);
© 2023 Little Bird Electronics Pty Ltd. Powered by Koi About Us Privacy Policy Terms of Service
Made with ❤ in SYD. All prices inc GST. ABN 15 634 521 449. We're 🐥 @lbhq on Twitter.