saksham20201
Published © GPL3+

Servoradar

This project's name is Servoradar as you know it is a radar so it is used to detect the object and then display it in the serial monitor.

IntermediateFull instructions provided5,084
Servoradar

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1
SG90 Micro-servo motor
SG90 Micro-servo motor
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Breadboard (generic)
Breadboard (generic)
×1

Story

Read more

Schematics

circuit and diagram

connect the following

Sensor Arduino
VCC - 5V
trigpin - 8
echopin - 11
gnd - gnd

servo Arduino

positive pin - 5V
negative pin - gnd
pin - 3

please follow the above

Code

servoradar code

Arduino
the diagram may differ a bit from the code so please try following the code
#include <Servo.h>


Servo myservo;
int Ang = 0;
long duration;
int  distance;
const int trigpin = 8;
const int echopin = 11;

void setup() {


  Serial.begin(9600);
  myservo.attach(3);
  pinMode(trigpin, OUTPUT);
  pinMode(echopin, INPUT);

}

void loop() {

  for (Ang = 0; Ang <= 180; Ang += 1) {
    myservo.write(Ang);
    delay(15);



  } for (Ang = 180; Ang >= 0; Ang -= 1) {
    myservo.write(Ang);
    delay(200);


    digitalWrite(trigpin, LOW);
    delayMicroseconds(2);
    digitalWrite(trigpin, HIGH);
    delayMicroseconds(15);
    digitalWrite(trigpin, LOW);



    duration = pulseIn(echopin, HIGH);
    distance = duration * 0.034 / 2;



    Serial.println("Distance");
    Serial.println(distance);
    Serial.println("Angle");
    Serial.println(Ang);

    if (distance <= 10)
      Serial.println("object detected");







  }
}

Credits

saksham20201
0 projects • 1 follower

Comments