Servo.write(value_servo) // shaft of servo will start to rotate. Value_servo = map(value_knob, 0, 1023, 5, 175) // will map knob value range to servo value range Value_knob = analogRead(PIN_KNOB) // reads value of the knob/potentiometer. Servo.attach(PIN_SERVO) // assigns pin 9 to the servo object Int value_servo = 0 // will be used to control the servo => should be between 5 and 175 degrees Int value_knob = 0 // will be used to store the value of the potentiometer/knob Servo servo // creates servo object to control the SG90 servo At the end of the loop function, we add a delay of 20ms to give the servo some time to turn its shaft. After calling the map-function, the resulting value is used to let the servo turn its shaft. Therefore, we subtracted 10° in order to avoid damaging our servo motor. According to my experience, the SG90 does not sound very “healthy”, if the full range of 180° is used. Since the SG90 supports approximately 180°, we map the value two values between 5° and 175°. As the Arduino’s analog-to-digital converter will map the voltage to values between, we have to remap these values to an rotary angle value that is supported by our servo motor. In the loop function, we read the analog value of the rotary angle sensor’s knob (or value of the potentiometer). The servo object is now fully initialized and ready to control the servo. In the setup function, we attach digital pin number 9 to the servo object. The second variable is the rotation value that will be sent to the servo motor. The first one is used to store the values retrieved from the sensor/potentiometer. Then, a servo object is created that will be used to control the servo motor. Next, we define two pins: digital pin 9 for the servo motor and analog pin A0 for the rotary angle sensor (or potentiometer). In order to use this library, we have to include its header file. Luckily, the Arduino IDE has already a built-in servo library. The pin in the middle is the signal pin which corresponds to the sensor’s SIG pin and must be connected to an analog input pin (e.g. If a potentiometer is used instead of the rotary angle sensor: Typically, the outer pins of the potentiometer must be connected to the power supply (GND and 5V pin of the Arduino). Finally, the sensor’s SIG pin must be connected to one of the Arduino’s analog input pins. The pin in the middle is the VCC pin, which must be connected to breadboard (same column as the other two pins). The sensor’s left pin is the ground which must be connected to one of the Arduino’s GND pins. In this tutorial, digital pin 9 of the Arduino is used for this task and, therefore, wired to the SG90’s yellow pin.įollowing, we have to wire the rotary angle sensor to the Arduino. In order to control the SG90 servo, PWM signals (Pulse Width Modulation) must be sent through the yellow wire. Next, the brown wire of the SG90 must be connected to one of the Arduino’s GND pins. Then, the servo’s red wire is connected to the breadboard (same column as previous pin). The Arduino’s 5V pin is connected to a breadboard. Since the Arduino Uno has only one 5V pin, we use a breadboard to split the 5V signal. Both, the servo and the rotary angle sensor need a voltage supply. In order to control the SG90, a rotary angle sensor is used.įirst, we connect the SG90 servo motor to the Arduino Uno. Pin layout: A scheme that shows how to wire the micro servo motor SG90 to an Arduino Uno. – Potentiometer (in alternative to the rotary angle sensor) Therefore, it can be simply replaced by almost any potentiometer, since it is used here only for convenience reasons. This module is nothing more than a conventional potentiometer combined with a knob. In order to control the motor, a so-called rotary angle sensor module is used. In this tutorial, it is shown how to control the SG90 servo motor. Moreover, is is very small and lightweight (Weight: 9g Dimension: 22.2 x 11.8 x 31 mm). The SG90 is such a servo motor that can rotate approximately 180°. Both can be used to control the servo motor. In the background is a rotary angle sensor module and a potentiometer. Nonetheless, servo motors are very useful if a projects requires a motor with a precise control and awareness of its current position. However, the disadvantage of these servos is that the rotation range is limited (e.g. In particular, a command can be sent to the servo so that the servo’s shaft rotates to a specific position. As a result, servo motors can be controlled very precisely. Among these four things, the potentiometer acts as a position sensor. Typically, servo motors are a combination of four things: a conventional DC motor, a set of gearings, a potentiometer, and a control circuit.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |