Remember to maintain security and privacy. Do not share sensitive information. Procedimento.com.br may make mistakes. Verify important information. Termo de Responsabilidade
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.
Connect the LEDs:
Connect the Push Button:
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;
}
}
Press the button to cycle through the red, yellow, and green LEDs. Each press should change the state of the signaling system.