Getting started with a 4 pin Ping Sensor, HC-SR04
I hadn't seen any tutorials on a 4 pin HC-SR04 ping sensor for use with a Parallax P8X32A, so I thought I'd give some starter info for people new to this.
I basically looked at the code for the 3 pin ping in the Simple Libraries and tweaked it a bit, here it is.
I basically looked at the code for the 3 pin ping in the Simple Libraries and tweaked it a bit, here it is.
#include "simpletools.h" int main(void){ while(1){ float i = -1; i = ping(10,11); print("%f\n", i/148); //divide the ping by 148 to get inches, or by 54 to get centimeters pause(300); } } int ping(int trig, int echo)//trig is trigger pin, echo is echo pin { low(trig);//set trig low for start pulse low(echo);//set echo low to be safe pulse_out(trig, 10);//send the minimum 10 ms pulse on trig to start a ping return pulse_in(echo, 1);//get the pulse duration back on echo pin }
Comments
Thanks for the code. This will help out others with the same hardware..
Thanks,
Dom..