Welcome Guest | RSS


Sunday, 2019-06-16, 11:31 AM

Ultrasonic Measuring Device:

(for information on this sensor, click 
Things needed:-
1) Arduino
2) Ultrasonic Sensor(in this project HC SR04 model is used)


There are 4 pins on this Ultrasonic sensor.
Connect VCC        to arduino 5V
               GND        to arduino GND
               ECHO      to arduino pin 12
               TRIGGER  to arduino pin 13

[Note:- These sensor pins arrangement is for HC SR04 model. The pins may vary for some models.]


 HC-SR04 Ping distance sensor]
 VCC to arduino 5v GND to arduino GND
 Echo to Arduino pin 13 Trig to Arduino pin 12
 More info at: http://inlovetech.ucoz.com

#define trigPin 13
#define echoPin 12

void setup() {
  Serial.begin (9600);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);

void loop() {
  long duration, distance;
  digitalWrite(trigPin, LOW);  // Added this line
  delayMicroseconds(2); // Added this line

  digitalWrite(trigPin, HIGH);
//  delayMicroseconds(1000); - Removed this line
  delayMicroseconds(10); // Added this line
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance = (duration/2) / 29.1;
  if (distance >= 200 || distance <= 0){
    Serial.println("Out of range");
  else {
    Serial.println(" cm");