i have been designing a solar powered wireless router for a while now and have decided to use a small arduino board to monitor it over the wifi network.
the router is a TP-link WR703N TP-Link TL-WR703N [Old OpenWrt Wiki]
i love this router due to it only using around 0.6w so it makes it ideal for solar power and that it has a serial port that i can access over the network via SER2NET so the next step was to build a way of monitoring the battery voltage, how many amps the solar panel is putting into the battery, thermal management of the batteries and how bright the sun is so i know if the batteries are charging like they should.
using what coding remembered from school 10 years ago and some tinkering with settings i have done setting some some RC flight controllers i managed to copy and paste something together from a few different sources that appears to look okish when I run it on my test arduino nano and monitor the serial output but i think it will need some calibration when all the parts arrive.
it started out as this program for monitoring temperature and AC voltage that i edited down to what i needed from it
i then grafted the current monitoring part from here by simply deleting everything i didnt need then copy and pasting.
i got the part to turn the led on if it gets too hot from here i will use it to turn on a cooler for the batteries
and the LDR code from here
http://bildr.org/2012/11/photoresistor-arduino/
the code is not finished yet i am going to add a second thermal switch to heat the batteries if it gets too cold and im still not 100% sure on how to get the light to show as a calibrated percentage ie i would like 2 values that i can set on a sunny day and in the dark.
I doubt this code will work as is but can anyone point out any mistakes or is there a better way of doing any part of it?
int voltPin = A0; // voltage divider (middle terminal) connected to analog pin 0
int tempPin = A2; // TMP36 data pin
int val = 0; // variable to store the value read
int volt = 0; // variable to store the voltage calculated
int analogInPin = A1; // Analog input pin that the carrier board OUT is connected to
int sensorValue = 0; // value read from the carrier board
int outputValue = 0; // output in milliamps
int LDR_Pin = A4; //analog pin 0
int ledPin = 13; // choose the pin for the LED
float amps = 0.0;
unsigned long msec = 0;
float time = 0.0;
int sample = 0;
void setup()
{
Serial.begin(9600); // setup serial
pinMode(ledPin, OUTPUT); // declare LED as output
}
void loop()
{
// Voltage Calculation
val = analogRead(voltPin); // read the input pin
volt = map(val, 0, 1023, 0, 29); // map 29v range
delay(50);
// temp calculaton
int reading = analogRead(tempPin); // read the input pin
float voltage = reading * 5.0;
voltage /= 1024.0;
//current monitor
// read the analog in value:
sensorValue = analogRead(analogInPin);
// convert to milli amps
outputValue = (((long)sensorValue * 5000 / 1024) - 500 ) * 1000 / 133;
amps = (float) outputValue / 1000;
float watts = amps * voltage;
//light dependsnt resistor
int LDRReading = analogRead (LDR_Pin)/10 ;
//uptime
msec = millis();
time = (float) msec / 1000.0;
//Fan control
{
float temperatureC = (voltage - 0.5) * 100;
if (temperatureC < 1000) {
digitalWrite(ledPin, LOW); // turn LED OFF
} else {
digitalWrite(ledPin, HIGH); // turn LED ON
}
// serial output
}
Serial.print(voltage);
Serial.print(" volts");
Serial.print("\t Current (amps) = ");
Serial.print(amps);
Serial.print("\t Power (Watts) = ");
Serial.print(watts);
float temperatureC = (voltage - 0.5) * 100;
Serial.print("\t degrees C = ");
Serial.print(temperatureC);
Serial.print("\t Solar output % = ");
Serial.print(LDRReading);
Serial.print("\t Time (hours) = ");
Serial.println(time/3600);
delay(500);
}



