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

Arduino Pro Mini-Based LED Control System with Pushbutton Interface

View and Edit Project In Cirkit DesignerImage of Arduino Pro Mini-Based LED Control System with Pushbutton Interface

Circuit Documentation

Summary

This circuit consists of two Arduino Pro Mini microcontrollers and a pushbutton. The two Arduinos communicate with each other via serial communication. One Arduino is responsible for toggling an LED based on commands received from the other Arduino, which sends commands when a pushbutton is pressed.

Component List

Arduino Pro Mini

Pushbutton

Wiring Details

Arduino Pro Mini (1)

Arduino Pro Mini (2)

Pushbutton

Code Documentation

Arduino Pro Mini (1)

File Name: sketch.ino

const int indicationLedPin = 13; // Pin for the indication LED
bool ledState = false; // Variable to track the state of the LED

void setup() {
  pinMode(indicationLedPin, OUTPUT);
  Serial.begin(9600);  // Start serial communication at 9600 baud
}

void loop() {
  if (Serial.available() > 0) {
    String command = Serial.readStringUntil('\n'); // Read incoming command

    if (command == "TOGGLE") {
      ledState = !ledState; // Toggle the LED state
      digitalWrite(indicationLedPin, ledState ? HIGH : LOW); // Set the LED accordingly

      // Send feedback to Arduino 1 about the LED state
      if (ledState) {
        Serial.println("1");  // LED is ON
      } else {
        Serial.println("0");  // LED is OFF
      }
    }
  }
}

Arduino Pro Mini (2)

File Name: sketch.ino

const int buttonPin = A2;   // Pin for the button
const int feedbackLedPin = 13; // Pin for feedback LED
int buttonState = 0;          // Variable to store the button state
int lastButtonState = 0;      // Last button state to detect changes

void setup() {
  pinMode(buttonPin, INPUT_PULLUP);
  pinMode(feedbackLedPin, OUTPUT);
  Serial.begin(9600);  // Start serial communication at 9600 baud
}

void loop() {
  buttonState = digitalRead(buttonPin);

  // Check if the button state changes from LOW to HIGH (button press)
  if (buttonState == HIGH && lastButtonState == LOW) {
    // Send signal to Arduino 2 to toggle LED
    Serial.println("TOGGLE");

    // Wait for feedback from Arduino 2
    while (Serial.available() == 0); // Wait for data to be available
    char received = Serial.read(); // Read the feedback signal from Arduino 2

    if (received == '1') {
      digitalWrite(feedbackLedPin, HIGH); // Turn on feedback LED to match Arduino 2's state
    } else {
      digitalWrite(feedbackLedPin, LOW);  // Turn off feedback LED to match Arduino 2's state
    }

    delay(200);  // Debounce delay for button
  }

  lastButtonState = buttonState;
}