To interface LED/Buzzer with Arduino/Raspberry Pi and write a program to turn ON LED for 1 sec after every 2 seconds.
Last Updated : 31 Jul 2025
Jul 24, Jan 24, Jul 23, Jan 22
Solution:
void setup() {
pinMode(11, OUTPUT); // Set pin 11 as an output for the LED
}
void loop() {
digitalWrite(11, HIGH); // Turn the LED on
delay(1000); // Wait for 1 second (1000 milliseconds)
digitalWrite(11, LOW); // Turn the LED off
delay(2000); // Wait for 2 seconds (2000 milliseconds)
}
Output Description:
LED Behavior:
The LED connected to pin 11 will turn ON for 1 second.
It will then turn OFF for 2 seconds.
This cycle repeats indefinitely.
Code Explaination:
Setup() Function:
pinMode(11, OUTPUT);
: Sets pin 11 as output for the LED.
Loop() Function:
digitalWrite(11, HIGH);
: Turns the LED on.delay(1000);
: Waits 1 second.digitalWrite(11, LOW);
: Turns the LED off.delay(2000);
: Waits 2 seconds.
Meanwhile you can watch this video
Watch Video