Arduino Ping Sensor Connection Question

Hi guys so i got the HC-SR04 Ping sensor which has four pins now I have the arduino mega 2580 with the mega sensor shield V4. My question is where in the sensor shield would I hook up the sensor because all the slots are three pin slots exept for the front 4 pin but they read "COM1 , COM2 ...etc would it go here? and in the code how would I name it to read in order to get a propper reading ( digital.Read COM1 ) this doesnt sound right to me. Has anyone else had this problem connecting their Ping sensor to the sensor shield???

like this? ? the trigger pin and echo pin both need to go to a digital pin. so bring out two digital pins from the mega sensor board(since it doesn’t have any correctly laid out for this sensor) to a bread board, one of theses to the trigger pin, one to the echo. then + to VCC and - to GND of the ping sensor. finally set the echo and trigger pins in the code below to the pins you connected them to on the arduino.

see how i did it here: Digitalduino: Ultrasonic Theremin basically what you need:

#define trig 7 //trigger pin on sonar module
#define echo 6 //echo pin

int dist; //how far the object is away from the module(cm)
int valueSensor = 0; //see here, just added this line

void setup()
  pinMode(echo, INPUT);
  pinMode(trig, OUTPUT);

void loop()
  //send a trigger signal
  digitalWrite(trig, HIGH);
  digitalWrite(trig, LOW);
  //receive the trigger signal echo, and calculate cm to the object
  valueSensor= pulseIn(echo, HIGH);
  dist= valueSensor/58; //converts raw to cm, valueSensor/74/2 = inches

it says valueSensor was not declared in this scope??

Why does it say that?
Because you haven’t told the compiler what type “valueSensor” is

look at code now, it should work notice the line i added at top :slight_smile:

It works Great Now Thanks!!! It still sucks that the sensor takes 2 pins!! but i guess for the price I cant complain does anyone know of a cheap 3 pinned one??