กลับไปหน้ารวมไฟล์
simple-led-button-b8fa77.md

Hello.

In this Project, you will create a button press LED. When The button is pressed, the LED will turn on. In the Tips and Tricks after the trouble shooting page, you may add a off button to turn the LED off. Don't worry, the full code will be provided. Finally, don't forget to check out my website and YouTube channel!

Attaching The LED To The Uno

Lets start with adding the LED. The LED will be attached to pin3. Don't forget that the LED is on the digital side, not the Analog. An image is provided below.

Adding The Button To The Uno

Now that we have the LED connected to the Snapino, we may add the button to activate the LED. Add the button to D9 and make sure that the LED and button are connected to ground(GND). You may use a different button, but ensure it is SPST(Single Pole Single Throw).

Writing the CODE

Finally lets write the code. Don't you worry! You ain't writing it all with the indents and curly brackets and brackets and quotation marks! The code is provided below. Make sure you copy and paste it in your IDE. If you do not have the Arduino IDE, see arduino.cc

Enter this code into your IDE:

void setup() {

//button1

pinMode(9, INPUT);

//led1

pinMode(3, OUTPUT);

}

void loop() {

if(digitalRead(9)==LOW){

digitalWrite(3, HIGH);

}

}

____________________________________-______-_______--

Don't forget that DO NOT TYPE void setup() { and void loop() {.

____________________________________-______-_______--

Troubleshooting

If you code does not work, try the following:

Make sure Your Button is connected to ground

Make sure your LED is connected to ground

Make sure you have not used hot glue on your button and it works

Make sure LED is not burnt out or does not work

Try running the Snapino test program to ensure the Snapino UNO is working properly

Tips and Tricks

If you would like to go farther, try one of these tricks:

-- You could add a off button to turn the LED off using this code:

void setup() {

//button1

pinMode(7, INPUT);

//button2

pinMode(8, INPUT);

//led1

pinMode(3, OUTPUT);

}

void loop() {

if(digitalRead(7)==LOW){

digitalWrite(3, HIGH);

}

if(digitalRead(8)==LOW){

digitalWrite(3, LOW);

}

}

The LED would be connected to pin 3 The button to turn it on will be on pin 7 and your off button will be on pin 8.

-- Change the code so the led starts on and you press the button to turn it off using this code:

void setup() {

//button1

pinMode(10, INPUT);

//led1

pinMode(3, OUTPUT);

}

void loop() {

if(digitalRead(10)==LOW){

digitalWrite(3, LOW);

}

}

_______________-___-_-_-__-_-_____-_____-______-_____-_

Successful

That is The end. You just made a code or program to have it where when you press a button, the LED turns on! Great job! Have a good day with your new code! Don't forget to save it on your computer so you can use it again.

Thank you.


🛠️ เจาะลึกเบื้องหลังการทำงาน (Deep Dive / Technical Analysis)

Before you can build robots or smart homes, you must master the fundamental building block of electronics: the LED Circuit. This project teaches you how to control a digital output and protect your components from damage.

Why use a Resistor?

The most important lesson in this project is Current Limiting. An LED is a diode with very little internal resistance. If you connect it directly to the Arduino's 5V pin, it will draw too much current and burn out instantly.

  • The Solution: We place a 220-ohm resistor in series with the LED to limit the current to a safe level (around 20mA).

The Hardware

  • Arduino Uno: Used here as a 5V power source.
  • LED (any color): The output device.
  • 220-ohm Resistor: The protector.
  • Breadboard and Jumper Wires: For clean, solderless connections.

What You'll Learn

By building this, you'll understand polarities (the Anode + and Cathode - of an LED) and the basic layout of a breadboard. It's the simplest project there is, but it's the foundation for every blinking light, indicator, and screen in the world.

ข้อมูล Frontmatter ดั้งเดิม

title: "Simple LED Button"
description: "When you press the button, the LED turns on, Using a Snapino UNO!"
author: "matthewkohn6"
category: ""
tags:
  - "easy"
  - "buttons"
  - "simple"
  - "uno"
  - "snapino"
views: 1457
likes: 0
price: 1499
difficulty: "Easy"
components:
  - "1x LED"
  - "1x Button"
  - "2x Alligator Clips"
tools: []
apps:
  - "1x Arduino IDE"
downloadableFiles:
  - "https://projects.arduinocontent.cc/4760d8c0-3478-494f-ba69-8351c46831ee.ino"
  - "https://projects.arduinocontent.cc/4760d8c0-3478-494f-ba69-8351c46831ee.ino"
  - "https://projects.arduinocontent.cc/4760d8c0-3478-494f-ba69-8351c46831ee.ino"
documentationLinks: []
passwordHash: "6d7f6c80d3492cd06377349a1b6f240161967739bc02a7de1e9848f18ea312f9"
encryptedPayload: "U2FsdGVkX1+QHvz2KujZHXc0eFmmlHihIYE4rQBfOufL5w1VIMCrSqXnEZhY3fNEbC7SqULIY9Zd+dclIE1YJEsq62a1wEsdG5Dyalqt//I="
seoDescription: "Learn to build a Simple LED Button with Snapino UNO. Press the Button to turn on the LED. Perfect for Arduino beginners."
videoLinks: []
heroImage: "https://cdn.jsdelivr.net/gh/bigboxthailand/arduino-assets@main/images/projects/simple-led-button-b8fa77_cover.jpg"
lang: "en"