loading

In this instructable, I will show you how to combine a ultrasonic sensor (HC-SR04) with a Linkit one to make a distance measuring device. This device can measure a maximum rage of up to 2 meters, this is really fun project to design. You can use this instructable to design a ultrasonic robot using the Linkit One and maybe I will put up an instructable on how to make a robot.

Step 1: Components

Here is a list of all the components required to get started, make sure you collect all the components first before proceeding to other steps-

Ultrasonic distance Module (HC-SR04)

Breadbaord

Wires

Battery

Step 2: Schematics

Here is how the connections go from the linkit one to the HC SR04 -

HC SR04 Gnd pin to Linkit One Gnd

HC SR04 VCC pin to Linkit One +5V

HC SR04 Trig pin to Linkit One Digital pin 8

HC SR04 Echo pin to Linkit One Digital pin 7

Step 3: Code

The code can be found below.

To upload the program you need to install the Linkit one plugin along with the arduino IDE. You can find instructions on how to do that in the official website. You can also download the IDE with the Linkit One plugin pre-installed from GitHub.

#include
/* Tested with HY-SRF05, HC-SR04 Assuming a room temp of 20 degrees centigrade The circuit: * VVC connection of the sensor attached to +5V * GND connection of the sensor attached to ground * TRIG connection of the sensor attached to digital pin 12 * ECHO connection of the sensor attached to digital pin 13 */ const int TRIG_PIN = 8; const int ECHO_PIN = 9; void setup() { // initialize serial communication: Serial.begin(9600); pinMode(TRIG_PIN,OUTPUT); pinMode(ECHO_PIN,INPUT); } void loop() { long duration, distanceCm, distanceIn; // Give a short LOW pulse beforehand to ensure a clean HIGH pulse: digitalWrite(TRIG_PIN, LOW); delayMicroseconds(2); digitalWrite(TRIG_PIN, HIGH); delayMicroseconds(10); digitalWrite(TRIG_PIN, LOW); duration = pulseIn(ECHO_PIN,HIGH); // convert the time into a distance distanceCm = duration / 29.1 / 2 ; distanceIn = duration / 74 / 2; if (distanceCm <= 0 || distanceCm > 600){ Serial.println("Out of range"); } else { Serial.print(distanceIn); Serial.print("in, "); Serial.print(distanceCm); Serial.print("cm"); Serial.println(); } delay(1000); }

Step 4: Testing

After uploading the code, you need to open up a serial monitor on the right port and you should see a stream of distance data being displayed on the monitor. You can use this data to design a robot or an electronic distance measuring tape, let me know what you make using this module.

<p>Great!<br>however please correct suggested connections to match your code, in these 3 lines:<br>HC SR04 Echo pin to Linkit One Digital pin 7 <strong>-&gt; 9</strong></p><p>* TRIG connection of the sensor attached to digital pin <strong>12 -&gt;8</strong></p><p> * ECHO connection of the sensor attached to digital pin <strong>13 -&gt;9</strong></p><p>Thanks!</p>

About This Instructable

1,428views

33favorites

License:

More by ImGokul:Serial Communication - Arduino and Linkit One Linkit One Temperature Sensor  Linkit One Motion Sensor  
Add instructable to: