Hey I have made the Ultrasonic transceiver from pocketmagic, because I want to make my Roomba robot follow me.
I have made the circuit and would like to test if I receive signals from the transmitter to the receiver, so I have attach the receiver output pin to the arduino digital pin 2:

and the transmitter diagram:
I have written this code because I wanted to see if the receiver, receives any signals from the transmitter.
int pingPin = 2;
int ledPin = 13;
void setup()
{
pinMode(ledPin,OUTPUT);
}
void loop()
{
pinMode(pingPin, INPUT);
pulseIn(pingPin, HIGH);
if (digitalRead(pingPin == HIGH))
digitalWrite(ledPin, LOW);
else
digitalWrite(ledPin,HIGH);
}
but the diode just lights up, and when I turn off the transmitter it keeps being lighten up, so I know it doesnt work. I expect the reason, the diode on pin 13 always is on is because of this statement: pulseIn(pingPin, HIGH);
so I changed it to LOW, and that was the problem.
So my question is if anybody can help me on what I can do or how my code should be inorder to see if the receiver, receives anything.
Best regards
I would start by removing the call to pulseIn(). That waits until the pin goes LOW and waits for the next HIGH pulse. It returns the length (in microseconds) of the HIGH pulse. If no pulse is seen in 1 second it returns 0. Since you don't use the return value there is no good reason to call that function.
Thanks John.
I tried a normal ping send / receive code and it showed the distance fine in the serial monitor, so now I know it works!
I also got my Roomba encoders working now (posted in another thread) so now I have a Roomba driven by my arduino and a H-bridge, and I would like to use the ultrasonic transceiver to make it following me.
But I dont know where to start or end with the programming part...
some parameters to follow:
It needs to stop when the distance from the transmitter to the receiver is < 40 cm
And speed up a bit more if the distance is greater than 120 cm
Probably always stay a distance around 80 cm from the transmitter to the receiver.
how do I make a program like that.
I dont understand if I can use the data which is showed in the serial monitor or if I have to do it a totally different way.. Im a bit confused..
As I understand it reads the signal every 0.5 second. I would know if the signal is strong or poor by reading the voltage the receiver gets right?, through the analog pin or should this be approach in another way?
and the data I get from the ultrasonic transceiver how should I convert it to make the motors move in general??
Best regards