Arduino Giga R1 WiFi Button LED

This guide covers button-controlled LED switching with the Arduino Giga R1 WiFi. The implementation demonstrates fundamental digital input/output concepts using push button control to directly manage LED state in real-time.

This tutorial walks through circuit design, proper current limiting, GPIO configuration, and polling-based input reading.

Arduino Giga R1 WiFi - Button - LED

We are going to learn how to:

We will learn how to toggle LED each time button is pressed in Arduino - Button Toggles LED tutorial.

Hardware Preparation

1×Arduino Giga R1 WiFi
1×USB 2.0 cable type A/B (for USB-A PC)
1×USB 2.0 cable type C/B (for USB-C PC)
1×Breadboard-mount Button with Cap
1×Breadboard-mount Button Kit
1×Panel-mount Push Button
1×Push Button Module
1×LED Kit
1×LED (red)
1×LED Module
1×220Ω Resistor
1×Breadboard
1×Jumper Wires
1×Recommended: Screw Terminal Block Shield for Arduino Uno/Mega/Giga
1×Recommended: Breadboard Shield for Arduino Mega/Giga
1×Recommended: Enclosure for Arduino Giga
1×Recommended: Power Splitter for Arduino Giga

Or you can buy the following kits:

1×DIYables Sensor Kit (30 sensors/displays)
1×DIYables Sensor Kit (18 sensors/displays)
Disclosure: Some of the links provided in this section are Amazon affiliate links. We may receive a commission for any purchases made through these links at no additional cost to you.
Additionally, some of these links are for products from our own brand, DIYables .

Buy Note: Use the LED Module for easier wiring. It includes an integrated resistor.

Overview of LED and Button

LEDs are semiconductor devices with forward voltage drop of 1.8V-3.3V and optimal operating current around 20mA. They require current limiting through series resistance.

Push buttons create temporary electrical connections when pressed. Momentary buttons return to their default state when released. The Arduino Giga R1 WiFi provides 5V-tolerant digital inputs with internal pull-up resistors and can source up to 20mA per pin for direct LED control.

If you do not know about LED and button (pinout, how it works, how to program ...), learn about them in the following tutorials:

Wiring Diagram

The wiring diagram below demonstrates the essential connections for button-controlled LED operation. Proper component placement and current limiting are critical for reliable operation and component longevity.

The wiring diagram between Arduino Button LED

This image is created using Fritzing. Click to enlarge image

Electrical Note: The diagram above shows the minimum viable connection. For production or extended use, consider adding a debouncing capacitor (100nF ceramic) across the button terminals to minimize contact bounce effects, and verify the LED forward current remains within specification under varying supply voltage conditions.

Arduino Giga R1 WiFi Pin Component Connection Function
Digital Pin 2 Button Terminal 1 Digital input with internal pull-up
GND Button Terminal 2 Ground reference
Digital Pin 13 LED Anode (via 220Ω resistor) PWM-capable output, current-limited
GND LED Cathode Ground return path
5V Power rail (if external components need 5V) Primary power supply

The 220Ω current-limiting resistor prevents excessive current through the LED, maintaining forward current at approximately 18mA with a 5V supply. The button utilizes the Arduino's internal pull-up resistor, eliminating the need for external pull-up components while ensuring clean logic level transitions.

Arduino Code

The following implementation demonstrates direct GPIO polling for button state detection and immediate LED response. The code is structured to handle real-time input monitoring without delays that could affect responsiveness. Key sections include GPIO initialization, continuous state polling, and direct output control.

The standard Arduino digital I/O functions provide the necessary interface: pinMode() configures GPIO direction and pull-up behavior, digitalRead() samples the current input state, and digitalWrite() controls output levels. This polling-based approach ensures sub-millisecond response times for immediate visual feedback.

/* * This Arduino Giga R1 WiFi code was developed by newbiely.com * * This Arduino Giga R1 WiFi code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-giga/arduino-giga-r1-wifi-button-led */ #define BUTTON_PIN 7 // The Arduino Giga R1 WiFi pin connected to the button #define LED_PIN 3 // The Arduino Giga R1 WiFi pin connected to the LED void setup() { Serial.begin(9600); // initialize serial pinMode(BUTTON_PIN, INPUT_PULLUP); // set arduino pin to input pull-up mode pinMode(LED_PIN, OUTPUT); // set arduino pin to output mode } void loop() { int buttonState = digitalRead(BUTTON_PIN); // read new state if (buttonState == LOW) { Serial.println("The button is being pressed"); digitalWrite(LED_PIN, HIGH); // turn on } else if (buttonState == HIGH) { Serial.println("The button is unpressed"); digitalWrite(LED_PIN, LOW); // turn off } }

