B2: Alternate Control of LED & Buzzer

AR-B2: Alternate Control of LED & Buzzer

This entry is part 2 of 13 in the series Arduino Basic Circuits

This code is used to blink the LED connected at pin-13 of Arduino UNO and produce buzzer beeps alternately. First type the code by creating new file in Arduino IDE, save the file and then upload it.

Required Material

Arduino UNO Board – 1, data cable – 1, Red LED – 1, Resistor 1kΩ (Brown Black Red) – 1, Buzzer – 1, Jumper wires – 4.

Working

After uploading the code in Arduino UNO board, the buzzer and LED “L” will be ON alternately. This happens because of alternate action written in the code.

The Code

Upload the following code in Arduino UNO to control LED and buzzer in alternate action. It is very interesting code, which will help you understand the simple logic behind controlling number of devices using Arduino.

int LED = 7; // connect anode of LED to pin-7 
int buzzer = 11; // connect +ve terminal of buzzer to pin-11

void setup()
{
  pinMode(LED,OUTPUT);
  pinMode(buzzer,OUTPUT);
}

void loop()
{
  digitalWrite(LED,HIGH);
  digitalWrite(buzzer,LOW);
  delay(2000);
  digitalWrite(LED,LOW);
  digitalWrite(buzzer,HIGH);
  delay(2000);
}


Procedure & Precautions

  1. First type the code correctly in Arduino IDE software.
  2. Then connect the Arduino board to computer through data cable and click on “Tools” menu.
  3. Then select “Arduino board” and respective “COM” Port.
  4. The upload the code in Arduino UNO board.
  5. Observe that the LED “L” and the buzzer will be ON alternately, at a rate decided by your delay() function value.

Circuit Diagram

alternate blinking LED Diagram Vidyasagar Academy

Share on your network!
Prof. Dattaraj Vidyasagar
Prof. Dattaraj Vidyasagar

Author on this website. He is veteran of Core Electronics since last 36+ years. ATL Mentor of Change, Niti Ayog, Govt. of India, Google Certified Educator, International Robotics Trainer and author of 18 books on electronics, robotics, programming languages and web designing... ➤➤

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x