I reused last week's project for this week's assignment but enhanced it by programming the LED lights to interact with music using two different switches.also control it with wirelessly via mobile app through bluetooth module
the software:
thinker cad
Arduino
RDWorks
adobe illustrator
Arduino Bluetooth control
the materials:
construction parts
acrylic sheets
plywood
blu tack
ُُElectronic components
breadboard
Arduino uno board
LEDs (12 pcs)
multiple wires (Jumpers)
microwave sensor (only week06 ) no need now
resistors 330ohms (12 pcs)
buzzer (for weeks 07 & 08)
slider switch (for week07)
Bluetooth module (for week08)
the machines:
laser-cut machine
First, I prepared the components in Tinkercad .I gathered an Arduino, a breadboard, 12 LEDs, 12 resistors, a buzzer, and two switches and blutooth module
I couldn’t test the simulation on Tinkercad because it didn’t work, so I left last week’s videos as they were.However, it worked when I tested it in real life. The only change I made was replacing the two buttons with wireless ones in the code. Then, I attempted to integrate both the button and Bluetooth so the circuit could work with either the button or a mobile application and that was the tricky part.
final simulation
I had to apply some blu Tack to the buzzer to reduce its loudness.
final circut wiring
I wired the Bluetooth module as shown in the picture and the Tinkercad simulation: VCC to positive, GND to negative, RX to pin 1 (TX), and TX to pin 0 (RX).
I also replaced the larger button with another slider switch since it was easier to use and helped reduce the number of wires.
Star Wars testing with a button
harrypotter testing with a button
I first tested the previous melodies with the button to ensure they were working efficiently on their own. Then, I disconnected the buttons and replaced them with the Bluetooth module. I modified the code so that if incoming data == '1', the Star Wars melody would play, and if I pressed '2', it would turn off. then tested the other melody separately using the same concept, but with '3' to play and '4' to turn it off. After confirming both worked individually, I combined them, as shown in the videos.
Star Wars testing with app 1 is on, 2 is off
Harry Potter testing with app 3 is on, 4 is off
combining both together
final outcome
This Arduino sketch is designed to play two different melodies using a buzzer while controlling LEDs. The melody playback is triggered via a Bluetooth serial connection, where different commands can start or stop the melodies.
variables used:
tempo1, tempo2: Define the beats per minute (BPM) for two different melodies.
buzzer: PIN (9) where the buzzer is connected.
ledPins[]: Array storing the digital pins for controlling six LEDs.
numLeds: The number of LEDs.
melody1[], melody2[]: Arrays storing note frequencies and durations for two different melodies.
notes1, notes2: Calculate the number of notes in each melody.
wholenote1, wholenote2: Define the duration of a whole note based on the tempo.
divider, noteDuration: Used for calculating individual note durations.
incomingData: Stores received Bluetooth serial commands
Function used:
setup() Function: Initializes serial communication at a 9600 baud rate. Configures the buzzer as an output. Configures LED pins as outputs.
loop() Function: Waits for Bluetooth data input. Reads the received command and performs actions: '1' Plays melody1 1, and2' Stops playing and turns off LEDs and '3' Plays melody2 and '4' Stops playing and turns off LEDs
playMelody(): Loops through the melody array. Checks if a stop command ('2' or '4') is received. Determines note duration based on divider (if negative, it's a dotted note).Uses tone() to play the note on the buzzer.Lights up LEDs in sequence while playing the note. Stops the tone after each note
stopEverything() : Turns off the buzzer.Turns off all LEDs.
Since my project in Week 08 remained essentially the same as Week 07, with the only change being replacing physical buttons with mobile buttons via the Bluetooth module, the feedback, ideas, and suggestions were identical to those from Week 07.
Additionally, I had concerns regarding my final project. During the Makeathon, when we used a Bluetooth module to control the robotic arm, we encountered some challenges, ,specifically, the Bluetooth connection frequently dropped in and out. Because of this, I asked Abdelrahman whether I should include manual mode buttons to sync with the Bluetooth button sequences in case the connection failed. He explained that the issue occurred because multiple teams were using Bluetooth modules simultaneously, causing interference. He reassured me that this wouldn't be a problem in my final project since not many people would be using Bluetooth modules at the same time. Therefore, he advised that I stick with the Bluetooth approach rather than adding manual buttons.
While working on the project, I encountered a few challenges, mainly in two areas:
Bluetooth communication issues: Sometimes, the commands sent from my phone weren't received correctly by the Arduino, causing delays or the wrong melody to play.
Timing and synchronization The LED sequence wasn’t syncing properly with the music, making it feel offbeat.
I remembered Ahmed Sami during the session while debugging the code and used Serial.println() to check if the Bluetooth module was sending signals. So I did the same. When I saw that no signals were being received, I rechecked the connections, powered the system off, and turned it back on until it finally worked.
I also tested the LEDs using an avometer since the Bluetooth module was successfully transmitting signals and the music played correctly, but the LEDs weren’t responding. That’s when I realized the issue was in the code.
One of the biggest learning moments was figuring out how to stop the melody instantly when a new command was received. Initially, the program would keep playing the entire tune before switching to a new one, even if I pressed "stop."
I had to research how to interrupt the for loop controlling the melody playback when new data was received. I found that checking Serial.available() inside the loop and breaking out when necessary was the best way to fix it. I also learned that using timers instead of delay() could improve responsiveness, but I decided to keep it simple for this project. and use this method later in the final project
Using delay() too much Initially, I had delays between LED changes, which slowed down responsiveness. Using shorter delays or timers made the system more interactive.
Not using power-efficient code. Keeping the buzzer running without breaks caused distortion in the sound. A small pause (note duration * 0.9) helped maintain clarity.