Solar Tracker
The project was to create a little solar tracker, that follows a light. This device can be linked to a robot, a parabola, etc.
Components and supplies
3
Resistor 10k ohm
2
SG90 Micro-servo motor
1
9V battery (generic)
1
Arduino UNO
3
Photo resistor
Tools and machines
1
Hot glue gun (generic)
Project description
Code
CODE Solar tracker
csharp
1// 29/07/2017 - Programme C - Tracker solaire - Carte Arduino ( UNO ) 2// Ce programme a pour objectif de : 3// - Traiter les informations apportés par les photorésistances 4// - Gérer la rotation et l'inclinaison du module pour suivre une source lumineuse 5// Programme réalisé par Techno_Fabrik 6 7//********************BIBLIOTHEQUES**************************** 8 // bibliothèque permettant d'utiliser les commandes pour servomoteurs facilement 9 #include <Servo.h> 10//********************DECLARATIONS**************************** 11 12float photo_r_0,photo_r_1,photo_r_2; // valeur des photorésisances 13int servo1=6; // commande du premier servo 14int servo2=7; 15int angle_rot=90,angle_inc=90; // angle des servos 16Servo moteur_rotation; 17Servo moteur_inclinaison; 18 19 //*************************INITIALISATION ********************** 20 21void setup() { 22 23 moteur_rotation.attach(servo1); // on relie l'obtet au pin de commande 24 moteur_inclinaison.attach(servo2);// on relie l'objet au pin de commande 25 Serial.begin(9600); 26 delay(2000); 27} 28 29//*************************************** BOUCLE *************************** 30 31void loop() { 32 33while ( (angle_rot > 10 )&&(angle_rot< 170) && (angle_inc>10)&&(angle_inc<170)) // sécurité pour les servos 34{ 35photo_r_0=analogRead(A0);Serial.print("R_0 : ");Serial.println(photo_r_0); // entrée analogique 8 bits = 1024 valeurs = 0 à 5V 36photo_r_1=analogRead(A1);Serial.print("R_1 : ");Serial.println(photo_r_1); 37photo_r_2=analogRead(A2);Serial.print("R_2 : ");Serial.println(photo_r_2); 38 39 40if ( photo_r_0<photo_r_1-3) // selon la valeur des photorésistances, on va moduler l'angle des servomoteurs 41{ 42 angle_rot=angle_rot-1; 43 moteur_rotation.write(angle_rot); 44} 45else if (photo_r_0>photo_r_1+3) 46{ 47 angle_rot=angle_rot+1; 48 moteur_rotation.write(angle_rot); 49} 50 51if (photo_r_2>photo_r_1+3) 52{ 53 angle_inc=angle_inc-1; 54 moteur_inclinaison.write(angle_inc); 55} 56else if (photo_r_2<photo_r_1-3) 57{ 58 angle_inc=angle_inc+1; 59 moteur_inclinaison.write(angle_inc); 60} 61} 62Serial.println(" ANGLE SERVO MAXIMUM "); 63}
CODE Solar tracker
csharp
1// 29/07/2017 - Programme C - Tracker solaire - Carte Arduino ( UNO ) 2// Ce programme a pour objectif de : 3// - Traiter les informations apportés par les photorésistances 4// - Gérer la rotation et l'inclinaison du module pour suivre une source lumineuse 5// Programme réalisé par Techno_Fabrik 6 7//********************BIBLIOTHEQUES**************************** 8 // bibliothèque permettant d'utiliser les commandes pour servomoteurs facilement 9 #include <Servo.h> 10//********************DECLARATIONS**************************** 11 12float photo_r_0,photo_r_1,photo_r_2; // valeur des photorésisances 13int servo1=6; // commande du premier servo 14int servo2=7; 15int angle_rot=90,angle_inc=90; // angle des servos 16Servo moteur_rotation; 17Servo moteur_inclinaison; 18 19 //*************************INITIALISATION ********************** 20 21void setup() { 22 23 moteur_rotation.attach(servo1); // on relie l'obtet au pin de commande 24 moteur_inclinaison.attach(servo2);// on relie l'objet au pin de commande 25 Serial.begin(9600); 26 delay(2000); 27} 28 29//*************************************** BOUCLE *************************** 30 31void loop() { 32 33while ( (angle_rot > 10 )&&(angle_rot< 170) && (angle_inc>10)&&(angle_inc<170)) // sécurité pour les servos 34{ 35photo_r_0=analogRead(A0);Serial.print("R_0 : ");Serial.println(photo_r_0); // entrée analogique 8 bits = 1024 valeurs = 0 à 5V 36photo_r_1=analogRead(A1);Serial.print("R_1 : ");Serial.println(photo_r_1); 37photo_r_2=analogRead(A2);Serial.print("R_2 : ");Serial.println(photo_r_2); 38 39 40if ( photo_r_0<photo_r_1-3) // selon la valeur des photorésistances, on va moduler l'angle des servomoteurs 41{ 42 angle_rot=angle_rot-1; 43 moteur_rotation.write(angle_rot); 44} 45else if (photo_r_0>photo_r_1+3) 46{ 47 angle_rot=angle_rot+1; 48 moteur_rotation.write(angle_rot); 49} 50 51if (photo_r_2>photo_r_1+3) 52{ 53 angle_inc=angle_inc-1; 54 moteur_inclinaison.write(angle_inc); 55} 56else if (photo_r_2<photo_r_1-3) 57{ 58 angle_inc=angle_inc+1; 59 moteur_inclinaison.write(angle_inc); 60} 61} 62Serial.println(" ANGLE SERVO MAXIMUM "); 63}
Downloadable files
Solar Tracker fritzing
Solar Tracker fritzing
Solar Tracker fritzing
Solar Tracker fritzing
Picture of the fritzing schematic
Picture of the fritzing schematic
Comments
Only logged in users can leave comments