Make a Distance Meter
In this instructable, I have shown How to make Distance meter with Ultrasonic Sensor and Arduino nano.
How to Make Distance Meter
Material Required
1. Plastic Box
2. Arduino Nano
3. Ultrasonic Sensor (HC-SR04)
4. Servo Motor
5. Vero Board
6. Battery
7. Switch
8. Header Pins
9. Wire
Make the Circuit Board
Make the circuit board as per this circuit diagram.
Arduino Code
Download the code from the link
#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);*/
}
Downloads
Cut the Edge of Plastic Box
Cut all the extra edges of your plastic box.
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.
Download the Scale
Download this image for scaling.
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.
Assemble
Like and Subscribe
If you like this instructable.
Please like it and also subscribe my youtube
www.youtube.com/c/yobots