Remember to maintain security and privacy. Do not share sensitive information. Procedimento.com.br may make mistakes. Verify important information. Termo de Responsabilidade

How to Create a Signaling System Using Arduino

Signaling systems are essential in various applications, from traffic lights to alarm systems. In this article, we will explore how to create a simple signaling system using Arduino. This system will use LEDs to represent different signals, and a button to change the state of the signals.

Components Needed:

  • Arduino Uno
  • Breadboard
  • LEDs (Red, Yellow, Green)
  • Resistors (220 ohms)
  • Push Button
  • Jumper Wires

Step-by-Step Guide:

Step 1: Setting Up the Hardware

  1. Connect the LEDs:

    • Place the red, yellow, and green LEDs on the breadboard.
    • Connect the anode (longer leg) of each LED to digital pins 2, 3, and 4 on the Arduino, respectively.
    • Connect the cathode (shorter leg) of each LED to a 220-ohm resistor, and then to the ground (GND) on the Arduino.
  2. Connect the Push Button:

    • Place the push button on the breadboard.
    • Connect one side of the button to 5V on the Arduino.
    • Connect the other side of the button to digital pin 5 on the Arduino.
    • Add a pull-down resistor (10k ohms) between the button pin and ground.

Step 2: Writing the Code

Open the Arduino IDE and write the following code:

const int redLED = 2;
const int yellowLED = 3;
const int greenLED = 4;
const int buttonPin = 5;

int buttonState = 0;
int currentSignal = 0; // 0: Red, 1: Yellow, 2: Green

void setup() {
  pinMode(redLED, OUTPUT);
  pinMode(yellowLED, OUTPUT);
  pinMode(greenLED, OUTPUT);
  pinMode(buttonPin, INPUT);
}

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

  if (buttonState == HIGH) {
    currentSignal = (currentSignal + 1) % 3;
    delay(200); // Debounce delay
  }

  switch (currentSignal) {
    case 0:
      digitalWrite(redLED, HIGH);
      digitalWrite(yellowLED, LOW);
      digitalWrite(greenLED, LOW);
      break;
    case 1:
      digitalWrite(redLED, LOW);
      digitalWrite(yellowLED, HIGH);
      digitalWrite(greenLED, LOW);
      break;
    case 2:
      digitalWrite(redLED, LOW);
      digitalWrite(yellowLED, LOW);
      digitalWrite(greenLED, HIGH);
      break;
  }
}

Step 3: Upload the Code

  1. Connect your Arduino to your computer using a USB cable.
  2. Select the correct board and port from the Arduino IDE.
  3. Upload the code to the Arduino.

Step 4: Test the System

Press the button to cycle through the red, yellow, and green LEDs. Each press should change the state of the signaling system.

Examples:

  • Traffic Light Simulation: Modify the code to include timing delays to simulate a real traffic light.
  • Alarm System: Use different colored LEDs to indicate different states of an alarm system (armed, disarmed, triggered).

To share Download PDF

Gostou do artigo? Deixe sua avaliação!
Sua opinião é muito importante para nós. Clique em um dos botões abaixo para nos dizer o que achou deste conteúdo.