ORG030

DEEP SEA BIG PINEAPPLE GROUP

Hardware Selection & Technical Solution Testing

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:

https://wiki.dfrobot.com.cn/_SKU_DFR0052_%E6%A8%A1%E6%8B%9F%E5%8E%8B%E7%94%B5%E9%99%B6%E7%93%B7%E9%9C%87%E5%8A%A8%E4%BC%A0%E6%84%9F%E5%99%A8

(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
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
void setup() {
Serial.begin(9600);
}
void loop() {
int val;
val=analogRead(A0);
Serial.print("Gray scale:");
Serial.println(val,DEC);

if (val > 940) {
Serial.println(" white! ");
}
if (val >= 800 && val <= 880) {
Serial.println(" Nothing! "); //
}
if (val >= 880 && val <= 920) {
Serial.println("other"); //
}
if (val >= 700 && val <= 800) {
Serial.println(" Black! "); //
}

delay(500);
}

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
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#include <SimpleList.h>
#include <SoftwareSerial.h>
#include <DFRobot_SerialMp3.h>
#include <DFRobot_NeoPixel.h>
#include <DFRobot_PlayerMini.h>

// 动态变量
volatile float mind_n_HuiDu;

// 函数声明
void DF_HuiDuJianCe(int mind_n_int);
void preplay(int songnumber);
void lighting(int site);

// 创建对象
DFRobot_SerialMp3 serialMp3;
DFRobot_SerialMp3 serialMp3_1;
DFRobot_SerialMp3 serialMp3_2;

DFRobot_NeoPixel neoPixel_6;
SoftwareSerial softSerialserialMp3(2, 3);

DFRobot_PlayerMini mp3_1;
SoftwareSerial softSerialserialMp3_1(50, 51);

DFRobot_PlayerMini mp3_2;
SoftwareSerial softSerialserialMp3_2(52, 53);

const int buttonPin = 10;
int buttonState = 0;

// 定义变量以存储上一次的按钮状态
int lastButtonState = 0;
int playState = 1;
int i = 0;
int speed = 100;
const int analogPin = A15; // 旋钮连接的模拟引脚

int list1[13] = {0};

int white[13] = {776, 880, 831, 846, 880, 860, 858, 881, 850, 869, 859, 853, 819};
int whitee[13] = {780, 899, 840, 870, 890, 872, 870, 889, 868, 886, 875, 866, 833};

int grey[13] = {680, 835, 796, 786, 825, 800, 792, 823, 780, 815, 817, 790, 757};
int greyy[13] = {680, 842, 800, 808, 831, 816, 806, 838, 800, 835, 831, 810, 767};

int red[13] = {660, 815, 775, 755, 797, 775, 773, 805, 754, 780, 803, 738, 734};
int redd[13] = {665, 823, 780, 775, 803, 788, 783, 814, 762, 800, 814, 750, 745};

int black[13] = {598, 760, 741, 620, 672, 675, 666, 695, 612, 680, 760, 670, 656};
int blackk[13] = {625, 764, 743, 665, 686, 685, 686, 720, 640, 695, 762, 685, 662};

int myNumbers[13] = {4, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
int now = 0;

// 主程序开始
void setup() {
pinMode(buttonPin, INPUT);
Serial.begin(9600);

neoPixel_6.begin(6, 30);
neoPixel_6.clear();

serialMp3.begin(&softSerialserialMp3);
serialMp3.volume(100);

serialMp3_1.begin(&softSerialserialMp3_1);
serialMp3_1.volume(80);

serialMp3_2.begin(&softSerialserialMp3_2);
serialMp3_2.volume(100);
}

void loop() {
int analogValue;

if (playState != 0) {
for (int pin = A0; pin < A13; ++pin) {
DF_HuiDuJianCe(pin);
delay(20);
}
}

buttonState = digitalRead(buttonPin);

if (buttonState != lastButtonState) {
if (buttonState == HIGH) {
playState = !playState;
i = 0;
}
}

int sensorValue = analogRead(analogPin);
float speed = map(sensorValue, 0, 1023, 30, 100) * 0.01;

if (playState == 0) {
if (i % 2 == 0) {
if (list1[i / 2 + 1] > 0) {
serialMp3_2.playList(list1[i / 2 + 1]);
}
}
if (list1[i + 5] > 0) {
serialMp3_1.playList(list1[i + 5]);
}

if (list1[0] > 0) {
serialMp3.playList(list1[0]);
}

delay(200 * speed);
neoPixel_6.setRangeColor(i * 3, i * 3, 0xFFFFFF);
delay(1200 * speed);
neoPixel_6.clear();
delay(600 * speed);
i = i + 1;
if (i == 8) {
i = 0;
}
}

lastButtonState = buttonState;
}

void DF_HuiDuJianCe(int pinnumber) {
mind_n_HuiDu = analogRead(pinnumber);

Serial.print("Analog value at ");
Serial.print(pinnumber);
Serial.print(": ");
Serial.println(mind_n_HuiDu);
Serial.println(list1[pinnumber - 54]);

if (((mind_n_HuiDu >= white[pinnumber - 54]) && (mind_n_HuiDu <= whitee[pinnumber - 54]))) {
now = 1; // 白色
} else if (((mind_n_HuiDu >= black[pinnumber - 54]) && (mind_n_HuiDu <= blackk[pinnumber - 54]))) {
now = 4; // 黑色
} else if (((mind_n_HuiDu >= red[pinnumber - 54]) && (mind_n_HuiDu <= redd[pinnumber - 54]))) {
now = 3; // 红色
} else if (((mind_n_HuiDu >= grey[pinnumber - 54]) && (mind_n_HuiDu <= greyy[pinnumber - 54]))) {
now = 2; // 灰色
} else {
now = 0;
}

if (now != list1[pinnumber - 54]) {
list1[pinnumber - 54] = now;
Serial.println(list1[pinnumber - 54]);
if ((now != 0) && (playState != 0)) {
preplay(now);
lighting(pinnumber - 54);
}
}
}

void preplay(int songnumber) {
serialMp3_1.playList(songnumber);
delay(500);
}

void lighting(int site) {
if (site == 0) {
// 中心轨道 亮蓝色
for (int n = 0; n < 8; ++n) {
neoPixel_6.setRangeColor(n * 3, n * 3, 0xFFFF00);
}
delay(700);
neoPixel_6.clear();
} else if ((site > 0) && (site <= 4)) {
// 方形轨道 亮黄色
neoPixel_6.setRangeColor(site * 6 - 6, site * 6 - 6, 0x3366FF);
delay(700);
neoPixel_6.clear();
} else {
// 花瓣轨道 亮粉色
neoPixel_6.setRangeColor(site * 3 - 15, site * 3 - 15, 0xCC66CC);
delay(700);
neoPixel_6.clear();
}
}

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

https://blog.csdn.net/sdagv/article/details/121152791