Hi , I saw the project of Ben heck show :https://www.youtube.com/watch?v=tAyWrJoVUbs
It's a ultrasonic following robot ,the basic principle is there are two ultrasonic sensors on the robot, and the guy who is followed by the robot has one ultrasonic sensor.
The module I use is HC-SR04. http://www.micropik.com/PDF/HCSR04.pdf
It has two big eyes ,one is to receive the ultra sonic ,another one is to send ultrasonic.
As the film , robot is a receiver ,guy is a sender, when the guy send the ultrasonic ,the robot would check the distance difference between the two receivers to the sender,and decide which way to go.(11:54)
Because it only trace the signal from the sender instead of original function, they cut off the receivers' transmit eyes to receive only ,we don't want to receive the reflection by its own , cut off sender's receive eye to send signal only.(5:03)
The tricky part is receiver still need to send 10us pulse to trig pin to trigger the echo pin high and send 8-cycle 40kHZ ultrasonic from the transmit eye, the echo pin would be high until receive ultrasonic ,this low high -high low interval is the distance we want, but the receiver cut off the transmit eye , so it only trigger the echo pin high.
The big problem is the receiver and the sender need to be synchronized, they need to send 10us to trig pin individually at the same time to avoid wrong distance measurement,so Ben use xbee(15:42) to make Wireless transmission,when receiver send 10 pulse to trig pin, it immediately send the signal through xbee to tell the sender send 10us pulse to sender's trig pin,too.
I only have blue tooth hc-05&hc-06 right now so I try to do wireless transmission by blue tooth,if it is work, I will try to use xbee instead of .
But the truth is wireless transmission by blue tooth is so slow , it takes almost 100ms to send data to sender, when sender catch the command from xbee then sends signal to receiver ,the receiver's echo pin already been high a long time, it always shows large value like dozen of meters even I put them together,and it is not take a certain time to send data by wireless trasmission, sometimes 100ms,sometimes 50ms.I wonder if the xbee has the same problem?
How did Ben compliment the synchronization,or I totally misunderstood the whole process?
RECEIVER:
#include <Ultrasonic.h>
#define ECHO_PIN 13
#define TRIGGER_PIN 12
float cmMsec=0;
long microsec=0;
Ultrasonic ultrasonic(TRIGGER_PIN, ECHO_PIN);
void setup(){
Serial.begin(9600);
Serial3.begin(9600);
}
void loop() {
if(Serial.available()){
c=Serial.read();
Serial3.write(c);
digitalWrite(TRIGGER_PIN, LOW);
delayMicroseconds(2);
digitalWrite(TRIGGER_PIN, HIGH);
delayMicroseconds(10);
digitalWrite(TRIGGER_PIN, LOW);
microsec=pulseIn(ECHO_PIN, HIGH);
}
cmMsec = ultrasonic.convert(microsec, Ultrasonic::CM)*2;
Serial.print("MS: ");
Serial.print(microsec);
Serial.print(", CM: ");
Serial.println(cmMsec);
}
SENDER:
#include <Ultrasonic.h>
#include <SoftwareSerial.h>// UNO BOARD
#define TRIGGER_PIN 12
#define ECHO_PIN 13
float cmMsec;
SoftwareSerial BTSerial(2, 3); // RX | TX
Ultrasonic ultrasonic(TRIGGER_PIN, ECHO_PIN);
long microsec=0;
char c = ' ';
void setup(){
Serial.begin(9600);
BTSerial.begin(9600);
}
void loop(){
if(BTSerial.available()){
microsec = ultrasonic.timing();
c=BTSerial.read();
Serial.write(c);
cmMsec = ultrasonic.convert(microsec, Ultrasonic::CM);
Serial.print("MS: ");
Serial.print(microsec);
Serial.print(", CM: ");
Serial.println(cmMsec);
}
