I'm very new to Arduino and I am trying to make a servo spin when I press "a". I couldn't find anything online so I'm not sure where to start.
Hi @parkerb0888
welcome to the arduino-forum
The reason why you didn't found anything online is that the combination of
keybaoard input and controlling a servo is only one of a billion of possible combinations how two microcontroller things can be combined.
As soon as you search for single terms like
"receive a keypress on arduino"
"control a servo"
You will find code-examples
You can either
-
investing time in waiting for answers not learning anything
or -
investing time in learning how to finish your project faster
There are some things to learn for a beginner if you want to proceed faster in your project
one of the most important things to learn is how to post in a way that is efficient
This is described here
best regards Stefan
Is this key press from the Keyboard of the PC or from a 4x4 Keypad attached with UNO?
consider
#include <Servo.h>
Servo servo;
byte PinServo = 10;
int val;
void
loop (void)
{
if (Serial.available ()) {
switch (Serial.read()) {
case 'a':
val = 180;
break;
case 'b':
val = 125;
break;
case 'd':
val = 90;
break;
case 'e':
val = 45;
break;
default:
val = 0;
break;
}
servo.write (val);
}
}
void
setup (void)
{
Serial.begin (9600);
servo.attach (PinServo);
servo.write (0);
}
if it is your PC then using the serial monitor of the ardiuno-IDE will work with the minimal example that gcjr has posted
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.