I was trying to use my ultra-sonic sensor that worked until I have applied heat to the metal cylinder part as I was sticking the sensor to a frame with hot glue gun. It's been a week or so since I have applied heat to the sensor, so I don't know whether if the sensor is broken due to heat. I have used lots of programs that were on internet, such as the programs that I'm uploading. Anyways, one of the program is the one that I used before and worked perfectly. There is no clicking sound (there was one when my sensor was working) and it only shows 0cm all the time.
NewPing example = http://forum.arduino.cc/index.php/topic,106043.0.html
long duration, distance;
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration / 2) / 29.1;
#include <LiquidCrystal_I2C.h> //Load Liquid Crystal Library
LiquidCrystal_I2C lcd(0x27, 16, 2); //Create Liquid Crystal Object called LCD
int trigPin=41; //Sensor Trip pin connected to Arduino pin 13
int echoPin=39; //Sensor Echo pin connected to Arduino pin 11
int myCounter=0; //declare your variable myCounter and set to 0
int servoControlPin=6; //Servo control line is connected to pin 6
float pingTime; //time for ping to travel from sensor to target and return
float targetDistance; //Distance to Target in inches
float speedOfSound=776.5; //Speed of sound in miles per hour when temp is 77 degrees.
void setup() {
Serial.begin(9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
lcd.init();
lcd.backlight();
lcd.setCursor(0,0); //Set LCD cursor to upper left corner, column 0, row 0
lcd.print("Target Distance:"); //Print Message on First Row
}
void loop() {
digitalWrite(trigPin, LOW); //Set trigger pin low
delayMicroseconds(2000); //Let signal settle
digitalWrite(trigPin, HIGH); //Set trigPin high
delayMicroseconds(15); //Delay in high state
digitalWrite(trigPin, LOW); //ping has now been sent
delayMicroseconds(10); //Delay in high state
pingTime = pulseIn(echoPin, HIGH); //pingTime is presented in microceconds
pingTime=pingTime/1000000; //convert pingTime to seconds by dividing by 1000000 (microseconds in a second)
pingTime=pingTime/3600; //convert pingtime to hourse by dividing by 3600 (seconds in an hour)
targetDistance= speedOfSound * pingTime; //This will be in miles, since speed of sound was miles per hour
targetDistance=targetDistance/2; //Remember ping travels to target and back from target, so you must divide by 2 for actual target distance.
targetDistance= targetDistance*63360; //Convert miles to inches by multipling by 63360 (inches per mile)
lcd.setCursor(0,1); //Set cursor to first column of second row
lcd.print(" "); //Print blanks to clear the row
lcd.setCursor(0,1); //Set Cursor again to first column of second row
lcd.print(targetDistance); //Print measured distance
lcd.print(" inches"); //Print your units.
delay(250); //pause to let things settle
}