1 / 25
Tracking system
ZYA0017
V2.02.308.03
2 / 25
Introduction to the tutorial
This tutorial includes the content of the file as shown in the figure below to help you learn more about this kit and
programming knowledge:
"1_Get_start": This folder stores the robot assembly guide and necessary software environment files, etc. In order to
complete the assembly accurately and quickly, please be sure to review it in detail and assemble it according to the manual.
At the same time, the premise of realizing the program function is to create the software environment correctly, please check
the PDF file under this folder.
"2_Arduino_Code": This folder is used to store Arduino code files, and each code file is uploaded and used independently;
After completing the environment creation, follow this tutorial to complete program burning and realize interesting
functions step by step!
3 / 25
1. Burn the servo reset code
1.1 Description
Before assembling this kit, you need to reset the servos, which will make it easier for you to assemble your light tracking
system accurately. After burning the code successfully, wait for the servo to reset. After the reset is completed, please do not
change the angle of the servo center shaft at will, which will affect the assembly. For more details, please see the attached
installation manual (Installation Steps.pdf) or the assembly video.
1.2 Burn code
Open the first code file in the Arduino IDE software (path: 2_Arduino_Code\1_Reset\1_Reset.ino)
Connect the main control board to the computer with a USB cable and check that the Board Type and Serial Port settings
are correct. Here we choose the board type as UNO, and the serial port COM number as COM5. Note: The board type
here is Uno and the serial port is COM5 . Actually the serial port appears to be different for everyone, even though COM
4 / 25
5 is selected here , it could be COM3 or COM4 on your computer.
Click the "upload" upload button to complete compiling and uploading the code.
After the upload is successful, you can hear the servos start to reset, keep the angle of the servos and start assembling your
light tracking system.
5 / 25
2. Tracking system
2.1 Description:
After the assembly of the tracking system is completed, the burning of the tracking code and the effect test begin. Prepare a
flashlight or other equipment with a light source in advance to test the effect of the follow light system.
2.2 Burn the tracking system code
Open the code file of the light tracking system (path: 2_Arduino_Code\2_Sunflower\2_Sunflower.ino )
Also correctly select the board as UNO and serial com
6 / 25
After burning the code, the light tracking system will also be reset, and it will start to detect the surrounding lighting
conditions and rotate slowly.
2.3 Test the light tracking system
Use a flashlight to illuminate the photosensitive sensor from different directions to observe the movement of the
photovoltaic panel. If the rotation is found to be reversed, please check whether the wiring pins are consistent with those in
the assembly manual. (Note that the G\V\S in the sensor should be consistent with that in the expansion board)
7 / 25
So far, the effect of the light tracking system has been understood, and the following content mainly learns more detailed
knowledge of the device.
8 / 25
3. Servo
3.1 Description:
In this section, you will learn about the knowledge of the steering gear (servo motor) and learn how to adjust the angle of
the servo motor.
3.2 Servo motor rotation:
This servo motor can rotate about 0°~180°, the initial 0° position of the servo needs to be determined before assembly:
( Because the reset program is burned, the content of this section is only for understanding )
1. Install the steering gear crank on the steering gear, slowly turn the crank clockwise to the limit position, and remove the
crank
9 / 25
+ =
2. Reinstall the crank to be installed in the vertical direction to determine the initial 0° position, and turn the crank
counterclockwise to obtain 90° and 180°
0°
90°
180°
(1) (2) (3)
3. It is worth noting that the range of the horizontal steering gear used in this course is 5° to 175°, and the range of the
vertical steering gear is 20° to 100° (leave a limit position margin to avoid getting stuck)
10 / 25
4. After fixing the servo, turn the crank of the servo to the 90° position, and then assemble other parts.
3.3 Circuit connection:
A servo motor has three wires: power, ground, and signal. The power wire is usually red and connects to the "V" pin on the
UNO expansion board. The ground wire is generally black or brown and should be connected to the ground "G" pin of the
expansion board. The signal pin is usually yellow, orange or white and should be connected to the "S" pin on the expansion
board.
Schematic:
11 / 25
Wiring diagram:
12 / 25
Horizontal
vertical
13 / 25
4. Photoresistive sensor
4.1 Description
There are four photoresistive sensors used in this section, which correspond to the detection of light intensity in four
directions.
4.2 Light chasing principle
Take the average value of two adjacent photoresistive sensors and compare it with the average value of the other two
sensors. Under the control of the motor, the solar panel turns to the side with higher light intensity. For example:
14 / 25
As shown in the figure above, when the average light intensity received by the upper two sensors is greater than the average
light intensity of the two lower sensors, the solar panel will rotate and move in the upward direction, which is the direction
of the vertical servo motor in the right figure, and the opposite direction of light intensity is then The servo motor just
reverses until the motor turns to the set limit angle position.
15 / 25
As shown in the figure above, when the average light intensity received by the two sensors on the right is greater than the
average light intensity of the two sensors on the left, the solar panel will rotate and move in the right direction, that is, the
horizontal servo motor in the right figure turns in the direction of the arrow, and the opposite light intensity direction, then
the servo motor reverses the same way until the motor turns to the set limit angle position.
Notice:Each photoresistive sensor has three wiring pins, from left to right: data transmission pin, power supply pin, wiring
pin ("S", "V", "-"). When connecting, the "-" pin is connected to "G", the middle pin is connected to "V", and the "S" pin is
connected to "S".
16 / 25
Upper left sensor:
Upper right sensor:
17 / 25
Lower left sensor:
Lower right sensor:
18 / 25
5. Solar panels and three digital tubes
5.1 Description
In the previous study, we have learned the principle of the light-following system. Under the light intensity at a certain angle,
the solar panel can face the light source. This lesson mainly learns how the solar panel converts solar energy into electrical
energy and transmits it under the light source. It is a three-digit digital tube.
Wiring diagram:
19 / 25
Renderings:
20 / 25
6. Program debugging method
Define the port:
#include <Servo.h>
#define SERVOPINH 5 //Horizontal server
#define SERVOPINV 6 //Vertical server
Define the delay and tolerance parameters:
#define dtime 50 //Delay parameter, the smaller the value, the faster the corresponding speed, and vice versa, the corresponding slower. The unit
is millisecond. General value (10~100)
#define tol 50
Define 4 sensor wiring interfaces:
const int ldrlt = A0; //Upper left
const int ldrrt = A1; //Upper right
const int ldrld = A2; //Lower left
const int ldrrd = A3; //Lower right
As mentioned earlier, set the initial angle and limit angle of the two servo motors
// Horizontal server Settings
Servo horizontal; // Horizontal server
int servoh = 90 ; // Default angle
21 / 25
int servohLimitHigh = 175 ; //Left and right angle
int servohLimitLow = 5 ; //Left and right angle
// Vertical server settings
Servo vertical; // Vertical server
int servov = 9 0 ; // Default angle
int servovLimitHigh = 100 ; //
int servovLimitLow = 20 ; //The maximum elevation angle is not easy to be too large, the sensor may withstand the rack
Set part of the code to let the servo motor enter the initialization position, so you will see that the solar panel will quickly
swing to the set position after the program is loaded successfully.
void setup ()
{
Serial.begin ( 9600 ) ; _
horizontal.attach ( SERVOPINH) ;
vertical.attach ( SERVOPINV );
horizontal.write ( servoh) ;
vertical . write (servov);
delay ( 100 );
//Test operation
//Test the operation of the vertical axis, pay attention to check whether there is a jam (or wire winding).
22 / 25
// for(int i=servovLimitLow;i<servovLimitHigh;i+=2)
// { vertical. write(i);
// delay(30);
// }
// //vertical.write((servovLimitLow + servovLimitHigh)/2);
// delay(100);
// //Test horizontal
// for(int i=servohLimitLow;i<servohLimitHigh;i+=2)
// { horizontal. write(i);
// delay(30);
// }
// //horizontal.write((servohLimitHigh + servohLimitLow)/2);
//If there is no problem with the test, you can remove the code here.
}
The green part is the comment code, which is used to test the process when the angle minimum value servovLimitLow
rotates to the angle maximum value servovLimitHig, and can be deleted after the test is ok.
The principle of light tracking is mentioned in the previous content. Similarly, the following program sets the variables of
the intensity of light received by the four sensors, and controls the rotation of the steering gear by comparing the average
23 / 25
values of the two groups of sensors.
void loop ()
{
int lt = analogRead (ldrlt); //up_ left
int rt = analogRead (ldrrt); // up_right
int ld = analogRead (ldrld); //low_l
int rd = analogRead (ldrrd); //low_r Read the illuminance value of 4 sensors separately
int avt = (lt + rt) / 2 ; // up_l_r
int avd = (ld + rd) / 2 ; // low_l_r
int avl = (lt + ld) / 2 ; // left_up_low
int avr = (rt + rd) / 2 ; // right_up_low Average the adjacent readings
int dvert = avt - avd; // vertical-up-low
int dhoriz = avl - avr; // horizontal-left-right Then calculate the average value of the upper and lower rows and the average value of the left and
right rows
//Check if the difference is within tolerance, otherwise change the vertical Angle
if (- 1 *tol > dvert || dvert > tol) //Determine if the tolerance is out of range
{
if (avt < avd) //vertical
{
servov = ++servov;
if (servov > servovLimitHigh)
{
24 / 25
servov = servovLimitHigh;
}
}
else if (avt > avd)
{
servov= --servov;
if (servov < servovLimitLow)
{
servov = servovLimitLow;
}
}
vertical . write (servov); //If the rotation angle of the servo is opposite to the light, use (180- servov) or (servov) to change the direction.
}
//Check whether the difference is within the tolerance range, otherwise change the horizontal angle
if (- 1 *tol > dhoriz || dhoriz > tol)
{
if (avl < avr)
{
servoh = --servoh;
if (servoh <servohLimitLow)
{
servoh = servohLimitLow;
}
}
25 / 25
else if (avl > avr)
{
servoh = ++servoh;
if (servoh > servohLimitHigh)
{
servoh = servohLimitHigh;
}
}
else if (avl = avr)
{
// nothing
}
horizontal . write (servoh); //Steering gear rotation Angle and the light of the opposite with (180-servOH) or (servOH) can be reversed
}
delay (dtime);
}