Switch light and sound simultaneously
FunduinoPublished on
LED und Piezo gleichzeitig ansteuern – und Variablen kennenlernen
You need this
5 V buzzer - electromagnetic sounder, 2400 Hz
0,90 € *Item no. F23108736About the product — 5 V buzzer - electromagnetic sounder, 2400 Hz
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
2,90 € *Item no. FUN-1010553About the product — 830-point Breadboard - solderless breadboard for Arduino
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
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
1,72 € *Item no. F23107216About the product — Resistor Assortment 100 Pieces - 5 Values 100 Ω to 10 kΩ, 0.5 W
All 6 parts together 20,35 € *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
Active or passive speaker?
Setup and program for the Arduino UNO
Arduino UNO
// Dieses Mal nutzen wir auch den ersten Programmabschnitt.
// Hier werden Variablen eingetragen. Das bedeutet, dass sich hinter einem Buchstaben oder einem Wort eine Zahl verbirgt.
// Bei uns ist die LED an Pin 5 angeschlossen und der Piezo-Speaker an Pin 7.
// Damit man die beiden Pins später nicht verwechselt, benennen wir Pin 5 und Pin 7 einfach um.
int LED = 5; // Das Wort „LED“ steht jetzt für die Zahl „5“.
int Pieps = 7; // Das Wort „Pieps“ steht jetzt für die Zahl „7“.
void setup() // wir starten mit dem Setup.
{
pinMode(LED, OUTPUT); // Pin 5 (Pin „LED“) ist ein Ausgang.
pinMode(Pieps, OUTPUT); // Pin 7 (Pin „Pieps“) ist ein Ausgang.
}
void loop() // Das Hauptprogramm beginnt.
{
digitalWrite(LED, HIGH); // Schalte die LED an.
digitalWrite(Pieps, HIGH); // Schalte den Piezo-Lautsprecher an.
delay(1000); // Warte 1000 Millisekunden. (Es piepst und leuchtet.)
digitalWrite(LED, LOW); // Schalte die LED aus.
digitalWrite(Pieps, LOW); // Schalte den Piezo aus.
delay(1000); // Warte 1000 Millisekunden. (kein Lärm, kein Licht)
}
// Hier am Ende springt das Programm an den Start des Loop-Teils.
// also wird es gleich wieder piepsen und leuchten. Wenn man die Pause (delay) verkleinert oder vergrößert,
// piepst und leuchtet es schneller oder langsamer.Assembly and program for the Wemos D1 Mini
Wemos D1 Mini
int LED = D5; // The word “LED” now stands for D5.
int Pieps = D6; // The word “Pieps” now stands for D6.
void setup() // We start with the setup.
{
pinMode(LED, OUTPUT); // Pin D5 (pin “LED”) is an output.
pinMode(Pieps, OUTPUT); // Pin D6 (pin “Pieps”) is an output.
}
void loop() // The main program begins.
{
digitalWrite(LED, HIGH); // Turn on the LED.
digitalWrite(Pieps, HIGH); // Turn on the piezo speaker.
delay(1000); // Wait 1000 milliseconds. (It beeps and lights up.)
digitalWrite(LED, LOW); // Turn off the LED.
digitalWrite(Pieps, LOW); // Turn off the piezo.
delay(1000); // Wait 1000 milliseconds. (no noise, no light)
}Setup and program for the ESP32-Wroom
ESP32-Wroom
int LED = 26; // The word “LED” now stands for the number “26”.
int Pieps = 27; // The word “Pieps” now stands for the number “27”.
void setup() // We start with the setup.
{
pinMode(LED, OUTPUT); // Pin 26 (pin “LED”) is an output.
pinMode(Pieps, OUTPUT); // Pin 27 (pin “Pieps”) is an output.
}
void loop() // The main program begins.
{
digitalWrite(LED, HIGH); // Turn the LED on.
digitalWrite(Pieps, HIGH); // Turn the piezo speaker on.
delay(1000); // Wait 1000 milliseconds. (It beeps and lights up.)
digitalWrite(LED, LOW); // Turn the LED off.
digitalWrite(Pieps, LOW); // Turn the piezo off.
delay(1000); // Wait 1000 milliseconds. (no noise, no light)
}Assembly and program for the NodeMCU
NodeMCU
int LED = D1; // The word “LED” now stands for D1.
int Pieps = D2; // The word “Pieps” now stands for D2.
void setup() // We start with setup.
{
pinMode(LED, OUTPUT); // Pin D1 (pin “LED”) is an output.
pinMode(Pieps, OUTPUT); // Pin D2 (pin “Pieps”) is an output.
}
void loop() // The main program begins.
{
digitalWrite(LED, HIGH); // Turn on the LED.
digitalWrite(Pieps, HIGH); // Turn on the piezo speaker.
delay(1000); // Wait 1000 milliseconds. (It beeps and lights up.)
digitalWrite(LED, LOW); // Turn off the LED.
digitalWrite(Pieps, LOW); // Turn off the piezo.
delay(1000); // Wait 1000 milliseconds. (no noise, no light)
}Rate the instructions