Introduction: Servo Motor Keypad Control
First is to set-up the servo motor.
- Middle wire goes to the 5V port
- The left goes to the GND port
- Connect the last (the control wire) to port 9
Step 1: Connect the Keypad
The keypad is pretty simple. Just connect pins left from right 8, 7, 6, 5, 4, 3, 2, 1. The picture is shifted by one but we are connecting the servo to 9 so just shift everything down.
Step 2: Download the Code Though
Download the code (that is commented) and run. All should be well. Basically when you enter a 3 digit number below 180 it moves the servo arm to that degree. By three digit I mean you will need to enter 010 to get 10 and 005 to get 5.
Step 3: Code Setup
Keypad's can differ, just be sure yours looks like the char array, if not simply change the chars to match yours. I used a start variable to hold the reset val (0) which is option. You can always pass a 0 to the method instead.
Step 4: Digit 1
This code check to see if it is evaluating the first digit which can only be a 0 or 1. Anything else causes the servo to reset to 0 since input was invalid. If valid increase to the next digit and adds 100 if 1 was entered. So you have a base now of 100.
Step 5: Digit 2
Similar to the first it only evaluates numbers, this time 1-9. Once a valid character is entered it adds the number entered times 10 to fill in the 10's place. So let's say digit 1 was 1 so you have 100, now you entered 5. The base is now 150.
Step 6: Digit 3
Digit 3 is similar to the others but simply adds 1-9 based on what was selected. Let's say 8 was entered. You now have 158 to pass to the servo move method. Once passed, go to next step...
Step 7: Servo Move
Checks that the val, our example is 158, is less than 180. Since it is it moves the motor to 158 degrees. If it were say 190, the servo would reset to 0. The serial prints are just for data checking. Nothing to significant there.
We have a be nice policy.
Please be positive and constructive.