Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. Write an Arduino program that controls a DC MotorMust include a function that

ID: 3869722 • Letter: 1

Question

1. Write an Arduino program that controls a DC MotorMust include a function that sets the direction of the motor and speed Input Arguments: int Direction, int Speed Program should read from the serial port Receiving value ‘0’ sets the motor speed to 0 Receiving value ‘9’ sets the motor speed to 255 Values ‘1’ – ‘8’ are equally spaced speeds between 0 - 255 Receiving ‘F’ sets the motor direction to FORWARD Receiving ‘R’ sets the motor direction to REVERSE

2. Write an Arduino program that ramps up and ramps down the speed of the continuous servo Must include a function that sets the speed and direction of the servo Motor should increase speed from stopped to maximum in 5 seconds

3. Write an Arduino program that moves the position servo in 10 degree increments through its entire range of motion. Must include a function that accepts the desired angle as an input argument and sends the appropriate command Pause at each angle for 0.5 seconds Write an Arduino program that combines questions 1-3.

Thanks!

Explanation / Answer

Let us assume that you have 2 push buttons each connected to a pin on arduino. Now each button represents the direction of the dc motor.

void setup()

{

Serial.begin(9600);

int motorPin1=15;

int motorPin2=16;

int buttonpin=14;

pinMode(buttonpin,INPUT);

pinMode(motorPin1,OUTPUT);

pinMode(motorPin2,OUTPUT);}

void loop()

{

if(Serial.available()>0)

{

int speed=Serial.read();

}

int direction=digitalRead(buttonpin);

speed=map(speed,0,9,0,255);

if(direction==HIGH)

{

analogWrite(motorPin1,speed);

analogWrite(motorPin2,0);

}

else

{

analogWrite(motorPin1,speed);

analogWrite(motorPin2,0);

}

}