LED on Breadboard

# Connect and Toggle an LED on Breadboard The Lonely Binary UNO R3 is an excellent microcontroller board for beginners and hobbyists alike, offering compatibility with the Arduino ecosystem. One of the simplest and most educational projects you can start with is connecting an LED to a General Purpose Input/Output (GPIO) pin and toggling it on and off. In this article, we'll use GPIO 3 (digital pin 3) on the Lonely Binary UNO R3 to control an LED, providing a step-by-step guide to both the hardware setup and the programming process. # Materials Needed - Lonely Binary UNO R3 microcontroller board - LED (any color, typically 5mm or 3mm) - 220-ohm resistor (to limit current) - Breadboard - Jumper wires - USB cable (to connect the UNO R3 to your computer) - Computer with the Arduino IDE installed # Understanding the Components Before diving in, let’s briefly cover the key components: - **LED**: A light-emitting diode has two legs—an anode (longer leg, positive) and a cathode (shorter leg, negative). It requires a current-limiting resistor to prevent damage. ![](https://cdn.shopify.com/s/files/1/0331/9994/7908/files/Pasted_image_20250310094613.png?v=1741560743) - **Lonely Binary UNO R3**: This board has 14 digital GPIO pins (0–13), and we’ll use pin 3 for this project. Each pin can output 5V when set to HIGH or 0V when set to LOW. - **Resistor**: A 220-ohm resistor is suitable for most LEDs when powered by the UNO’s 5V output, ensuring the current stays within safe limits (typically 10–20mA for a standard LED). # Hardware Setup 1. **Power Off the Board**: Ensure the Lonely Binary UNO R3 is disconnected from your computer or any power source to avoid accidental shorts during setup. 2. **Connect the LED**: - Insert the LED into a breadboard. - Connect the anode (longer leg) of the LED to digital pin 3 (labeled "3" on the board). - Connect the cathode (shorter leg) to one end of the 220-ohm resistor. 3. **Complete the Circuit**: - Connect the other end of the resistor to the GND (ground) - The circuit is now complete: Pin 3 → LED anode → LED cathode → Resistor → GND. 4. **Double-Check Connections**: Ensure the LED’s polarity is correct and the resistor is properly connected. A reversed LED won’t light up, but it won’t damage anything. # Writing the Code Now that the hardware is set up, let’s program the Lonely Binary UNO R3 to toggle the LED. We’ll use the Arduino IDE to write a simple sketch that turns the LED on and off every second. 1. **Set Up the Board**: - Connect the UNO R3 to your computer via the USB cable. - In the Arduino IDE, go to **Tools > Board** and select “Arduino UNO” (the Lonely Binary UNO R3 is compatible with this setting). - Go to **Tools > Port** and select the port your board is connected to (e.g., COM3 on Windows or /dev/ttyUSBxxx on Mac). 2. **Write the Sketch**: Copy and paste the following code into a new Arduino IDE window: ```cpp // Define the LED pin const int ledPin = 3; // GPIO 3 // Setup function runs once at startup void setup() { pinMode(ledPin, OUTPUT); // Set pin 3 as an output } // Loop function runs continuously after setup void loop() { digitalWrite(ledPin, HIGH); // Turn the LED on delay(1000); // Wait for 1 second digitalWrite(ledPin, LOW); // Turn the LED off delay(1000); // Wait for 1 second } ``` The code is nearly identical to what we used in the built-in LED toggling demo, with the only difference being that we defined the `ledPin` as GPIO 3. ```cpp const int ledPin = 3; ``` 4. **Upload the Code**: - Click the **Upload** button (right arrow) in the Arduino IDE. - Wait for the **Done uploading** message to appear. If you encounter errors, double-check your board and port settings. # Troubleshooting Once the code is uploaded, the LED connected to GPIO 3 should start blinking—on for one second, off for one second, repeating indefinitely. If it doesn’t work: - **Check Connections**: Ensure the LED’s anode is in pin 3 and the cathode is connected through the resistor to GND. - **Verify Polarity**: Swap the LED’s legs if it’s not lighting up. - **Inspect the Resistor**: Confirm it’s 220 ohms (color bands: red, red, brown) and properly inserted. # Taking It Further - **Adjust Timing**: Change the `delay(1000)` values to make the LED blink faster (e.g., `delay(500)` for half a second) or slower (e.g., `delay(2000)` for two seconds).

RELATED ARTICLES