Anjali Shaw
Published

Servo motor + ultrasonic sensor

let's break the corona chain without touching the handwash container. I want you guys to look in this project for something exciting.

IntermediateFull instructions provided1 hour60,257
Servo motor + ultrasonic sensor

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Breadboard (generic)
Breadboard (generic)
×1
Female/Female Jumper Wires
Female/Female Jumper Wires
×1
Male/Female Jumper Wires
Male/Female Jumper Wires
×1
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1
SG90 Micro-servo motor
SG90 Micro-servo motor
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

schematic representation

I have'nt shown the part to include the handwash top.I want you guys to do that.Here,is the hint if you suffer any problem kindly ping me up.
HINT:attach the servo's rotating part to hand wash's top via string or thick thread(able to bear some tension.)

Code

project code

Arduino
you have to make the connections as per code.
attach the trig and echo pin of ultrasonic sensor to the pin 8 and 9 respectively.
I would like to suggest you guys that you should write the code and must not just copy paste it.
#include<Servo.h>
int trig=8;
int echo=9;
int dt=10;
Servo servo;

//int distance,duration;
void setup() {
  // put your setup code here, to run once:
pinMode(trig,OUTPUT);
pinMode(echo,INPUT);
Serial.begin(9600);
servo.attach(11);
}

void loop() {
  // put your main code here, to run repeatedly:


if (calc_dis()<10)
{
  for (int i=0;i<=540;i++)
  {
    servo.write(i);
    delay(1);
  }
  delay(100);
  for (int i=540;i>=0;i--)
  {
    servo.write(i);
    delay(1);
  }
  delay(100);
}
}

//This code is written to calculate the DISTANCE using ULTRASONIC SENSOR

int calc_dis()
{
  int duration,distance;
  digitalWrite(trig,HIGH);
  delay(dt);
  digitalWrite(trig,LOW);
  duration=pulseIn(echo,HIGH);
  distance = (duration/2) / 29.1;
  return distance;
}

Credits

Anjali Shaw

Anjali Shaw

10 projects • 7 followers

Comments