• Welcome to TechPowerUp Forums, Guest! Please check out our forum guidelines for info related to our community.
  • The forums have been upgraded with support for dark mode. By default it will follow the setting on your system/browser. You may override it by scrolling to the end of the page and clicking the gears icon.

Arduino for managing Solar powered wireless router volts/amps/temp/light

Joined
Mar 12, 2009
Messages
1,155 (0.20/day)
Location
SCOTLAND!
System Name Machine XX
Processor Ryzen 7600
Motherboard MSI X670E GAMING PLUS
Cooling 120mm heatsink
Memory 32GB DDR5 6000 CL30
Video Card(s) RX5700XT 8Gb
Storage 280GB Optane 900p + 2tb 4.0 NVME + 2tb sata ssd.
Display(s) 19" + 23" + 17"
Case ATX
Audio Device(s) Soundblaster Z
Power Supply 800W
Software Windows 11
i have built a solar powered wireless router and to manage it i have designed a system around an arduino board connected to the network via a serial port and SER2NET on openWRT.

the idea is to use the arduino to monitor the battery voltage, solar panel current output, sun brightness, uptime and monitor the battery temperature to turn on the cooler.

so using what i have picked up from school doing Comal and messing around with flight controllers i managed to google and hack enough code together to almost do what i need it to do. (i think)

does anyone know a better way of doing any of the code ? this is my first time so assume its crap

the solar readout is a bit basic i need to figure out a way of calibrating the LDR so 100% is a sunny day in summer and 0% is darkness

it looks okish on my test arduino with nothing connected but im sure thats why the measurements are a bit whacky.

the fan control will eventually run a small TEC to cool the batteries transferring the heat to the aluminium back plate. i figure if its hot enough to overheat the batteries i can spare some power to cool them.



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 hightemp = 13; // choose the pin for the LED
int lowtemp = 12; // 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(hightemp, OUTPUT); // declare LED as output
pinMode(lowtemp, 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 > 40) {
digitalWrite(hightemp, LOW); // turn LED OFF
} else {
digitalWrite(hightemp, HIGH); // turn LED ON
}
if (temperatureC < 10) {
digitalWrite(lowtemp, LOW); // turn LED OFF
} else {
digitalWrite(lowtemp, 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);
}
 

Attachments

  • .jpg
    .jpg
    793.8 KB · Views: 680
  • arduino.png
    arduino.png
    67.4 KB · Views: 604
Last edited:
You sir always have the most interesting projects I must say.
 
i want to mas produce these soon so i am doing my best to keep the costs down so far its:

20W solar panel £32
TP-link wr703n with openWRT £14
4s 5800mah lithium pack £30
arduino lillypad £4
4s battery protection pcb £4
temperature sensor £2.30
light dependant resistor £2.75
5a current sensor £2.66

if it gets too hot during the summer i will add
5a transistor
30w TEC plate connecting the aluminium plate against the batteries to the backplate of the router.


and a couple of random resistors

I could probably use just one of the batteries during the summer and 1/4 of the solar panel but I live in Scotland where the days are very short during the winter with sunrise around 8:30 and sunset around 4pm but im on the west coast so it doest get too cold for very long. so i hope to get away with using cheap lithium packs.
 
Last edited:
i am replacing the cheap ebay regulator at 4v and the linear regulator in the router with a TRACO TSR 1-2433 - 3.3V/1A switching regulator to try and get power consumption down as low as i can. if i bypass the regulator and run both the arduino and the router direct from the 3.3v switching regulator i should get much more efficiency.
 
Last edited:
i have make singificant progress on the arduino software i now have functional voltage,amps,temperature, light, cooling and heating.

i have even managed to add graphing to it using SimPlot http://www.negtronics.com/simplot



im just waiting for some sensors and the routers now.


