Answered step by step
Verified Expert Solution
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started