BUZZER REACT TO A SPECIFIC RGB LED COLOR:
In this tutorial it will be explained that how buzzer reacts to a specific RGB color. For example, it could be an alarm for specific situation, which is defined by colors. That is, as the color of RGB changes, the alarm sound changes and has a specific meaning.
Note: This tutorial only focuses on one color and one sound. Based on, different voltage and different RGB colors, buzzer could be applied for more kinds of notes and sounds.
• Arduino UNO (1)
• Breadboard (1)
• RGB LED (1)
• Jumper wire (11)
• 330 Ohm resistor (3)
• Piezo element (1)
• Potentiometer (1)
How to set up:
The first thing should be done is assembling all parts on the breadboard. Then, start coding.
Note1: Be sure that RGB led legs are connected correctly (in terms of colors and Common leg which is connected to GND without resistor).
Note2: Most LEDs are designed to work with a voltage between 1.5v and 3v. As most microcontrollers (including the Arduino) operate on 5 volts a current limiting resistor is required.
The following diagram shows how to assemble the parts on the breadboard:
Your final assembly should be something like this:
Please note that your Arduino must not be connected to the computer. Otherwise, the power might damage or burn out the parts. The code is as follows and next to each part it is explained what each part does.
//BUZZER REACTS TO A SPECIFIC RGB LED COLOR:
int red = 9; //Digital pin9 for red led
int green = 10; //Digital pin10 for green led
int blue = 11; //Digital pin11 for blue led
// This verifies the pins for RGB led light on the board
int sound = 12; //Digital pin for piezo buzzer
int sensorpin = 0; // The potentiometer is connected to analog pin 0
int sensorValue = 0; //introducing vriable
void setup() //method runs once, when the sketch starts
pinMode(red, OUTPUT); // initialize the digital pin as an output
Serial.begin(9600); //initialize serial communication at 9600 bits per second
void loop() // the loop() method runs over and over again
sensorValue = analogRead(sensorpin); // read the value from the sensor
Serial.println(sensorValue); // print out the value you read
if (sensorValue > 0 && sensorValue <=200)//if voltage value is between 0 and 200, do next step
analogWrite(red, 255); //turn the red light on
digitalWrite(sound, HIGH); //Piezo sing
analogWrite(green, 255);//turn the green light on
digitalWrite(sound, LOW);//Piezo silence
Now to see the result, plug in your Arduino, upload your code and tern the potentiometer. The result should be like this video: