Party time
For this week’s assignment, I designed a Smart Spectrum Circuit that combines an RGB LED and a buzzer, both controlled wirelessly through a Bluetooth connection. The project allows me to select different colors for the RGB LED, and each color is linked with a unique buzzer sound frequency. For example, if the LED glows red, the buzzer plays a low tone, while blue gives a higher tone.
This creates a multi-sensory feedback system where light and sound are synchronized. I control the circuit via a Graphical User Interface (GUI) on a PC or smartphone, sending simple commands through Bluetooth to change both the color and the sound.
RGB LED
Jumper wire
Resistor
Buzzer
Adapter
Arduino
Simulation:
TinkerCAD
Fritzing
Implementation:
Electronic kit
Arduino Bluetooth
Create a TinkerCAD simulation
Create a Fritzng simulation
Serial setup
The Arduino starts communication with the computer or HC-05 Bluetooth module at 9600 baud.
This lets it receive characters like '1', '2', '3', etc.
Serial.begin(9600);
Pin setup
Pins 9, 10, and 11 are used to control the RGB LED colors.
Pin A0 is used as the buzzer output.
These are set as INPUT in the sketch, but they should actually be OUTPUT since we’re driving LED and buzzer (a small mistake in code).
pinMode(9, INPUT);
pinMode(10, INPUT);
pinMode(11, INPUT);
pinMode(A0, INPUT);
Listening for Bluetooth / Serial data
Inside loop(), the Arduino checks if there is any data coming from Serial.
If yes, it reads one character into the variable command.
if (Serial.available()) {
command = Serial.read();
Command cases
Depending on the character received, the Arduino changes the LED color and makes the buzzer beep at a certain frequency.
For example:
'1' => Red LED, buzzer at 600 Hz
'2' => Green LED, buzzer at 800 Hz
'3' => Blue LED, buzzer at 1000 Hz
'4'=> Yellow (Red+Green), buzzer at 1200 Hz
'5' =>Cyan (Green+Blue), buzzer at 1400 Hz
'6' => LED off, buzzer silent
switch (command) {
case '1':
setColor(255, 0, 0); // red
tone(A0, 600);
break;
...
case '6':
setColor(0, 0, 0); off
noTone(A0);
break;
setColor() function
This function writes values to the LED pins using PWM (analogWrite).
Each color (red, green, blue) is given a value between 0–255.
The combination creates the visible color.
void setColor(int red, int green, int blue) {
analogWrite(10, red); // Green
analogWrite(9, green); // Red
analogWrite(11, blue); // Blue
I used a switch–case statement because my program needs to react to different values of the same variable (command). Instead of writing a long chain of if and else if conditions to check whether command is '1', '2', '3', and so on, the switch–case structure organizes these options neatly in separate blocks. This makes the code easier for me to read, understand, and maintain, since each case clearly shows what happens for that specific input. It also makes the program slightly more efficient, because the Arduino can jump directly to the matching case rather than checking every condition in sequence. Overall, it’s the best choice when I have multiple clear options tied to one variable.
Implement the Circuits
I did not define the tone which was A0
When I wrote the code, they colours change but the buzzer creates a light sound. It was strange as i wrote the code correctly.
I am very lucky that I have colleagues who are already coder. As they saw the code and we sat together discussing the code, turns out i should have written " tone(A0, 800)" not " tone(800)". I thought by writing "pinMode(A0, INPUT)", then it will be enough!!
At first, I tried to write the program using only if–else statements, but I quickly found it difficult and messy to manage. Each condition for command made the code longer and harder to follow, and I kept worrying that I might make a mistake or forget one of the cases. When I showed my attempt to a friend, he recommended that I use a switch–case instead. It was explained that it would make the program much cleaner and easier to read, since each command would have its own clear section. Taking their advice, I rewrote the code using switch–case, and it immediately looked more organized and worked more smoothly.
Them trying to help me XD!!!!!!
CODING!!!!!
On Saturday, when we had to do the assignment, I had a problem in the connection, the arm did not want to work. It moves once then stops moving. After my colleagues finished their work they came to help me, recheck the code.
One colleague suggested to make an eqution for the movement. Instead saying "case 1 = 5 cm to the right", its written "case 1 = x + 5 cm to the right", where x is defined as the previous value.
Not for the final project but in general, i enjoyed learning how to connect the my phone with a prototype. Maybe next time for my final project I will add the phone feature.
How to connect the Arduino with the Bluetooth via RX and TX.
Title of Media