Coding for controlling DC motors with keyboard

I have an Arduino Uno and motor shield and i want to control DC motors speed and direction with the keyboard arrow keys, I want to be able to control 2 motors connect to A+ and A- and B- And B+, what code do I use to do this?

What have you tried so far ?

Can you run one motor at a fixed speed, for instance

Then as far as I know you will not be able to read the keyboard arrow keys. The best that you could do is to read commands entered as text from the keyboard using the Serial interface

I haven't run it at a fixed speed, im completely new to arudino programming.

I suggest that you start with something simpler like the examples in the IDE but bear in mind what I wrote about the Uno being able to receive the keypresses from the PC

Thanks for tip (:

Just figured how to make it run at a set speed.

As an exercise, now make it change speed based on input to the Serial monitor

Either use '+' to increase speed and '-' to decrease speed. For extra experience read a speed value from the Serial monitor and change the motor speed to the value entered

1 Like

I don't know how to use the input serial monitor for motor control, I tried it first but originally I got a stray/302 in program at the if ( s == '0') line of code.

That's usually caused by copying the code from a web page. You can delete and retype the offending line(s) or sometimes pasting it here between code tags will clean it up and you can copy it back for use.

1 Like

I think it may also be cause because after one if statement there where multiple functions.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.