Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
13 views3 pages

Google Drive Data

The document contains an Arduino code that utilizes a servo motor and an ultrasonic sensor to measure distance. When the distance is less than 10 cm, the servo moves to 90 degrees; otherwise, it returns to 0 degrees. Additionally, it prints the distance measured to the serial monitor, with specific messages for distances less than 5 cm and greater than 40 cm.

Uploaded by

poonamsonij103
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views3 pages

Google Drive Data

The document contains an Arduino code that utilizes a servo motor and an ultrasonic sensor to measure distance. When the distance is less than 10 cm, the servo moves to 90 degrees; otherwise, it returns to 0 degrees. Additionally, it prints the distance measured to the serial monitor, with specific messages for distances less than 5 cm and greater than 40 cm.

Uploaded by

poonamsonij103
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

#include <Servo.h> //IMPOTENT POINT ADD servo.

h LIBRARYY

#define trigPin 3

#define echoPin 2

Servo servo;

int sound = 250;

void setup() {

Serial.begin (9600);

pinMode(trigPin, OUTPUT);

pinMode(echoPin, INPUT);

servo.attach(4); // conect sevro pin 6

void loop() {

long duration, distance;

digitalWrite(trigPin, LOW);

delayMicroseconds(2);

digitalWrite(trigPin, HIGH);

delayMicroseconds(10);

digitalWrite(trigPin, LOW);

duration = pulseIn(echoPin, HIGH);

distance = (duration/2) / 29.1;

if (distance < 10) {

Serial.println("the distance is less than 5");

servo.write(90);

else {

servo.write(0);

}
if (distance > 40 || distance <= 0){

Serial.println("The distance is more than 60");

else {

Serial.print(distance);

Serial.println(" cm");

delay(500);

CIRCUIT DIAGRAM

You might also like