int voltPin = A0; // voltage divider (middle terminal) connected to analog pin 0
int tempPin = A2; // TMP36 data pin
const int pinLDR = A5; // Analog Pin A0 connects across LDR
const int pinLED = A1; // Analog Pin A1 connects across LED
int val = 0; // variable to store the value read
int volt = 0; // variable to store the voltage calculated
int hightemp = 13; // choose the pin for the LED
int lowtemp = 12; // choose the pin for the LED
unsigned long msec = 0;
float time = 0.0;
int sample = 0;
float valueVolt; // We'll need these float variables for calculations
float valueBrightness;


int buffer[20];
float deltaAngle = 3.14/51; //Arbitrary angle increment size
float angle = 0;
int amplitude = 100;


void setup()
{
Serial.begin(9600); // setup serial
pinMode(hightemp, OUTPUT); // declare LED as output
pinMode(lowtemp, OUTPUT); // declare LED as output
}

void loop()
{


int data1;
int data2;
int data3;
int data4;





// 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

float amps = 0;
for(int i = 0; i < 1000; i++) {
amps = amps + (.0264 * analogRead(A1) -13.51) / 1000;
delay(1);
}



//light dependsnt resistor
valueVolt = analogRead(pinLED)*5.0/1024; // Store the calculated voltage in a float var
valueBrightness = map(analogRead(pinLDR),990,645,0,100);

//uptime
msec = millis();
time = (float) msec / 1000.0;


//Fan control
{
float temperatureC = (voltage - 0.5) * 100;
if (temperatureC < 40) {
digitalWrite(hightemp, LOW); // turn LED OFF
} else {
digitalWrite(hightemp, HIGH); // turn LED ON
Serial.println("OVERHEAT");
}
if (temperatureC > 10) {
digitalWrite(lowtemp, LOW); // turn LED OFF
} else {
digitalWrite(lowtemp, HIGH); // turn LED ON
Serial.println("COLD");
}





//graphing




// serial output
}
Serial.print(voltage);
Serial.print(" volts");
Serial.print("\t Current (amps) = ");
Serial.print(amps);
float watts = amps * voltage;
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(valueBrightness);

Serial.print("\t Time (hours) = ");
Serial.println(time/3600);



//Generating data that will be plotted
data1 = voltage;
data2 = amps;

data3 = temperatureC;
data4 = valueBrightness;

angle = angle + deltaAngle;

plot(data1,data2,data3,data4);

delay(100); //Need some delay else the program gets swamped with data

}

void plot(int data1, int data2, int data3, int data4)
{
int pktSize;

buffer[0] = 0xCDAB; //SimPlot packet header. Indicates start of data packet
buffer[1] = 4*sizeof(int); //Size of data in bytes. Does not include the header and size fields
buffer[2] = data1;
buffer[3] = data2;
buffer[4] = data3;
buffer[5] = data4;

pktSize = 2 + 2 + (4*sizeof(int)); //Header bytes + size field bytes + data

//IMPORTANT: Change to serial port that is connected to PC
Serial.write((uint8_t * )buffer, pktSize);





}
 

Attachments

  • arduino.png
    arduino.png
    105.7 KB · Views: 693
Last edited:
my TP link router arrived today
tl-wr703n.jpg

tl-wr703n_top.jpg

tl-wr703n_bottom.jpg



what i have to do:
install OpenWRT,

configure the serial port to run at 9600 baud rather than 115200 to hopefully save a little more power

install ser2net

setup ser2net to forward the onboard serial port

solder 2 wires from the serial port to the arduino

chop the antenna off the pcb and solder on a pigtail

bypass the onboard 3.3v regulator and run it from a TRACO TSR 1-2433 - 3.3V/1A switching regulator along with the arduino.
 
A friend of mine built an arduino controlled solar powered hydroponic tower. The arduino controls the solar charging, pump on/off timing and measures temp (he plans on PH as well), logs all information to an SD card. The setup looks like a crashed satellite with tomatoes growing out of it ;)

Needless to say, I'm interested in this! Can't help much as I was just watching it all. Subbed.
 
