Thank you for taking the time to look at this post.
This is the first time I have ever interacted with the Arduino family of products and was referred to it by someone at work when I told them about my project. The aim of my project is to automate a dual axis solar tracker I am building. I took a stab at the software portion of the project and would greatly appreciate someone with a little experience looking it over and giving me feedback. I made a conscious effort to provide comments to hopefully clarify things and make the review process easier.
Thank you for any assistance you can give,
Dath_Ar
/*
This is my first time utilizing an Arduino Microprocessor. My intent is to use the
Arduino MEGA microprocessor and board to automate a dual axis solar tracker I built.
Below is the software I put together based on a few simple examples and the following
web site:
https://www.arduino.cc/reference/en/#page-title
Below is a crude schematic for the sensor input utilizing a voltage divider circuit:
5V Aduino pin-->LSR GL5539-->Arduino Analog Input Pin-->1Mohm Resistor-->Arduino GND Pin
4 LSR's are then put in the various quardents of an XY graph with the X and Y axis being
walls to seperate each LSR and provide shade accordingly.
The output will be going to 4 relays to operate a single Linear actuator. This basic
priciple is then duplicated in order to get the second axis of movement.
I would appericate someone looking over this code to make sure what I am doing is valid.
If there are easier ways of doing thing, please feel free to comment so I can incorporate
them.
Thank you.
*/
//Pin IN Definitions
float ATL = A0; //Analog Top Left input from pin A0 of Arduino Mega Board
float ATR = A1; //Analog Top Right input from pin A1 of Arduino Mega Board
float ABL = A2; //Analog Bottom Left input from pin A2 of Arduino Mega Board
float ABR = A3; //Analog Bottom Right input from pin A3 of Arduino Mega Board
//Intermediate Variables
float NS = 0; //North(+) vs South(-) compairison variable initalizing to 0
float EW = 0; //East(+) vs West(-) compairison variable initalizing to 0
float NoiseOffSet = 0.01; //Noise offset in Volts to prevent unintentional movement from noise
//PIN OUT Definitions
int N = 13; //Digital North Relay output from pin 13 of Arduino Board
int S = 12; //Digital South Relay output from pin 12 of Arduino Board
int E = 11; //Digital East Relay output from pin 11 of Arduino Board
int W = 10; //Digital West Relay output from pin 10 of Arduino Board
void setup()
{
//Inital Setup and Start Point with all outputs LOW to prevent sudden unpredictable movement
pinMode(N,OUTPUT); //Pin N is defined as an output
pinMode(N, LOW); //Pin N is set low
pinMode(S,OUTPUT); //Pin S is defined as an output
pinMode(S, LOW); //Pin S is set low
pinMode(E,OUTPUT); //Pin E is defined as an output
pinMode(E, LOW); //Pin E is set low
pinMode(W,OUTPUT); //Pin W is defined as an output
pinMode(W, LOW); //Pin W is set low
NoiseOffSet = constrain(NoiseOffSet,0,5); //Ensure a valid range (0-5V) for NoiseOffSet
}
void loop() {
/*
Check Voltage On Analog Inputs from ATR, ATL, ABR, ABL and activate relays on the dual axis
solar tracker to control linear actuators to point the solar panals at the sun
Read in Alalog Voltage values from a voltage division circuit utilizing Light Sesitive
Resistor(LSR) and compair the voltages to determine which way to move
*/
NS = analogRead(ATL) + analogRead(ATR) - analogRead(ABL) - analogRead(ABR); //Top/NORTH(+) vs Bottom/SOUTH(-) signals
EW = analogRead(ABR) + analogRead(ATR) - analogRead(ABL) - analogRead(ATL); //Right/EAST(+) vs left/WEST(-) Signals
if(NS > OffSet)
{
pinMode(S, LOW); //Point solar array NORTH
pinMode(N, HIGH); //Point solar array NORTH
}
else if (NS < OffSet)
{
pinMode(N, LOW); //Point solar array SOUTH
pinMode(S, HIGH); //Point solar array SOUTH
}
else
{
pinMode(N, LOW); //In correct position: Take no action
pinMode(S, LOW); //In correct position: Take no action
}
if(EW > OffSet)
{
pinMode(W, LOW); //Point solar array EAST
pinMode(E, HIGH); //Point solar array EAST
}
else if (EW < OffSet)
{
pinMode(E, LOW); //Point solar array WEST
pinMode(W, HIGH); //Point solar array WEST
}
else
{
pinMode(E, LOW); //In correct position: Take no action
pinMode(W, LOW); //In correct position: Take no action
}
//Continually loop and take appropriate actions to direct the solar panals toward the sun
}
//Pin IN Definitions
float ATL = A0; //Analog Top Left input from pin A0 of Arduino Mega Board
float ATR = A1; //Analog Top Right input from pin A1 of Arduino Mega Board
float ABL = A2; //Analog Bottom Left input from pin A2 of Arduino Mega Board
float ABR = A3;
There is no analogue input pin A0.732.
Why use a float?
if(NS > OffSet)
{
pinMode(S, LOW); //Point solar array NORTH
pinMode(N, HIGH); //Point solar array NORTH
}