Hardware Selection & Technical Solution Testing
PART1. Hardware Selection for Object Recognition
Objective: To find a technical solution capable of recognizing various placed objects and playing corresponding sound effects.
(1)Simulation of Piezoelectric Ceramic Sensors
Capable of recognizing only momentary vibrations, unable to detect sustained pressure, often used in touch-sensitive applications for fingertips.
Reference Tutorial:
(2)Thin Film Pressure Sensor
Recognizes a small area, high solution cost, and requires complex accessory fabrication.
Reference Tutorial:https://www.bilibili.com/read/cv24701144/
(3)Color Recognition Sensor
Analog input demands are excessive, resulting in high solution costs.
Reference Tutorial:https://zhuanlan.zhihu.com/p/644203142?utm_id=0
(4)Infrared Grayscale Sensor 【Selected Solution】
Requires only 1 analog input, simple wiring, and low-cost implementation.
Reference Tutorial:https://www.cnblogs.com/eagler8/p/14494219.html
Basic Introduction
The grayscale sensor is an analog sensor designed to be used in conjunction with Arduino Sensor Shield v5.0. It can sense different colors on the ground or tabletop, generating corresponding signals. This sensor enables interactive projects related to color and can be employed as a line-following sensor for robotic vehicles or for grayscale recognition in soccer robots. The power supply should match the controller, typically operating at 3.3V or 5V.
Working Principle
The grayscale sensor consists of a bright white LED and a photosensitive resistor. Due to the reflection of the LED on different shades of paper, the photosensitive resistor receives varying amounts of reflected light. Depending on the intensity of the light, the resistance of the photosensitive resistor changes, allowing the testing of grayscale values.
Developed based on the semiconductor’s photoelectric effect principle, the light and grayscale sensor primarily employs a phototransistor. Within the effective detection range, the LED emits white light, which illuminates the detection surface. The surface reflects a portion of the light, causing the resistance of the phototransistor to decrease with increasing light intensity. Through series connection with a resistor, the voltage division value of the output resistor changes with the varying light signal, transforming it into an electrical signal output through the analog port. The LED on the board can be used for debugging purposes.
The grayscale sensor has three pins: Vcc for positive power, GND for ground, and OUT for the signal. In practical use, the sensor can be directly connected to the Arduino controller’s analog interface, such as analog port A0. After powering the Arduino, the sensor’s bright white LED lights up. Placing the sensor on papers of different shades, data can be read through the Arduino controller’s built-in AD conversion, and the measured analog value can be printed via serial communication.
The LED is connected in series with a 1K resistor, with the LED serving as the light source, shining on the detected object, and the 1K resistor limiting the current. The photosensitive resistor is connected in series with a 10K resistor. The photosensitive resistor has the characteristic of lower resistance with stronger light. When the LED shines on a white object, reflecting all light and resulting in high brightness, the photosensitive resistor has low resistance, low voltage division, and a high voltage output at the OUT point. Conversely, when the LED shines on a black object, absorbing all light and resulting in low brightness, the photosensitive resistor has high resistance, high voltage division, and a low voltage output at the OUT point.
Testing Code
1 | void setup() { |
PART2. Microcontroller Selection
Objective: A microcontroller capable of interfacing with multiple analog sensors.
(1)Arduino Uno:6 Analog Inputs
(2)Arduino MEGA 2560【Selected Solution】:16 analog pins (A0-A15) are available, and there are 54 digital input/output pins.
PART3. Music Playback Hardware Selection
Objective: Finding hardware capable of continuous playback of music segments.
(1)Dfplayer Mini
Hardware limitation: After playing continuously for over ten cycles, there will be a pause/reset once.
Reference Tutorial:https://wiki.dfrobot.com.cn/_SKU_DFR0299_DFPlayer_Mini%E6%A8%A1%E5%9D%97
(2)Voice Module Serial MP3【Selected Solution】
Capable of continuous music playback with built-in memory and speaker.
Reference Tutorial:https://wiki.dfrobot.com.cn/_SKU_DFR0534_Voice_Module
Final Hardware Selection for the Solution
Hardware and Code Testing Process
(1) Implementation of Basic Hardware Functions
- Implement recognition by the grayscale sensor for three colors and detection of absence.
- Implement speed control functionality using a rotary potentiometer.
- Implement the startup playback function for the LED strip and player to execute sequentially upon pressing a button.
【Implementation of Basic Hardware Functions】
Testing Video Effects: (Testing with Built-in Voice)
Recognize white color - Play “Mom”; Recognize black color - Play “Dad”; Recognize other colors - Play “Grandpa”; Detect absence - Do not play.
(2) Complete Prototype Functionality Implementation
- Connect all hardware components (13 sensors + 3 MP3 modules + LED strip + button) and perform comprehensive testing.
- Include a preview functionality for sound effects when placing objects before starting playback.
- Allow dynamic adjustment of the melody by placing objects during playback.
- Design dimension drawings for the top board based on component sizes and layout.
【Complete Prototype Functionality Implementation】
Video Effects:
- Recognize white color and play the snapping sound effect.
- Press the button to start playing the ‘ding ding’ sound.
- Rotate the rotary potentiometer to adjust the playback speed.
- Press the button again during playback to pause the music.
(3) Optimize the visual effects for the preview functionality
- Enhance the preview sound functionality by making the LED corresponding to the placed object blink.
- Differentiate the blinking colors for LEDs on different tracks.
- Model and 3D print fixtures for sensor placement.
【Optimize the visual effects for the preview functionality】
Video Effects:
- When objects are placed on different tracks, distinct lighting effects are observed.
- Square track: Corresponding positions blink in yellow.
- Petal track: Corresponding positions blink in pink-purple.
- Central loop track: All positions blink in blue.
Complete Technical Solution
Hardware Relationship Explanation
Code flow logic
Components List
- Arduino MEGA 2560 *1
- Infrared grayscale sensors *13
- Serial MP3 modules *3
- WS2812 LED strip *1m
- Rotary potentiometer *1
- Four-legged tactile switch *1
- Resistor *1
- Dupont wires, severa
Wiring diagram (12 infrared sensors omitted)
Final functional code
1 |
|
Prototype layout drawings
Grayscale sensor bracket fabrication
Rapid Prototype Testing
Reference
https://wiki.dfrobot.com.cn/_SKU_DFR0534_Voice_Module
https://blog.csdn.net/lzxiaotu/article/details/128394725
https://blog.csdn.net/weixin_41659040/article/details/132161695
https://wiki.dfrobot.com.cn/_SKU_DFR0299_DFPlayer_Mini%E6%A8%A1%E5%9D%97