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

Wemos D1 Mini Pushbutton-Controlled LED with Serial Monitoring

View and Edit Project In Cirkit DesignerImage of Wemos D1 Mini Pushbutton-Controlled LED with Serial Monitoring

Circuit Documentation

Summary

This circuit involves a Wemos D1 Mini microcontroller, a pushbutton, a red LED, and two resistors. The pushbutton is used to control the state of the LED. When the button is pressed, the LED turns on, and when the button is released, the LED turns off. The Wemos D1 Mini reads the state of the pushbutton and controls the LED accordingly.

Component List

  1. Wemos D1 Mini

    • Description: A microcontroller board based on the ESP8266.
    • Pins: RST, A0, D0, D5, D6, D7, D8, 3V3, 5V, G, D4, D3, D2, D1, RX, TX
  2. Pushbutton

    • Description: A simple pushbutton switch.
    • Pins: Pin 3 (out), Pin 4 (out), Pin 1 (in), Pin 2 (in)
  3. Resistor (10k Ohms)

    • Description: A resistor with a resistance of 10k Ohms.
    • Pins: pin1, pin2
  4. LED: Two Pin (red)

    • Description: A red LED with two pins.
    • Pins: cathode, anode
  5. Resistor (200 Ohms)

    • Description: A resistor with a resistance of 200 Ohms.
    • Pins: pin1, pin2

Wiring Details

Wemos D1 Mini

Pushbutton

Resistor (10k Ohms)

LED: Two Pin (red)

Resistor (200 Ohms)

Code Documentation

/*
 * This Arduino sketch reads the state of a pushbutton connected to pin D2
 * of a Wemos D1 Mini and controls a red LED connected to pin D1. When the
 * button is pressed, the LED will turn on. When the button is released,
 * the LED will turn off.
 */

void setup() {
  pinMode(D2, INPUT); // Set D2 as an input for the pushbutton
  pinMode(D1, OUTPUT); // Set D1 as an output for the LED
  Serial.begin(9600); // Initialize serial communication
}

void loop() {
  int buttonState = digitalRead(D2); // Read the state of the pushbutton
  digitalWrite(D1, buttonState); // Set the LED state to match the button
  Serial.println(buttonState); // Print the state to the serial monitor
  delay(100); // Small delay to avoid flooding the serial monitor
}

This code initializes the Wemos D1 Mini to read the state of the pushbutton connected to pin D2 and control the LED connected to pin D1. The state of the pushbutton is printed to the serial monitor for debugging purposes.