The ultrasonic sensor sends a pulse, and receives an echo. The Arduino measures the time it takes for the echo pin to go high. The pin used to send the pulse just needs to be toggled on then off, after a tiny delay. The pin that receives the echo is set HIGH when the echo arrives. Any digital pin can be used for the pulse pin and any digital pin can be used for the echo pin.
Any analog pin can be used as a digital pin, too. On most Arduinos, anyway.
The pulseIn() function takes, as the first argument, a pin number. Why you are waiting for pin 0 or pin 1 to go high, when the sensor is connected to pin A1, is a real mystery.
Why you are trying to PWM the analog pins is a mystery.
The ONLY thing that you should have changed in the ping example is the pin numbers.
You have answered the hardware question. The Arduino is an Arduino Nano. You have also shown pictures of an "Expansion Board" that appears to be designed for a two-wheel robot.
There was a second question that you did not answer:
johnwasser:
What sketch is running on that Arduino?
johnwasser:
You have answered the hardware question. The Arduino is an Arduino Nano. You have also shown pictures of an "Expansion Board" that appears to be designed for a two-wheel robot.
There was a second question that you did not answer:Please answer that question.
official has give me Quadcopter code,
so i just need to make the Ultrasonic sensors work,
final i want to make Quadcopter flying and automatic obstacle avoidance,
but now i just want Ultrasonic sensors work on Quadcopter,
I have successfully used 2 digital pins to drive servo motors for my quadroped spider robot and connected those pins to my HC-SR04 sonar as well. However, you have to change the echo pin back to an output state before you return from the sonar function, if that digital pin is being used as an output.