PandaByte LED + Switch Module: Digital Input and Output Guide

by pandabyte in Circuits > Arduino

9 Views, 0 Favorites, 0 Comments

PandaByte LED + Switch Module: Digital Input and Output Guide

ledsw.png

The PandaByte LED + Switch Module combines two of the most commonly used components for learning embedded systems—a single-color LED and a momentary push button—on a single compact board. It enables beginners to learn both digital output (LED control) and digital input (button reading) using a single module.

Like other PandaByte Grove modules, it supports both:

  1. Traditional male header connections
  2. 4-pin Grove connector for plug-and-play prototyping

In this guide, you will learn:

  1. Module pin configuration
  2. Circuit connections
  3. Reading push button input
  4. Controlling LED output
  5. Complete Arduino example

This module is suitable for Arduino-compatible boards, ESP32, Raspberry Pi Pico and other microcontrollers.

Supplies

ledswa.png

Hardware

  1. PandaByte LED + Switch Module
  2. PandaByte xC3m ESP32-C3 Development Board
  3. PandaByte Grove Expansion Board
  4. USB Cable
  5. Grove Cable (or Dupont wires)

Software

  1. Arduino IDE

Circuit Connections

sw1.png
sw2.png

Perform the connection according to the table.

Programming

Program 1: Read the Switch

This example reads the push button using INPUT_PULLUP.

const int ledPin = 1;
const int switchPin = 0;

void setup() {
pinMode(ledPin, OUTPUT);
pinMode(switchPin, INPUT_PULLUP);
Serial.begin(115200);
}
void loop() {
if (digitalRead(switchPin) == LOW) {
Serial.println("Button Pressed");
}
else {
Serial.println("Button Released");
}
delay(100);
}

Program 2: Turn LED ON while Button is Pressed

const int ledPin = 1;
const int switchPin = 0;

void setup() {
pinMode(ledPin, OUTPUT);
pinMode(switchPin, INPUT_PULLUP);
}

void loop() {
if (digitalRead(switchPin) == LOW) {
digitalWrite(ledPin, HIGH);
}
else {
digitalWrite(ledPin, LOW);
}
}


Output

Program 1

  1. Serial Monitor displays:
  2. Button Pressed
  3. Button Released

Program 2

  1. Press the button.
  2. LED turns ON.
  3. Release the button.
  4. LED turns OFF.

Important Information

  1. The push button is configured using INPUT_PULLUP.
  2. With INPUT_PULLUP, the input normally reads HIGH, when button is not pressed.
  3. Pressing the button connects the pin to GND, so the input becomes LOW.
  4. The LED is connected to GPIO 1 and is controlled using standard digital output functions.