Hello everyone, i am 17 and new to learning arduino. I have a project in mind i will be really glad if you can resolve some of my queries.
How do i move my servos in a specific way on pressing a key from my computer's keyboard.
For instance, if i press the 'A' key, Servo 1 should move 20 degrees clockwise, Servo 2 should move 20 degrees anti clockwise. Please help me on how can i take input from the keyboard in such a fashion.
Thank you
It doesn't quite work like that.
You need to open the serial monitor, enter characters in the input text box, then press [Send] or your keyboard's [Enter] key. This will send the character(s) serially to the Arduino, where the data can be accessed using 'Serial.read()' and the related functions.
Then you can use 'Servo.write()' to move the servo to a particular position, based on the serial input.
Have you written any basic code for controlling servos yet?
OldSteve:
It doesn't quite work like that.You need to open the serial monitor, enter characters in the input text box, then press [Send] or your keyboard's [Enter] key. This will send the character(s) serially to the Arduino, where the data can be accessed using 'Serial.read()' and the related functions.
Indeed, but if you want, you can write a simple program to send the keystrokes directly, using Processing.
Or use a decent terminal program
Split the task into two parts - figure out how to control servos, using code based on the examples,
then figure out how to handle serial input and the various options on your computer for handling
a serial connection.
Only then put the two things together - by then it will make sense, and you are much less likely
to get completely stuck, because you will have an understanding of both aspects already.
sterretje:
Or use a decent terminal program
Indeed, shame I didn't think of that, it's much easier.
However, if you wanted to add clickable buttons to control the motors, you could use Processing.
PieterP:
Indeed, but if you want, you can write a simple program to send the keystrokes directly, using Processing.
True, or a C++ app, VB app, etc etc
I regularly write small C++ Windows programs to send/receive serial to/from an Arduino or PIC using a USB to TTL converter, either directly or via an RF transceiver.
What I really meant, but didn't say, was that it can't be done without additional software running on the PC.
Edit: Including terminal program that sends key presses directly, without having to press [Enter], as sterretje implies.
But if all you have is the IDE and an Arduino board, the serial monitor is the only option.
You may want to disconnect from the PC and use push button switches, IR remote or a keypad connected directly to the Arduino.
This way you have a self contained project.
.
Do you already have an Arduino? If not, there are many simple PC USB servo control boards out there that might be easier to work with.