Created
October 24, 2012 11:51
-
-
Save buildcircuit/3945670 to your computer and use it in GitHub Desktop.
Ultrasonic range finder using Amarino Evaluation shield
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <LiquidCrystal.h> | |
LiquidCrystal lcd(13, 12, 10, 9, 8, 7); | |
int TrigPin = 4; | |
int EchoPin = 2; | |
void setup() | |
{ | |
lcd.begin(16, 2); | |
Serial.begin(9600); | |
pinMode(TrigPin,OUTPUT); | |
pinMode(EchoPin,INPUT); | |
} | |
void loop() | |
{ | |
int distance,duration; | |
digitalWrite(TrigPin,HIGH);//TrigPin prepare high of more than 10us | |
delayMicroseconds(11); | |
digitalWrite(TrigPin,LOW); | |
duration = pulseIn(EchoPin, HIGH);//EchoPin received high start counting until the receiver to the low,return to the count valu | |
duration = duration/29/2;//Calculating the distance cm | |
// The speed of sound is 340 m/s or 29 microseconds per centimeter. | |
lcd.clear(); | |
lcd.print("Distance:"); | |
lcd.print(duration); | |
Serial.print(duration);//Serial display distance | |
lcd.print("cm"); | |
Serial.print("cm"); | |
Serial.println(); | |
delay(1000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment