All the tutorials I found to make this work were based on 4 pin sensors, for example the "Ultrasonic Ranging Module HC-SR04" which are the most commonly used, it is connected like this:
Sensor Pin 1 (Gnd) –> Arduino Ground
Sensor Pin 2 (Echo) –> Arduino Pin 11
Sensor Pin 3 (Trig) –> Arduino Pin 12
Sensor Pin 4 (Vcc) –> Arduino +5V
But mine has 3 Pins, SIG, VCC and GND
I tried following two of arduino's tutorials, Serial Input- From the "Liquid Crystal" Library, and the "Ping Ultrasonic Range Finder" from "Examples" http://arduino.cc/en/Tutorial/Ping?from=Tutorial.UltrasoundSensor
Both codes individually work great with the lcd display and the sensor.
So I tried putting them together, so that the lcd display would read the input from the sensor in the serial monitor and display it. But even if it doesnt show an "error" message, my code wont work.
```
*// include the library code:
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
//Liquid crystal
// this constant won't change. It's the pin number
// of the sensor's output:
const int pingPin = 7;
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// initialize the serial communications:
Serial.begin(9600);
}
void loop()
{
// establish variables for duration of the ping,
// and the distance result in inches and centimeters:
long duration, inches, cm;
// The PING))) is triggered by a HIGH pulse of 2 or more microseconds.
// Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
pinMode(pingPin, OUTPUT);
digitalWrite(pingPin, LOW);
delayMicroseconds(2);
digitalWrite(pingPin, HIGH);
delayMicroseconds(5);
digitalWrite(pingPin, LOW);
// The same pin is used to read the signal from the PING))): a HIGH
// pulse whose duration is the time (in microseconds) from the sending
// of the ping to the reception of its echo off of an object.
pinMode(pingPin, INPUT);
duration = pulseIn(pingPin, 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)
{
// According to Parallax's datasheet for the PING))), there are
// 73.746 microseconds per inch (i.e. sound travels at 1130 feet per
// second). This gives the distance travelled by the ping, outbound
// and return, so we divide by 2 to get the distance of the obstacle.
return microseconds / 74 / 2;
}
long microsecondsToCentimeters(long microseconds)
{
// The speed of sound is 340 m/s or 29 microseconds per centimeter.
// The ping travels out and back, so to find the distance of the
// object we take half of the distance travelled.
return microseconds / 29 / 2;
// when characters arrive over the serial port...
if (Serial.available()) {
// wait a bit for the entire message to arrive
delay(100);
// clear the screen
lcd.clear();
// read all the available characters
while (Serial.available() > 0) {
// display each character to the LCD
lcd.write(Serial.read());
}
}
}
}*
```
What am I doing wrong?