Arduino code:
#include <Servo.h> //servo library
Servo servo;
int trigPin = 5;
int echoPin = 6;
int servoPin = 7;
int led= 10;
long duration, dist, average;
long aver[3]; //array for average
void setup() {
Serial.begin(9600);
servo.attach(servoPin);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
servo.write(0); //close cap on power on
delay(100);
servo.detach();
}
void measure() {
digitalWrite(10,HIGH);
digitalWrite(trigPin, LOW);
delayMicroseconds(5);
digitalWrite(trigPin, HIGH);
delayMicroseconds(15);
digitalWrite(trigPin, LOW);
pinMode(echoPin, INPUT);
duration = pulseIn(echoPin, HIGH);
dist = (duration/2) / 29.1; //obtain distance
}
void loop() {
for (int i=0;i<=2;i++) { //average distance
measure();
aver[i]=dist;
delay(10); //delay between measurements
}
dist=(aver[0]+aver[1]+aver[2])/3;
if ( dist<50 ) {
//Change distance as per your need
servo.attach(servoPin);
delay(1);
servo.write(0);
delay(3000);
servo.write(150);
delay(1000);
servo.detach();
}
Serial.print(dist);
}
19 Comments
Thanks a lot
ReplyDeleteBro call me plsss help me
ReplyDeleteYes tell me
DeleteGive me you phone number
Deletethanks a lot
ReplyDeleteBattery kaha connect karenge sir
ReplyDeleteBro please call me
ReplyDeleteToday
ReplyDeleteYe coding kaha hogi sir??
ReplyDeleteArduino Name ke software me hogi coding
DeleteSendor kaise computer se connect hoga??
ReplyDeleteCl me 6006385894,I want to know something from you if you don't mind
ReplyDeleteBhai ye programming upload nhi ho rahi h
ReplyDeleteTo bhai bataye kya kre
ReplyDeleteSir give me ppt
ReplyDeleteGood afternoon sir .
ReplyDeletePlease , sir, I want to use your project for my final year project work.
Can you direct me on how to get write up.?
Thank you 🙏
Send me writeup on 8102558848...thanks in advance
DeletePlease sir give me number
ReplyDeleteSir meri help kardo please sir mere arduino uno board me code upload ni ho rha hai
ReplyDeleteSir aap is project ke liye code upload karte hue ek video bana dijiye
Code phone se upload karna hai