Hello again, everyone! Today I made a multicolored LED stream with a buzzer. This is a very good project for beginners that want to make something cool/interesting. The project uses 4 LEDS in the stream, one red, one blue, one yellow, and one green. Below is a video of the working project.
Step 1: Gather Necessary MaterialsFirst, get the following materials.
- Arduino Board
- Active Buzzer
- 1 Red LED
- 1 Blue LED
- 1 Green LED
- 1 Yellow LED
- A breadboard
- Some Jumper wires
Before you move onto the hardware and software, here are some tutorials that may give an introduction to the components used.
Step 2: Hardware SchematicHere is the schematic for this project. The Digital IO wires for the LEDs are color-coded based on the color of the LED.
Next, we shall move onto the coding portion.
Step 3: Coding SoftwarePut this code into the Arduino IDE.
//Digital Pins/Variables
int blueLED1 = 2; //Blue LED to Pin 2
int yellowLED2 = 3; //Yellow LED to Pin 3
int greenLED3 = 4; //Green LED to Pin 4
int redLED4 = 5; //Red LED to pin 5
int buzzer = 6; //Buzzer to pin 6
void setup() { //Setup Code
pinMode(blueLED1, OUTPUT); //Blue LED as output
pinMode(yellowLED2, OUTPUT); //Yellow LED as output
pinMode(greenLED3, OUTPUT); //Green LED as output
pinMode(redLED4, OUTPUT); //Red LED as output
pinMode(buzzer, OUTPUT); //Buzzer as output
digitalWrite(buzzer, HIGH); //Turn Buzzer on
}
void loop() { //Loop code
digitalWrite(blueLED1, HIGH); //Blue led on
delay(50); //wait for 1/25 of a second
digitalWrite(blueLED1, LOW); //Blue led off
digitalWrite(yellowLED2, HIGH); //Yellow led on
delay(50); //wait for 1/25 of a second
digitalWrite(yellowLED2, LOW); //Yellow led off
digitalWrite(greenLED3, HIGH); //Green led on
delay(50); //wait for 1/25 of a second
digitalWrite(greenLED3, LOW); //Green led off
digitalWrite(redLED4, HIGH); //Red led on
delay(50); //wait for 1/25 of a second
digitalWrite(redLED4, LOW); //Red led off
digitalWrite(greenLED3, HIGH); //Green led on
delay(50); //wait for 1/25 of a second
digitalWrite(greenLED3, LOW); //Green led off
digitalWrite(yellowLED2, HIGH); //Yellow led on
delay(50); //wait for 1/25 of a second
digitalWrite(yellowLED2, LOW); //Yellow led off
}
The explanations for the code are on each line.
Here is a breakdown of the functions used -
int
gives a name for the component that is connected to a digital pin. For example,int
blueLED1
=
2;
means that the blue led is connected to Digital IO pin 2. (See hardware schematic)
pinMode
sets something as an input or output. For example,pinMode(blueLED1,
OUTPUT);
sets the blue led as output.
digitalWrite
turns the components on and off. For example,digitalWrite(buzzer,
HIGH);
sets the buzzer on.
delay
creates a pause and goes by the time as ifdelay(1000);
were 1 second. Therefore, delay(50); is 1/20 of a second. (I think my math is correct :D )
Upload the code, and give yourself a pat on the back. You have just completed the project! If something is not working, please comment in the section below.
If you enjoyed this project, please click here to view my other ones. Thank you!
Comments