Question: Write an Arduino program that controls a DC Motor using the H-Bridge board.Program should read from the serial port Receiving value 0 sets the motor

Write an Arduino program that controls a DC Motor using the H-Bridge board.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

Print user instructions to the screen once at the beginning. In order to allow it to operate as a state machine, it should not have specific times for the user to make an entry.

Must include a function that sets the motor speed and direction

Input Argument: char/int8_t command (not global variable), which will be either a speed or a direction, depending on its value.

Example:

void updateMotor(int8_t command){

int8_t motorSpeed;

if(command == 'F' || command == 'f'){

// Commands to set direction forward

}

else if(command == 'R' || command == 'r'){

// Commands to set direction reverse

}

else if(command >= '0' && command <= '9'){

// Convert ASCII "command" code to integer by subtracting

// ASCII '0'. Multiply by desired ratio to give

// speed of 255 with command of '9' and

// speed of 0 with command of '0'.

motorSpeed = (command - '0')*255/9;

// Commands to set motor speed

}

// No else required. Errant commands/newlines ignored.

}

Program should acknowledge the user input by echoing back what it received:

e.g. You entered a speed of X OR You entered a direction of Y

This may be done either immediately after reading the user input or when setting the motor speed/direction.

Errant commands do not need to be echoed.

here is an example of checking for serial input from the user:

https://www.arduino.cc/reference/en/language/functions/communication/serial/available/

Note: Serial.read() only reads ASCII characters! So, when you type in a 5, the variable is assigned the ASCII code for 5.

Remember that you need to set up pin modes and Serial before using them!

Write an Arduino program that moves the position servo in 10 degree increments through its entire range of motion, sweeping back and forth between the limits. Pause at each angle for 0.5 seconds. Hint: it is helpful to use a flag variable to keep track of which direction it is moving.

Write an Arduino program that combines parts 1 and 2 in such a way that the servo continues incrementing or decrementing while the Arduino is also listening for serial input. You must use a state machine. the Arduino should respond immediately to any serial input

the code cannot wait until the servo has reached a certain position before checking for serial input

your final code cannot use any delay statements

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!