Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

Mechatronics Project Report

Part 1

This project aims to provide an alternative way of explaining the working principle of time-adjusted music reactive
lighting systems. The function of this setup is to analyse the sound coming from the KY-038 sensor and present how
loud the sound is at a particular time. This representation of loudness will be achieved with the LED system. To
simplify, the system will light up more LEDs as the sound coming from the sensor gets louder. This will be achieved
without the help of any external library to provide the general understanding of time-adjusted music reactive
lighting systems.

Part 2

The first accomplishment of this report is to provide a visual confirmation of the accuracy of the KY-038 sensor. Even
though it would be so hard for this report to measure the accuracy of the sensor statistically, figure 1 clearly shows
that KY-038 works properly and accurately. We have the original soundwave at top and sensor recorded
soundwaves at the bottom

Figure 1

The basic working principle of a sound sensor is to convert sound energy into electric energy
as diaphragm in the sensor is triggered by the pressure differences of air due to sound
travelling. When the sound wave hits the diaphragm, the diaphragm moves. Based upon this
movement, the magnet and the coil in the sensor convert this motion into electricity. With a
help of microcontroller, this voltage can further be read as analog or digital. As we see in the
sample at left, when we have an increase in the voltage which means the sound is louder at
that point, we just after that have a respectively equal decrease from the average meaning no
sound at all.

The looping approach that we will follow would not work if we don’t erase the bottom part of
this sound. Unless we only have the parts where sound increase above the average, we would
observe “jumpings” for the entire setup. In other words, the system would light up 5 LEDs at
the loudest point and after 0.005 seconds (delay between each loop automatically set up by
Arduino), we would have 0 LEDs open as the system would consider it as quietness. Since this
would happen for each level, we need to delete the points where the points is below the threshold. It is acquired
based upon following.
𝜏, 𝑥<𝜏
𝑓(𝑥) = {
𝑥, 𝑥≥𝜏
∑𝑛𝑖=1 𝑓(𝑖)
𝜏 = 𝑇ℎ𝑟𝑒𝑠ℎ𝑜𝑙𝑑 =
𝑙𝑒𝑛𝑔𝑡ℎ(𝑓)
Within this report, I analyse 2 methodologies for looping: Loudness method and frequency method. Within loudness
approach, I have set a function where each point in the data is rounded to its closest neighbor or group, where the
number of groups is 5 as a reference to the 5 LEDs on the board. Groups are defined as following. The distance
between each group’s value and the specific point is calculated and the point is accordingly rounded.
(max(𝑡ℎ𝑟𝑒𝑠ℎ𝑜𝑙𝑑𝑒𝑑) − min(𝑡ℎ𝑟𝑒𝑠ℎ𝑜𝑙𝑑𝑒𝑑))
𝜌=
4
𝐺𝑟𝑜𝑢𝑝 1 = min(𝑡ℎ𝑟𝑒𝑠ℎ𝑜𝑙𝑑𝑒𝑑)
𝐺𝑟𝑜𝑢𝑝 2 = min(𝑡ℎ𝑟𝑒𝑠ℎ𝑜𝑙𝑑𝑒𝑑) + 𝜌
𝐺𝑟𝑜𝑢𝑝 3 = min(𝑡ℎ𝑟𝑒𝑠ℎ𝑜𝑙𝑑𝑒𝑑) + 2𝜌
𝐺𝑟𝑜𝑢𝑝 4 = min(𝑡ℎ𝑟𝑒𝑠ℎ𝑜𝑙𝑑𝑒𝑑) + 3𝜌
𝐺𝑟𝑜𝑢𝑝 5 = min(𝑡ℎ𝑟𝑒𝑠ℎ𝑜𝑙𝑑𝑒𝑑) + 4𝜌 = max(𝑡ℎ𝑟𝑒𝑠ℎ𝑜𝑙𝑑𝑒𝑑)

Once groups are defined as above, each point within the data is sent to their groups are the groups are rearranged
as 1, 2,3,4,5 with respect to the number of LEDs as in figure 2.

Figure 2

This graph demonstrates the sound fit into 5 different levels. When the loop hits 2 for instance, 2 LEDs light up and 3
LEDs when it hits 3 and so on with respect to the levels.

The second approach this report provides is the frequency approach. The boundaries here are not generated based
upon the loudness or the highness of the sound but how common they are. In other words, the frequency of a
number increases the chance of the number to be selected. Regarding that, we would have the following
arrangement in figure 5 for the sound in figure 1.
Figure 3

From this, we can see that it is also quite a useful approach. However, it doesn’t necessarily work as well as the
loudness method. When the same sound in the previous approach is employed to be analysed, following results are
produced.

Figure 4

It can be seen that the same accuracy is not obtained here but we have a number of huge deviations. Thus this
approach still needs to be studied on.

The lighting system

Within the system, I employed the loudness approach for the sound considering its relatively better accuracy.

To observe the system in a real case, I tested it with a human audio spectrum [1] whose required processes to be
analysed are given below.
Since we know that the loudness is increasing linearly, it can be stated that this output is quite satisfying. In terms of
the test of system, given video can be checked for that.

https://drive.google.com/file/d/1_1XLXYNILc0J5Z530Zo_4T8s2DtULINp/view?usp=sharing

In addition to that, this report employs the same system for a music [2] in order to be able to test how a real life case
would work. The analysis of the music and the system reacting to the music can be found in the given link below.

https://drive.google.com/file/d/1_4tEockO09VWPaX80nBAqPNPyJ5CC1CP/view

As the analysis shows, we needed to have 2 LEDs open for most of the time and the system worked relatively
responsive with some outstanding problems that will be justifying in the upcoming section. Considering the working
of the system, it can be stated that this system has still a number of limitations and require many improvements to
be satisfying.

First of all, we have a delay of 100 ms between each point in each of the samples we have got. Lowering or removing
this delay totally would produce better results. Nevertheless, when I attempt to remove or even decrease the delay
down to 25 ms, Arduino faces an issue of the lack of memory. Due to the working principle of the loop, each number
that will be looped through occupies some memory and Arduino UNO, the model I have got in my setup, doesn’t
have the required space within itself. As a result of this problem, even if it is linear increase as in the human
spectrum example, we cannot observe a continuous lighting with the LEDs but there is always a decrease down to 1
LED lighting.

In order to get rid of this problem, I considered a way of composing the encoded data and decoding it in Arduino
again as it would require less space in the memory. Thus, I would be able to propose a continuous lighting within the
system. However, it is hard to obtain this composition due to the working principle of C++, not being able to return
an array of integers. A possible solution to this was to use pointers instead of arrays to be returned in C++ but it is
relatively complicated as well even if I attempted to propose a function.

Within this system, I attempted to provide a general understanding of how time-adjusted music reactive lighting
systems work. The first part is the analysis of the sound coming from the sensor and the second part explains the
transmission of the code onto the LED lighting system. The system works relatively well. However, it requires many
further improvements in order to function better without the instant drops in the number of LEDs open.

The code I have utilized through this project can be found at https://github.com/ResulBulbul/mechatronicsproject.

You might also like