Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#include Servo servoM; #define trig 6 #define echo 7 #define revleft 8 #define fwdleft 9 #define revright 12 #define fwdright 13 #define Ae 10 #define

#include
Servo servoM;
#define trig 6
#define echo 7
#define revleft 8
#define fwdleft 9
#define revright 12
#define fwdright 13
#define Ae 10
#define Be 11
int time;
int distance;
void setup()
{
Serial.begin(9600);
pinMode(echo,INPUT);
pinMode(trig,OUTPUT);
pinMode(revleft,OUTPUT);
pinMode(fwdleft,OUTPUT);
pinMode(revright,OUTPUT);
pinMode(fwdright,OUTPUT);
servoM.attach(3);
servoM.attach(90);
delay(100);
analogWrite(Ae,220);
analogWrite(Be,220);
// put your setup code here, to run once:
}
void loop() {
digitalWrite(trig,LOW);
delayMicroseconds(2);
digitalWrite(trig,HIGH);
delayMicroseconds(10);
time = pulseIn(echo,HIGH);
distance=time/58.2;
delay(10);
if(distance>20)
{
digitalWrite(revleft,LOW);
digitalWrite(revright,LOW);
digitalWrite(fwdleft,HIGH);
digitalWrite(fwdright,HIGH);
}
if(distance<20)
{
digitalWrite(revleft,LOW);
digitalWrite(revright,LOW);
digitalWrite(fwdleft,LOW);
digitalWrite(fwdright,LOW);
delay(500);
digitalWrite(revleft,HIGH);
digitalWrite(revright,HIGH);
digitalWrite(fwdleft,LOW);
digitalWrite(fwdright,LOW);
delay(1000);
digitalWrite(revleft,LOW);
digitalWrite(revright,LOW);
digitalWrite(fwdleft,LOW);
digitalWrite(fwdright,LOW);
delay(500);
digitalWrite(revleft,LOW);
digitalWrite(revright,LOW);
digitalWrite(revright,LOW);
digitalWrite(fwdleft,LOW);
digitalWrite(fwdright,HIGH);
delay(500);
}
}
Complete the obstacle avoiding arduino robot car.
*Include the servo motor code in the code given below.* (*Code to run the servo motor*)
The car has ( 2 dc motors, 1 servo motor, 1 ultrasonic sensor)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

PostgreSQL Up And Running A Practical Guide To The Advanced Open Source Database

Authors: Regina Obe, Leo Hsu

3rd Edition

1491963417, 978-1491963418

More Books

Students also viewed these Databases questions

Question

Explain the process of MBO

Answered: 1 week ago