Make a Distance Meter

1,199

14

1

Posted

Introduction: Make a Distance Meter

In this instructable, I have shown How to make Distance meter with Ultrasonic Sensor and Arduino nano.

Step 2: Material Required

1. Plastic Box

2. Arduino Nano

3. Ultrasonic Sensor (HC-SR04)

4. Servo Motor

5. Vero Board

6. Battery

7. Switch

9. Wire

Step 3: Make the Circuit Board

Make the circuit board as per this circuit diagram.

Step 4: Arduino Code

#define echoPin 6
#define trigPin 7

#include Servo myservo;

void setup()

{

Serial.begin(9600);

pinMode(trigPin, OUTPUT);

pinMode(echoPin, INPUT);

myservo.attach(9);

myservo.write(180);

}

void loop()

{

float distance, duration;

digitalWrite(trigPin , HIGH);

delayMicroseconds(100);

digitalWrite(trigPin, LOW);

duration = pulseIn(echoPin, HIGH);

distance= (((duration/2)/29.1/100)*39.37);

int angle = map( distance, 0,12,180,0);

myservo.write(angle);

/*Serial.print("Distance is"); /////////////////////////////////////////////////////

Serial.print(distance); //////Use this section to check///////

Serial.println("in"); //////every thing is ok//////////////////////

Serial.flush(); ///////////////////////////////////////////////////////

delay(1000);*/

}

Step 5: Cut the Edge of Plastic Box

Cut all the extra edges of your plastic box.

Step 6: Make Some Hole

Make some hole as per your circuit board dimension for your switch, charging port and also for ultrasonic sensor.

And also make some hole on the circuit board for fixing the board with plastic box.

Step 8: Make a Arrow and Fix Servo

Make an arrow with the cardboard. And fix the servo with glue on the plastic box's front case.

Step 10: Like and Subscribe

If you like this instructable.

Recommendations

• Arduino Class

68,082 Enrolled

• Science of Cooking

We have a be nice policy.