Introduction: Sensor Tutorial HC-SR04 Linkit One

Picture of Sensor Tutorial HC-SR04 Linkit One

In this tutorial I will make a simple project using hc-sr04 and linkit one board giving you an idea about using it.The L.E.D glows whenever an object comes in between the specified distance.Her is a video of it working:-

Step 1: Things Requires

Picture of Things Requires

We need :-

  1. Linkit one board
  2. Jumper wires
  3. Hc-Sr04 ultrasonic distance sensor
  4. Battery
  5. USB cord
  6. L.E.D

Step 2: Pin Configuration

Picture of Pin Configuration

Insert all jumper wires one by one in the 4 pins of sensor,2 terminals of L.E.D .

  1. Connect -ve terminal of L.E.D to gnd
  2. Connect +ve terminal of L.E.D to digital pin
  3. echo to 12
  4. trig to 13
  5. vcc to +5
  6. gnd to gnd

Step 3: Code

Picture of Code

#define trigPin 13

#define echoPin 12 #define led 11

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

}

void loop() { 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; if (distance < 50) { digitalWrite(led,HIGH);

}else { digitalWrite(led,LOW); } if (distance >= 200 || distance <= 0){ Serial.println("Out of range"); } else { Serial.print(distance); Serial.println(" cm"); } delay(800); }

Step 4: Done!

Picture of Done!

I hope this will help you to understand and modify the code to make more interesting instructables using the

Comments

washingtonj84 (author)2015-11-21

Thank you, exactly what I need.

DIY Hacks and How Tos (author)2015-11-07

Great tutorial. Thanks for sharing.

About This Instructable

745views

13favorites

License:

Bio: Thank you instructables!!
More by Gursimran Singh 425:Plant BoxDIY CNC For 60$ (Large Work Area)Advanced Mosquito Repeller and Swatter
Add instructable to: