Welcome to 2DOF PTZ repository
Arduino Tutorials
Arduino UNO platform-------ServoControlColor
1) Preparation
1-1 Arduino UNO board
1-2 SG90 servo
1-3 RGB module
2)Purpose of Experimental
After the code upload is completed, the car will still for 0.5 s. The servo starts to turn and lights up different colors when turning to different angles.
3)Principle of experimental
The working principle of the servo: the control signal enters the signal modulation chip from the channel of the receiver to obtain the bias voltage of the DC. It has a reference circuit inside, which generates a reference signal with a period of 20ms and a width of 1.5ms. It will compares the DC bias voltage with the voltage of the potentiometer to obtain a voltage difference and output. The positive and negative of the voltage difference is outputted to the motor drive chip to determine the forward and reverse of the motor.
Servo rotation angle is by adjusting the duty ratios of PWM (pulse width modulation) signal. The standard PWM (pulse width modulation) signal has a fixed period of 20ms (50Hz). Theoretically, pulse width distribution should be between 1 ms to 2 ms, but in fact between pulse width can be 0.5 ms and 2.5 ms. Pulse width and the servo rotation angle 0°~180° corresponds, as shown below.
0.5ms-----------------0°
1.0ms-----------------45°
1.5ms-----------------90°
2.0ms-----------------135°
2.5ms-----------------180°
4)Experimental Steps
4-1 About the schematic
4-1 Arduino UNO interface circuit diagram

4-2 RGB module interface 4-3 Servo interface
4-2 According to the circuit schematic:
LED_R-----11(Arduino UNO)
LED_G-----10(Arduino UNO)
LED_B-----9(Arduino UNO)
J1---3(Arduino UNO)
(Note: SG90 Servo is be connected to steering gear interface J1)
4-3 About the code
1. We need to open the code of this experiment: ServoControlColor.ino, click“√” under the menu bar to compile the code, and wait for the word "Done compiling " in the lower right corner, as shown in the figure below.
2.In the menu bar of Arduino IDE, we need to select 【Tools】---【Port】--- selecting the port that the serial number displayed by the device manager just now, as shown in the figure below.
3.After the selection is completed, you need to click “→”under the menu bar to upload the code to the Arduino UNO board. When the word “Done uploading” appears in the lower left corner, the code has been successfully uploaded to the Arduino UNO board, as shown in the figure below.