How to use the MP3 player from CATALEX
Source: InternetPublisher:狂妄火龙果 Keywords: Sensor player MP3 Updated: 2024/08/06
How to use the MP3 player from CATALEX
Only one library is needed (#include 《SoftwareSerial.h》) and there are some simple functions:
How to use HC-SR04 within the specified range
Inside, it's easy to use.
How to use them both Your version 1: simple mp3 if simple
If you don't have the library yet, please install it first (SoftwareSerial.h).
In this version of the code, if something gets close to 50, the mp3 audio is triggered.
NOTE: The complete .ino code is in the project attachment below.
How to use version 2 Similar to Disturbance mp3
This version does not affect the detection distance, only the difference between scans. If the error triggers suddenly, if (gap > 20) {. We need to declare the new variable outside the loop at the same time.
int firstTime=0;//we need to declare firstTime outside the loop
long Distance,auxDistance,gap=0;
void loop()
{
Distance=measureDistance(trigPin,echoPin);//measure distance and store
gap=abs(Distance-auxDistance);//calculate the difference between now and last reading
if(firstTime==0){//needed for stability,
auxDistance=Distance;
gap=0;
//only do this for the first time after playing a song to avoid first loop glitch
firstTime++;
delay(1000);
}
if(gap>20){ //if the distance changed by 20cm
sendCommand(CMD_PLAY_WITHFOLDER, 0X0201);//play the first song of the second folder
firstTime=0;//avoid errors!! We don't like errors
delay(2000);
}
Serial.print("New Distace:"); //debugggggg
Serial.print(Distance);
Serial.print("Old Distance:");
Serial.print(auxDistance);
Serial.println(gap);
delay(300);
auxDistance = Distance; //store the value of if() for the next loop
}
How to use them version 3: two distance sensors
Using two distance sensors, you can actually infer the direction of movement, so I made a program that can tell "hello" or "goodbye" based on the person's movement.
First, we'll digitize two more controls to control the second HC-SR04:
New variables!
In settings() we add new settings.
We can now get parameters from functions, change parameters.
In our loop():
void loop()
{
Distance=measureDistance(trigPin,echoPin);//Measure distance 1 and store
Distance2=measureDistance(trigPin2,echoPin2);//Measure distance 2 and store
gap=abs(Distance-auxDistance);//Calculate the difference between now and last reading
gap2=abs(Distance2-auxDistance2);//Calculate the difference between now and last reading
if(firstTime==0){//Necessary stuff for stability
auxDistance=Distance;
auxDistance2=Distance2;
gap=0;
gap2=0;
//Only do this the first time after playing a song to avoid first loop glitch
firstTime++;
delay(2000);
}
if(gap>20 and gap2<20 ){ //If distance changed by 20cm
sendCommand(CMD_PLAY_WITHFOLDER, 0X0201);//Play the first song of the second folder
firstTime=0;//Avoid bugs! ! We don't like errors
Serial.println("RIGHT MOVEMENT DETECTED");
delay(2000);
}
if(gap2>20 and gap<20){ //If the distance change is 20cm
sendCommand(CMD_PLAY_WITHFOLDER, 0X0202);//Play the second song in the second folder
firstTime=0;//Avoid errors ! ! We don't like errors
Serial.println("Left movement detected");
delay(2000);
}
Serial.println("\\\\\");//debugggggg
Serial.print("New Distace:");//debugggggg
Serial.print(distance);
Serial.print("Old distance:");
Serial.
Serial.print("GAP");
Serial.println(GAP);
Serial.print("New Distace2:");//debugggggg
Serial.print(Distance);
Serial.print("Old Distance2:"); Serial.print(
AuxDistance)
; Serial.print("GAP2");Serial.println
(GAP);
Serial.println("\\\\\");//debugggggg
delay(300);
auxDistance=Distance;//store the value of if() for the next loop
auxDistance2=Distance2;//store the value of if() for the next loop
}
Disturbance2=0;
Left=0;
Right=0;
delay(1000);//wait to avoid error
}
delay(300);
auxDistance=Distance;
auxDistance2=Distance2;//store the value of if() for the next loop
}
- Factors affecting the life of LiFePO4 batteries, how to extend the life of LiFePO4 batteries
- What is the LiFePO4 discharge curve? Advantages and applications of LiFePO4 discharge curve
- How to Build a Simple Yet Powerful MP3 Player
- Building an open source dynamic light scattering device
- How to make a clock Bluetooth IOT speaker using Arduino
- How to build an autonomous robot using the DonkeyCar platform
- The production principle of high voltage self-defense flashlight and electric stick
- Ultrasonic dog chaser made by NE555
- Design of smart radiator valve for home based on Raspberry Pi
- Analysis of the circuit of DL-01 low-frequency electrotherapy instrument
- Low power consumption 1.8V temperature sensor, have you heard of it?
- New ultra-thin fully integrated proximity sensor, do you know?
- Contact switch or proximity sensor circuit
- Ultrasonic proximity sensor circuit
- Humidity detector circuit
- Gyro amplifier circuit
- Thermocouple Thermometer Circuit
- SHD201 single feed water pump water level automatic control soft start circuit b
- Current-to-voltage converter with grounded bias and sensor
- MP3 circuit diagram_torque solution 1