Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can someone help me debug why this is not giving my motor any movement. #include Servo servo1; //Motor1 int PUL = 4; // define pin

Can someone help me debug why this is not giving my motor any movement.
#include
Servo servo1;
//Motor1
int PUL = 4; // define pin pulse
int DIR = 3; // define Direction pin
int ENA = 2; // define Enable Pin
//Motor2
int PUL2 = 7; // define pin pulse
int DIR2 = 6; // define Direction pin
int ENA2 = 5; // define Enable Pin
//#include "Ultrasonic.h"
int trigPin = 8;
int echoPin = 9;
//Ultrasonic ultrasound (trigPin, echoPin);
int dis = 20;
int distance;
int pinServo = 10; // Digital pin with PWM for the Servo
int pulseMin = 650; // Pulse in us to rotate an angle of 0
int pulseMax = 255; // Pulse in us to rotate a 180 angle
int angle = 0; // Variable to save the angle of the servo
int from = 0;
int to = 120;
int step = 1;
int ledrele = 11;
void setup () {
servo1.attach (pinServo, pulseMin, pulseMax);
pinMode (trigPin, OUTPUT);
pinMode (echoPin, INPUT);
pinMode (PUL, OUTPUT);
pinMode (DIR, OUTPUT);
pinMode (ENA, OUTPUT);
pinMode (PUL2, OUTPUT);
pinMode (DIR2, OUTPUT);
pinMode (ENA2, OUTPUT);
pinMode (ledrele, OUTPUT);
digitalWrite (ledrele, LOW);
}
void loop () {
angle += step;
servo1.write (angle);
delay (15);
if (angle >= 120) {
step = -1;
from = 120;
// up = 0;
}
if (angle == 0) {
step = 1;
from = 0;
to = 120;
}
// distance = ultrasound.Ranging (CM);
if (distance
advance();
} else {
stop();
}
}
void advance() {
digitalWrite (DIR, HIGH);
digitalWrite (ENA, HIGH);
digitalWrite (PUL, HIGH);
delayMicroseconds (50);
digitalWrite (PUL, LOW);
delayMicroseconds (50);
digitalWrite (DIR2, LOW);
digitalWrite (ENA2, HIGH);
digitalWrite (PUL2, HIGH);
delayMicroseconds (50);
digitalWrite (PUL2, LOW);
delayMicroseconds (50);
}
void stop () {
digitalWrite (DIR, LOW);
digitalWrite (ENA, HIGH);
digitalWrite (PUL, HIGH);
delayMicroseconds (50);
digitalWrite (PUL, LOW);
delayMicroseconds (50);
digitalWrite (DIR2, HIGH);
digitalWrite (ENA2, HIGH);
digitalWrite (PUL2, HIGH);
delayMicroseconds (50);
digitalWrite (PUL2, LOW);
delayMicroseconds (50);
}

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

Step: 3

blur-text-image

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

Databases Illuminated

Authors: Catherine M Ricardo, Susan D Urban

3rd Edition

1284056945, 9781284056945

More Books

Students also viewed these Databases questions

Question

2. Are there more men or women? (find statistics)

Answered: 1 week ago

Question

understand how design and writing connect in mass communication.

Answered: 1 week ago

Question

Who is the audience?

Answered: 1 week ago