my first prototype was a little funky looking it ran from 2x 5v 1A solar panels in parallel charging a 1s 6p rewired laptop battery. everything is mounted to a spare tv antenna that was ideal for adjusting the panels for the optimum angle. but this time im trying to put everything inside a solar panel rather than all the elaborate mounting.
 

Attachments

  • DSCF4019.jpg
    DSCF4019.jpg
    490.5 KB · Views: 534
this is the soldering to be done
 

Attachments

  • tl-wr703n_top.jpg
    tl-wr703n_top.jpg
    77.3 KB · Views: 523
  • tl-wr703n_bottom.jpg
    tl-wr703n_bottom.jpg
    92.2 KB · Views: 654
ok using a combiation of the firmware from here and guide here

I have managed to get ser2net running on openwrt and accepting connections from my pc over the network. when my arduino arrives il find out if it works properly.
 
i have been spending the last few days working out the best way to setup a transparent wireless repeater on DD-WRT or OpenWRT. unfortunately i didn't realise the universal repeater function was only available on broadcom and not on my atheros based routers so eventually after not being able to find an acceptable solution i have got it working using WDS. i didnt want to use it originally because of vendor lock in but since all my ubiquiti and tp-link routers are atheros its not really an issue.

i think i have everything working now. transparent wireless bridging and the serial output for monitoring @ 115200 since that is the routers default speed but i will change that to 9600 once im sure its working.

the key was disabling the console on the serial port removing "ttyATH0::askfirst:/bin/ash --login" from the /etc/inittab

and adding "1024:raw:600:/dev/ttyATH0/1:115200 NONE 1STOPBIT 8DATABITS -XONXOFF -LOCAL -RTSCTS" to /etc/ser2netconf

and "ser2net" to the startup.


im just waiting for my arduino. and current sensor before i can test it properly.
 
Last edited:
i soldered the wires on for the 3.3v voltage regulator and hot glued it in place along with the wires for the serial and a led to make sure the pads were working.
 

Attachments

  • DSCF4022.JPG
    DSCF4022.JPG
    994.8 KB · Views: 508
Nice work man! :toast:
 
i hooked up my test arduino nano v3 via a couple of 1k resistors to the routers serial port and got it kind of working...

its getting a lot of corruption at 115200 but to change it i would have to compile openwrt from source as the serial baud rate is hard coded into the kernel but i think it should be ok with my new arduino as its also 3.3v .


OK... After some more testing and changing the firmware I have the serial port talking to the arduio at 9600 baud and all the corruption has gone.
 

Attachments

  • ser2net.jpg
    ser2net.jpg
    168.7 KB · Views: 514
Last edited:
i have got sick of waiting for my arduino lillypad and decided to just convert my arduino pro mini to 3.3v and use it for calibrating everything.

now the ardino is talking to the router i can start connecting sensors.
 

Attachments

  • DSCF4024.JPG
    DSCF4024.JPG
    1.8 MB · Views: 640
Last edited:
i have hooked up a pair of resistors as a voltage divider and calibrated it for my 3.3v arduino,
10k LDR and 10k resistor to measure sunlight
TMP36 thermistor is working but needs better calibrated

the only thing stopping me installing this in a router just now is waiting for my current sensor.
 

Attachments

  • DSCF4026.JPG
    DSCF4026.JPG
    693 KB · Views: 465
  • DSCF4027.JPG
    DSCF4027.JPG
    1.1 MB · Views: 584
everything apart from the current sensor is now working damn slow china post.

next step is to learn about the power management on the arduino so that i can minimise its power consumption.

//volts
int batMonPin = A0; // input pin for the voltage divider
int batVal = 0; // variable for the A/D value
float pinVoltage = 0; // variable to hold the calculated voltage
float batteryVoltage = 0;


//current
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
unsigned long msec = 0;
float time = 0.0;
int sample = 0;
float totalCharge = 0.0;
float averageAmps = 0.0;
float ampSeconds = 0.0;
float ampHours = 0.0;
float wattHours = 0.0;
float amps = 0.0;


