Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

Raspberry Pi-Controlled LED with Pushbutton Interaction

View and Edit Project In Cirkit DesignerImage of Raspberry Pi-Controlled LED with Pushbutton Interaction

Circuit Documentation

Summary of the Circuit

This circuit is designed to control a red two-pin LED using a pushbutton, interfaced with a Raspberry Pi 5. The LED blinks when the pushbutton is not pressed and stays continuously on when the pushbutton is pressed. The circuit includes two resistors, one for current limiting to the LED and another as a pull-up for the pushbutton. The Raspberry Pi 5 is programmed to control the LED based on the state of the pushbutton.

Component List

LED: Two Pin (red)

Resistor (220 Ohms)

Resistor (10k Ohms)

Raspberry Pi 5

Pushbutton

Wiring Details

LED: Two Pin (red)

Resistor (220 Ohms)

Resistor (10k Ohms)

Raspberry Pi 5

Pushbutton

Documented Code

/*
 * This Arduino Sketch controls an LED using a push button.
 * The LED blinks when the push button is NOT pressed.
 * The LED stays on continuously when the push button IS pressed.
 */

#include <Arduino.h>

// Define pin numbers
const int LED_PIN = 18;
const int BUTTON_PIN = 17;

void setup() {
  // Initialize the LED pin as an output
  pinMode(LED_PIN, OUTPUT);
  // Initialize the button pin as an input with pull-up resistor
  pinMode(BUTTON_PIN, INPUT_PULLUP);
}

void loop() {
  // Read the state of the button
  int buttonState = digitalRead(BUTTON_PIN);

  if (buttonState == HIGH) {
    // Button is NOT pressed, blink the LED
    digitalWrite(LED_PIN, HIGH); // Turn LED on
    delay(500); // Wait for 500 milliseconds
    digitalWrite(LED_PIN, LOW); // Turn LED off
    delay(500); // Wait for 500 milliseconds
  } else {
    // Button IS pressed, keep the LED on
    digitalWrite(LED_PIN, HIGH);
  }
}

Filename: sketch.ino

This code is written for the Raspberry Pi 5, which is assumed to be compatible with Arduino syntax and libraries. The code initializes the GPIO pins, reads the state of the pushbutton, and controls the LED accordingly.