This project had a little bit going on. We used the Server Motor included in the kit to make an arm that moves in reaction to our potentiometer that we also have on the board connected to the Analog Pin 0 on the Arduino board. This will read the input to control the position of the arm on the server by changing the ratio of voltage when you turn the knob of the potentiometer. We connect the Servo wires to the power, ground and to Digital Pin 9. We use capacitors to smooth out voltage changes that occur when we turn the potentiometer.
For the code, we first had to import the servo library, and then #include it in the top of the code so the sketch reads that it is there. We refer the servo by making it a variable,, and then set up a constant for the Analog pin for the potentiometer. We also make a constant that will hold the analog input so it determines the value and the angle the servo will move towards. We set up a loop to read the potentiometer value afterwards. Using a Map function, we can add values to the Servo angles. Then with the Write function, this will move the motor to the correct angle.
Comments
Please log in or sign up to comment.