
Zdravím, zde naleznete rozpis pro Arduino semafor včetně kódu, součástek a schéma zapojení.
Pro zapojení semaforu budeme potřebovat:
1x Jakoukoliv Arduino kompatibilní desku např. Arduino UNO R3
6x DuPONT kabel
3x rezistor 220 Ω
1x zelená, žlutá a červená LEDka
Schéma zapojení včetně popisu:

Každý záporný pól všech LED zapojíme do konektoru GND na desce arduino a mezi konektor GND a záporný pól ledky usadíme rezistor 220 ohm viz obrázek, následně červenou LED zapojíme na digitální konektor desky 13, žlutou LED zapojíme na konektor 12 a zelenou LED zapojíme na port 11.
Kód
// Arduino traffic light by Dejv_cze1
// This traffic light uses:
// 1x Any arduino compatible board
// 6x Jumper wires
// 3x Rezistor 220 Ω
// 1x Green LED
// 1x Yellow LED
// 1x Red LED
// ↓ ↓ ↓ There are variables that set pin for each LEDs (For example if you connect green led to pin 7 you can change the number 11 to the number 7)
int GreenLED = 11;
int YellowLED = 12;
int RedLED = 13;
void setup() {
//
pinMode(GreenLED, OUTPUT);
pinMode(YellowLED, OUTPUT);
pinMode(RedLED, OUTPUT);
}
// the loop function runs over and over again forever
void loop() { // This in void loop is a looop that continuous when your arduino is pluged-in forever
digitalWrite(GreenLED, HIGH); // This turn on green LED
delay(3000); // This waits 3 seconds
digitalWrite(GreenLED, LOW); // This turn off green LED
digitalWrite(YellowLED, HIGH); // This turn on yellow LED
delay(1000); // This waits 1 second
digitalWrite(YellowLED, LOW); // This turn off yellow LED
digitalWrite(RedLED, HIGH); // This turn on red LED
delay(3000); // This waits 3 seconds
digitalWrite(YellowLED, HIGH); // This turn on yellow LED
delay(500); // This waits 1 second
digitalWrite(YellowLED, LOW); // This turn off yellow LED
digitalWrite(RedLED, LOW); // This turn off red LED
// And cycle repeats infinitly
}