Serial Monitor Controlling DC Motor

Hello, I need help understanding what seems to be a pretty basic function but I cannot figure out. Can someone please help?

I'm trying to control via serial monitor one DC motor.

I'm not understanding what lines of code will enable me to type "w" into the monitor and have my DC motor drive forward.

I've tried many different while, if, and case statements but am not understanding this simple (hard for me) concept.

/*

Left motor running one direction (forward)

*/

int enA = 9;
int in1 = 8;
int in2 = 7;

void setup()

{

// Set all left motor control pins to outputs

pinMode(enA, OUTPUT);
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);

}

void loop()

{

// This function will run the left motor forward a fixed speed

// Turn on left motor

digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);

// Set speed to 200 out of possible range 0~255

analogWrite(enA, 75);

}

Firstly, please read the post on page 1 entitled "Read this before posting a programming question ... " and then you will know to post your code within tags.

To address your requirements, in order to communicate with the outside world (monitor) you need to set up the comm port which is usually accomplished with a function call to Serial.begin(9600). The baud rate of 9600 can be changed to one of your liking. This command in in your setup() function,

In loop(), make a period check to see

if(Serial.available())

and if true, read what is at the input port and act on it. There are many good tutorials describing the Serial library.

Have a look at the examples in Serial Input Basics - simple reliable ways to receive data.

...R

Hello, I need help how to control two DC motor with arduino use serial monitor. Can someone please help?

lokendrajohare:
Hello, I need help how to control two DC motor with arduino use serial monitor. Can someone please help?

As you are asking your question in an existing Thread I presume you studied the advice earlier in the Thread and tried to get things working based on that advice?

Please post the program that represents your best attempt and tell us in detail what it actually does and what you want it to do that is different. And please use the code button </> when posting code
codeButton.png

...R