Input devices¶
Group Assignment¶
This week we focused on exploring different input devices and how they interact with microcontrollers. As a group, we tested and analyzed several sensors using both microcontroller readings and oscilloscope visualization.
As a group, we tested three main input devices:
MAX30102 Pulse Oximeter & Heart Rate Sensor
We used a breakout module to measure pulse rate using infrared and red LEDs. The change in IR reflection caused by blood flow was captured and processed using Arduino code to calculate BPM.
Analog IR Distance Sensor (GP2Y0A02YK)
This analog Sharp sensor outputs a voltage based on the distance to an object. We powered it at 5V and visualized the analog signal on an oscilloscope, confirming that the voltage decreased as distance increased (working range around 20–150 cm).
Digital Ultrasonic Sensor (US-100 Y401)
We connected the trigger and echo pins to generate and capture ultrasonic pulses. Using an oscilloscope, we examined the echo pulse width and how it changes with distance.
I used all these devices before, but it was good to refresh my memory
You can find all work that we did here
Guitar String Frequency Detection – Input Device¶
For this week’s assignment, I used a piezoelectric element as an input device to detect the vibration of guitar strings. The signal is then read and analyzed by the Raspberry Pi Pico 2W to determine the string’s frequency.
Piezoelectric Sensor¶
A piezoelectric disc converts mechanical vibrations into voltage. When placed on a vibrating surface, such as a guitar body or near a string, it generates an AC signal that corresponds to the vibration frequency.
It has raw output range: Approximately -100 mV to +100 mV when plucked. But Raspberry Pi Pico’s ADC can only measure signals in the range 0–3.3V, so direct connection is not possible. Which is solved by Amplifier circuit that I described in my Electronics Design Week
Code¶
I am writing code in ThonnyIDE using micropython. So I devided my code into pieces to describe separately.
Amplified signal must be processed by Raspberry, so to that, it must be digitalised. That process is made by ADC (Analog to Digital Converter) which is GPIO26 port of my board.
The middle (zero-level) of my signal is not zero, as it is pushed up and amplified. It must be around 1.75V
(Measured while no note played)
I’ve set Sampling Rate: 5000 Hz (5 kHz) and Buffer Size: 1024 samples Sampling happens in real time using precise delays to keep timing consistent.
This buffer is then analyzed to extract the frequency of the signal.
After collecting a buffer of 1024 samples, the program:
- Converts ADC values to voltage using Pico’s 12-bit resolution and 3.3V reference.
- Scans for positive-going zero crossings — when the signal moves from below the center voltage (1.75V) to above it.
- Counts how many such crossings occur in the buffer.
- Each crossing is treated as one cycle of the waveform, so the frequency = crossings / time.
- If the frequency is within ±3 Hz of a standard guitar string (E2, A2, D3, etc.), it’s matched to that string.
Standard tuning frequencies used in the code:
String | Frequency (Hz) |
---|---|
E2 | 82.41 |
A2 | 110.00 |
D3 | 146.83 |
G3 | 196.00 |
B3 | 246.94 |
E4 | 329.63 |
To avoid false detections a noise threshold is set: if all samples stay too close to the center voltage (less than ±50 mV), the signal is considered silent. This helps filter out minor vibrations and ambient noise.
¶
Setup¶
I connected piezoelement to Guitar’s head by tape to measure vibrations from that part. (I think that because the wood is thicker in that area, the vibrations are more clearly transmitted.)
Also i wired long wire to sensor, for having signal on distance, It is easier to check device’s work, until it is connected to PC by USB.
Work Video¶
So after everything is properly connected, I tried to runned program.
As you can see Everything works awful. The strings are not properly found.
Then I realised, that i must push sensor to guitar, and as hard I push clearer result I get
So I ended up with forcing sensor to give me right results. :)
And then
GREAT!!! IT WORKS.
So I connected OLED to my board, which I described in my Output devices week
And connected Input and output program parts, and got this
Conclusion¶
This week helped me understand how different types of input sensors work — analog, digital, and optical. I learned how to properly bias and power sensors, how to visualize sensor output on an oscilloscope, and how to interpret raw signals. Also I am very happy for what i did this week. I learnt a lot about signal processing, sound signals, micropython and a lot of more things. After not getting string name for very long time, I found very funny solution - just put force))
Program File¶
You can find Code File here