Being able to help people in need with innovative technology is very rewarding. build2tegether gives you a chance to use ultrasonic sensors to provide reminders for people with disabilities to avoid obstacles when swimming or traveling. The way to achieve this is to send ultrasound through the ultrasonic sensor, receive the ultrasonic echo and calculate the time at the same time, multiply the speed of sound to get the distance in the direction of ultrasonic transmission, and then show the distance at different intervals through the buzzer, reminding the disabled of the approaching obstacles, the whole process is like a bat obstacle avoidance mechanism in nature.
2.Part SourcingIn order to achieve this goal, we applied for the blues swan development board as the main control board, purchased the ultrasonic sensor SR04, purchased the buzzer from grove, and used Arduino as the development platform for rapid development:
1) blues swan
2) SR04
3) Buzzer
4) Wires and bread board
3. BuildingThe main body of the circuit is the Swan development board,
The development board is connected to the ultrasonic sensor SR04 via GPIO.
Connect with Buzzer via GPIO,
The entire circuit is shown in the figure.
We need to connect Swan's GPIO to the Echo and Trigger of SR04, send ultrasonic waves by triggering a high-level pulse of more than 10ms at the Trigg pin, and detect the time of the high-level pulse at the echo pin, so as to obtain the delay of ultrasonic sending to reception, multiply by the speed of sound and divide by 2 to get the distance. Normalize the distance to 2 meters to 2 centimeters, and invoke the buzzer as a parameter to sound.
#include <Arduino.h>
// put function declarations here:
// PA3->A0 PA1->A1 PC3->A2
#define TRIG PA5
#define ECHO PA6
#define ALARM PA7
long duration, distance;
void setup() {
// put your setup code here, to run once:
pinMode(TRIG,OUTPUT);
pinMode(ECHO,INPUT);
pinMode(ALARM,OUTPUT);
pinMode(LED_BUILTIN, OUTPUT);
}
void flash(int dis){
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(distance*10); // wait for a second
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
delay(distance*10);
}
// put function definitions here:
int Sonar() {
//sent pulse to trig
digitalWrite(TRIG, LOW);
delayMicroseconds(5);
digitalWrite(TRIG, HIGH);
delayMicroseconds(10);
digitalWrite(TRIG, LOW);
duration = pulseIn(ECHO,HIGH,250000);
//calc distance,unit cm.
distance = duration/2/29.1;
return distance;
}
//if distance is too near, broadcast alarm sound
void alarm(int dis){
int max = 250;
int min = 20;
int dd = 250;
if (dis> max)
dis = max;
else if(dis<min)
dis = min;
dd = (dis-min)*1.0/(max-min)+min;
digitalWrite(ALARM, HIGH); // turn the LED on (HIGH is the voltage level)
delay(dd); // wait for a second
digitalWrite(ALARM, LOW); // turn the LED off by making the voltage LOW
delay(dd); // wait for a second
}
//display sonar value in screen
void display(int dis){
}
void loop() {
// put your main code here, to run repeatedly:
long distant = 0;
distant = Sonar();
alarm(distant);
delayMicroseconds(250);
flash(distant);
}
Comments