int R1 = 30000; // Resistance of R1 in ohms
int R2 = 4620; // Resistance of R2 in ohms
float ratio = 0; // Calculated from R1 / R2


//Temperature

int tempPin = A2; // TMP36 data pin
const int pinLDR = A3; // Analog Pin A0 connects across LDR

//Brightness
float valueBrightness;




//graphing
int buffer[20];
float deltaAngle = 3.14/51; //Arbitrary angle increment size
float angle = 0;
int amplitude = 100;


void setup()
{
Serial.begin(9600); // setup serial
}

void loop()
{


int data1;
int data2;
int data3;
int data4;





// Voltage Calculation

int sampleBVal = 0;
int avgBVal = 0;
int sampleAmpVal = 0;
int avgSAV = 0;
for (int x = 0; x < 10; x++){ // run through loop 10x

// read the analog in value:
sensorValue = analogRead(analogInPin);
sampleAmpVal = sampleAmpVal + sensorValue; // add samples together

batVal = analogRead(batMonPin); // read the voltage on the divider
sampleBVal = sampleBVal + batVal; // add samples together
delay (10); // let ADC settle before next 0sample

}

avgBVal = sampleBVal / 10; //divide by 10 (number of samples) to get a steady reading

pinVoltage = avgBVal * 0.00334; // Calculate the voltage on the A/D pin

ratio = (float)R1 / (float)R2;
batteryVoltage = pinVoltage * ratio; // Use the ratio calculated for the voltage divider
// to calculate the battery voltage




// temp calculaton
int reading = analogRead(tempPin); // read the input pin
float voltage = reading * 3.3;
voltage /= 1024.0;


//current monitor

float amps = 0;
for(int i = 0; i < 1000; i++) {
amps = amps + (.0264 * analogRead(A1) -13.51) / 1000;
delay(1);
}



//light dependsnt resistor

valueBrightness = map(analogRead(pinLDR),1024,10,0,100);

//uptime
msec = millis();
time = (float) msec / 1000.0;





// serial output
Serial.print("Volts = " );
Serial.print(batteryVoltage);
Serial.print("\t Current (amps) = ");
Serial.print(amps);
float watts = amps * batteryVoltage;
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(valueBrightness);

Serial.print("\t Time (hours) = ");
Serial.println(time/3600);



//Generating data that will be plotted
data1 = batteryVoltage;
data2 = watts;

data3 = temperatureC;
data4 = valueBrightness;

angle = angle + deltaAngle;

plot(data1,data2,data3,data4);

delay(100); //Need some delay else the program gets swamped with data

}

void plot(int data1, int data2, int data3, int data4)
{
int pktSize;

buffer[0] = 0xCDAB; //SimPlot packet header. Indicates start of data packet
buffer[1] = 4*sizeof(int); //Size of data in bytes. Does not include the header and size fields
buffer[2] = data1;
buffer[3] = data2;
buffer[4] = data3;
buffer[5] = data4;

pktSize = 2 + 2 + (4*sizeof(int)); //Header bytes + size field bytes + data

//IMPORTANT: Change to serial port that is connected to PC
Serial.write((uint8_t * )buffer, pktSize);





}
 

Attachments

  • graph.jpg
    graph.jpg
    192.6 KB · Views: 497
Last edited:
ok some more progress!

done some thermal testing to see if the batteries would overheat but with the 6mm depron between the panel and the batteries they are barely getting warm. then i done some cold testing by sticking the router in my freezer for a week at -20 to see the effect on the battery but it was minimal since im only using 80ma from the batteries.

external rp-sma connector is now soldered to the router.
Light Dependant resistor is now on the front of the solar panel.
Router led now mounted to the outside of the solar panel.

still to do

waiting for the damn current sensor!!
change the charger pcb since this one goes up to 4.35v which is far too high for these lipo batteries.
 

Attachments

  • DSCF4029.JPG
    DSCF4029.JPG
    911.3 KB · Views: 547
Back
Top