Ultrosonic Code
Ultrosonic Code
Technical Specifications
Procedure:
Step 1. Open the Arduino IDE software on your computer. Coding in the Arduino language will
control your circuit. Open a new sketch File by clicking New.
Step 2. The Ultrasonic sensor has four terminals - +5V, Trigger, Echo, and GND connected
as follows
1. Connect the +5V pin of ultrasonic sensor to +5v on your Arduino board.
2. Connect Trigger to digital pin 9 on your Arduino board.
3. Connect Echo to digital pin 10 on your Arduino board.
4. Connect GND with GND on Arduino.
void setup() {
Serial.begin(9600);
pinMode (trigPin, OUTPUT);
pinMode (echoPin, INPUT);
// put your setup code here, to run once:
void loop() {
digitalWrite (trigPin, LOW);
delay(2);
digitalWrite (trigPin, HIGH);
delay(10);
digitalWrite (trigPin, LOW);
}
Description of the Command:
Conclusion:
You will see the distance measured by sensor in cm on Arduino serial monitor.