The implementation uses active-low button logic, where pressing the button pulls the input to ground (LOW state). The internal pull-up resistor maintains a HIGH state when the button is not pressed. LED control inverts this logic so the LED illuminates during button press events, providing intuitive user feedback.

Detailed Instructions

For initial Arduino Giga R1 WiFi setup, refer to the Arduino Giga R1 WiFi Getting Started guide before proceeding.

  • Connect Components: Wire the button between digital pin 2 and ground, and connect the LED (with 220Ω resistor) between digital pin 13 and ground. Verify all connections match the wiring diagram exactly to prevent component damage.
  • Launch Arduino IDE: Open the Arduino IDE and ensure the board is set to "Arduino Giga R1 WiFi" in the Tools menu. Select the correct COM port corresponding to your Arduino Giga R1 WiFi connection.
  • Configure Code: Copy the provided code into a new Arduino IDE sketch. The code initializes pin 2 as an input with internal pull-up enabled and pin 13 as a digital output for LED control.
  • Upload Firmware: Click the Upload button to compile and transfer the code to the Arduino Giga R1 WiFi. The IDE should display "Done uploading" upon successful completion without compilation errors.
  • Test Operation: Press and hold the button while observing the LED. The LED should illuminate immediately when the button is pressed and turn off when released, demonstrating real-time button-to-LED control.
  • Verify Serial Output: Open the Serial Monitor at 9600 baud to observe button state changes in real-time. The output should display current button status and corresponding LED state for debugging verification.

Technical Note: The polling loop executes continuously without delays, providing sub-millisecond response times. For applications requiring precise timing or multiple inputs, consider interrupt-driven button handling to improve system responsiveness and reduce CPU overhead.

Code Explanation

Read the line-by-line explanation in comment lines of source code! The implementation uses continuous polling to monitor button state changes and immediately update LED output accordingly. The digitalRead() function samples the button state each loop iteration, while digitalWrite() controls LED illumination based on the inverted button logic.

Serial Monitor Output

COM6
Send
Button Status: Released, LED: OFF Button Status: Released, LED: OFF Button Status: Pressed, LED: ON Button Status: Pressed, LED: ON Button Status: Pressed, LED: ON Button Status: Released, LED: OFF Button Status: Released, LED: OFF
Autoscroll Show timestamp
Clear output
9600 baud  
Newline  

Application and Project Ideas

Industrial Control Panel: Implement emergency stop indicators and manual override controls in manufacturing systems. The Arduino Giga R1 WiFi's industrial-grade reliability enables integration with PLCs and SCADA systems for real-time status indication.

Interactive Prototype Interface: Create user interface mockups for product development and usability testing. Multiple button-LED pairs can simulate complex control systems, allowing rapid iteration of human-machine interface designs.

Security System Status Display: Build access control panels with button-activated status lights for door locks, alarm systems, and zone monitoring. The Giga R1 WiFi's WiFi capability enables remote status reporting and centralized monitoring.

Educational Training Platform: Develop hands-on learning tools for digital logic and embedded systems education. Students can explore cause-and-effect relationships in electronic systems while building foundational programming skills.

Home Automation Controller: Integrate manual override switches with smart home systems, providing physical backup controls for lighting and appliance management. The dual-core architecture supports simultaneous WiFi communication and local control processing.

Laboratory Equipment Interface: Create manual control systems for scientific instruments where immediate response and visual feedback are critical. The precise timing control ensures reliable operation in measurement and testing applications.

Video Tutorial

The accompanying video demonstrates the hardware assembly and live code execution. It covers proper component placement, wiring verification techniques, and shows the expected LED response during button press events on the serial monitor in real-time.

Challenge Yourself

Challenge: Implement multiple button-LED pairs on different GPIO pins to create a multi-channel control system with individual status indication for each input.

Challenge: Add button press duration measurement to distinguish between short presses and long holds, triggering different LED patterns based on press length using the millis() timing function.

Challenge: Create a WiFi-enabled remote monitoring system that logs button press events to a web server, combining local LED feedback with cloud-based activity tracking using the Arduino Giga R1 WiFi's networking capabilities.

Challenge: Implement interrupt-driven button handling using attachInterrupt() to improve system responsiveness and enable low-power operation modes while maintaining immediate LED response.

Challenge: Design a complete access control simulator with multiple buttons representing different user credentials, corresponding status LEDs, and serial communication protocol for integration with external security systems.

※ OUR MESSAGES

  • As freelancers, We are AVAILABLE for HIRE. See how to outsource your project to us
  • Please feel free to share the link of this tutorial. However, Please do not use our content on any other websites. We invested a lot of effort and time to create the content, please respect our work!