Alternating flasher with two LEDs

FunduinoPublished on

Zwei LEDs abwechselnd blinken lassen – an vier Boards

Zwei Leuchtdioden sollen abwechselnd blinken – das klassische Warnsignal von Bahnübergängen und Fußgängerüberwegen. Für dieses Einsteigerprojekt brauchst du nur zwei LEDs, zwei Vorwiderstände und ein Steckbrett.

Die Anleitung zeigt Aufbau und Programm für vier Boards:

  • Arduino UNO
  • Wemos D1 Mini
  • ESP32-Wroom
  • NodeMCU

Alle vier Programme machen dasselbe, unterscheiden sich aber in der Bezeichnung der Pins.

Flashing light system at a railroad crossing
Alternating flashers in road traffic

You need this

Funduino UNO R3 Microcontroller - ATmega328P, 16 MHz, for Arduino Funduino UNO R3 Microcontroller - ATmega328P, 16 MHz, for Arduino 11,12 € *Item no. F23107480About the product — Funduino UNO R3 Microcontroller - ATmega328P, 16 MHz, for Arduino
830-point Breadboard - solderless breadboard for Arduino 830-point Breadboard - solderless breadboard for Arduino 2,90 € *Item no. FUN-1010553About the product — 830-point Breadboard - solderless breadboard for Arduino
Breadboard Cables Male-to-Male - 40 Pieces, 20 cm Breadboard Cables Male-to-Male - 40 Pieces, 20 cm 1,74 € *Item no. FUN-1010558About the product — Breadboard Cables Male-to-Male - 40 Pieces, 20 cm
LED 5 mm - 100 Pieces, 5 Colors, 2 V LED 5 mm - 100 Pieces, 5 Colors, 2 V 1,97 € *Item no. F23107316About the product — LED 5 mm - 100 Pieces, 5 Colors, 2 V
Resistor Assortment 100 Pieces - 5 Values 100 Ω to 10 kΩ, 0.5 W Resistor Assortment 100 Pieces - 5 Values 100 Ω to 10 kΩ, 0.5 W 1,72 € *Item no. F23107216About the product — Resistor Assortment 100 Pieces - 5 Values 100 Ω to 10 kΩ, 0.5 W

All 5 parts together 19,45 € *Ready to ship immediately · Delivery time: 1-3 business days

* All prices include statutory VAT, plus shipping costs.

Choose a microcontroller

Pins, schematic, and sketch in the steps change with your selection. It remains saved.

The task

Two LEDs should flash alternately. You know this from road traffic: at railway crossings and pedestrian crossings, flashing lights warn of danger.

LEDs operate at 2 to 3 volts, depending on their color. Microcontrollers, on the other hand, operate at 3.3 to 5 volts. This higher voltage can destroy the LED, so a series resistor is placed in front of each LED. In this case, they are 220 ohms.

Don't omit the series resistor - without it, the LED will only last a short time.

Flashing light system at a railroad crossing
Alternating flashers in road traffic

Setup and program for the Arduino UNO

On the Arduino UNO, the two LEDs are connected to Pin 5 and Pin 7. Build the circuit as shown in the image, then upload the program.

Breadboard setup with two LEDs on the Arduino UNO
Setup on the Arduino UNO, pin 5 and pin 7
Arduino UNO
// Ab hier kann der Code direkt in die Arduino Software kopiert werden.
// Schwarz, bunt = Code und Grau = Erklärungen
void setup()  // wir starten mit dem Setup
{
  pinMode(5, OUTPUT);  // Pin 5 ist ein Ausgang.
  pinMode(7, OUTPUT);  // Pin 7 ist ein Ausgang.
}
void loop()  // das Hauptprogramm beginnt.
{
  digitalWrite(5, HIGH);  // schalte die LED an Pin 5 an.
  delay(1000);            // warte 1000 Millisekunden.
  digitalWrite(5, LOW);   // schalte die LED an Pin 5 aus.
  digitalWrite(7, HIGH);  // Schalte die LED an Pin 7 ein.
  delay(1000);            // warte 1000 Millisekunden.
  digitalWrite(7, LOW);   // schalte die LED an Pin 7 aus.
}
// am Ende springt das Programm an den Start des Loop-Teils. Also …
// … schalte die LED an Pin 5 an.
// … usw. …

Assembly and program for the Wemos D1 Mini

On the Wemos D1 Mini, the LEDs are connected to D6 and D7.

On the Wemos D1 Mini, you need to prefix pin numbers in the program with a “D” - so D6 instead of 6.

Breadboard setup with two LEDs on the Wemos D1 Mini
Setup on the Wemos D1 Mini, D6 and D7
Wemos D1 Mini
void setup()
{
  pinMode(D6, OUTPUT);
  pinMode(D7, OUTPUT);
}
void loop()
{
  digitalWrite(D6, HIGH);
  digitalWrite(D7, LOW);
  delay(1000);
  digitalWrite(D6, LOW);
  digitalWrite(D7, HIGH);
  delay(1000);
}

Setup and program for the ESP32-Wroom

On the ESP32-Wroom, the LEDs are connected to Pin 26 and Pin 27 .

Breadboard setup with two LEDs on the ESP32-Wroom
Setup on the ESP32-Wroom, pins 26 and 27
ESP32-Wroom
void setup()
{
  pinMode(26, OUTPUT);
  pinMode(27, OUTPUT);
}
void loop()
{
  digitalWrite(26, HIGH);
  digitalWrite(27, LOW);
  delay(1000);
  digitalWrite(26, LOW);
  digitalWrite(27, HIGH);
  delay(1000);
}

Assembly and program for the NodeMCU

The LEDs on the NodeMCU are connected to D1 and D2.

Breadboard setup with two LEDs on the NodeMCU
Setup on the NodeMCU, D1 and D2
NodeMCU
void setup()
{
  pinMode(D1, OUTPUT);
  pinMode(D2, OUTPUT);
}
void loop()  // the main program begins.
{
  digitalWrite(D1, HIGH);
  delay(1000);
  digitalWrite(D1, LOW);
  digitalWrite(D2, HIGH);
  delay(1000);
  digitalWrite(D2, LOW);
}
Rate the instructions

Comments

Ask a question or share an experience

Contact us if something doesn’t work. Please include your board and the error message.

We review every comment before publication. Your email address remains with us.