Go Down

Topic: ping transmitter and receiver (Read 1 time) previous topic - next topic

Ahmed50mx

Apr 18, 2013, 06:58 am Last Edit: Apr 18, 2013, 10:09 am by Ahmed50mx Reason: 1
hi everyone.
in my project I need to build a ping ultrasonic transmitter and use another ping sensor to receive that signal,to test that method I removed the emitter from one of the pings and the receive from the other one,and I modified the arduino ping example sketch to test it,so one of pings will send the signal and the other one receive it . but that didn't work ,what kind of method should I use
here is the code

Code: [Select]
const int pingPin1 = 7;
const int pingPin2 = 8;

void setup() {

 Serial.begin(9600);
}

void loop()
{
 
 long duration, inches, cm;

 pinMode(pingPin1, OUTPUT);
 digitalWrite(pingPin1, LOW);
 delayMicroseconds(2);
 digitalWrite(pingPin1, HIGH);
 delayMicroseconds(5);
 digitalWrite(pingPin1, LOW);

 
 

 
 pinMode(pingPin2, INPUT);
 duration = pulseIn(pingPin2, HIGH);
 // convert the time into a distance
 inches = microsecondsToInches(duration);
 cm = microsecondsToCentimeters(duration);
 
 Serial.print(inches);
 Serial.print("in, ");
 Serial.print(cm);
 Serial.print("cm");
 Serial.println();
 
 delay(100);
}

long microsecondsToInches(long microseconds)
{
 return microseconds / 74 / 2;
}

long microsecondsToCentimeters(long microseconds)
{
 return microseconds / 29 / 2;
}

AWOL

Quote
but that didn't work

But what did it do?

My guess is the receiver didn't listen, because it didn't get a trigger pulse to transmit.

Please use code tags when posting code.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.
I speak for myself, not Arduino.

Ahmed50mx


Quote
but that didn't work

But what did it do?

My guess is the receiver didn't listen, because it didn't get a trigger pulse to transmit.

yes ,by using the serial monitor it shows that it didn't read the ultrasonic signal(it shows 0cm,0inch),and I am using the same arduino uno for both pings

I am sorry but I don't know how to use the code tags

AWOL

Quote
it shows that it didn't read the ultrasonic signal

So, trigger the receiver when you trigger the transmitter.


Quote
I am sorry but I don't know how to use the code tags
It is explained here, at the top of this section, in bold
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.
I speak for myself, not Arduino.

Ahmed50mx


Quote
it shows that it didn't read the ultrasonic signal

So, trigger the receiver when you trigger the transmitter.

sorry to bother you again sir but I am still a beginner in using the arduino and sensors in general,so how can I trigger them both at the same time

AWOL

You're triggering one now, so all you need to do is insert the same sequence of pinMode and digitalWrite for the second sensor pin.

You can go back and edit previous posts by clicking on "Modify", then add the code tags, then click on "save".
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.
I speak for myself, not Arduino.

Go Up