Arduino Forum

Using Arduino => General Electronics => Topic started by: bigote on Jul 08, 2018, 08:48 pm

Title: Arduino nano v3 Solar pwm controller
Post by: bigote on Jul 08, 2018, 08:48 pm
Hi everybody, I'm new to this forum and to arduino as whole, but I'm pretty handy with electronics.
Ihttp://www.arduined.eu/arduino-solar-charge-controller/ wanted to build this circuit:

I build this circuit using EAGLE CAD but used the arduino nano instead of the mini that the project calls for.
here is the circuit I build:
Problem is that the circuit does absolutely nothing just sits there the led which is supposed to indicate activity remains lit and the battery remains at same voltage even when the solar input is connected and providing a higher voltage than the battery.

the only different parts I'm using is the 2 pnp transistors I'm using pn2907 instead of the 2n3906.

Thank you for your help

This is the code on the project:
const int setPoint = 13.5 * 20 / (20+82) * 1024 / 5;
 int measurement = 0;
 int pulseWidth = 0;
 int difference = 0;
 int stepSize = 0;
 int calculation = 0;
 int led = 13;

void setup() {
 TCCR2A = TCCR2A | 0x30;
 TCCR2B = TCCR2B & 0xF8 | 0x01;
 analogWrite(11, 117);
 analogWrite(3, 137);
 //  Serial.begin(9600);
 pinMode(led, OUTPUT);
 }

void loop() {
 measurement = analogRead(A1);
 calculation = setPoint - measurement;
 difference = abs(calculation);
 stepSize = difference;

 if (measurement < setPoint)
{
pulseWidth += stepSize;
if (pulseWidth > 255) pulseWidth = 255;
 analogWrite(led, 0); // pwm to LED
 }
 if (measurement > setPoint)
 {
 pulseWidth -= stepSize;
 if (pulseWidth < 0) pulseWidth = 0;
analogWrite(led, 255); // pwm to LED
}
//  Serial.println(pulseWidth);
analogWrite(9, pulseWidth);
delay(10);
}
Title: Re: Arduino nano v3 Solar pwm controller
Post by: ReverseEMF on Jul 08, 2018, 08:54 pm
Here's the schematic the OP posted:
(http://forum.arduino.cc/index.php?action=dlattach;topic=557130.0;attach=265262)

FYI: If you want to learn how to insert photos into the text [so it's easier for us to access/see it/them], read this: https://forum.arduino.cc/index.php?topic=364156.msg3749310#msg3749310 (http://"http://\"http://\\"https://forum.arduino.cc/index.php?topic=364156.msg3749310#msg3749310""")

Also, it would be nice if you read, and complied with, the following, so you know to put your code in a code block, and such: http://forum.arduino.cc/index.php?topic=149015.0 (http://"http://\"http://forum.arduino.cc/index.php?topic=149015.0"")

And, a cursory look has me puzzled about T1. I'm not so sure pin 9 can turn T1 on enough to turn Q1 on.  I would:


That way, you will get a more solid switching action, there.

Also, the transistor substitutions should be fine: 2N2222 [PN22222 would probably be better] in place of 2N3904 and 2N2907, for 2N3906.  Though, the 2N3904/6 have higher current gain at the lower currents involved.  That might be an issue for T1 in the current configuration [to busy to analyze], but the modification I suggested should make it more immune to Beta spread.

Have you checked voltages and [if you have one] thrown a scope on those PWM outputs to see if they are swinging?  Are you getting voltage multiplication at the Emitter of Q1 [what?  Around 18 to 20V?]? 

Also, you could write a test program that exercises, things like D9, and see if things are switching properly, and voltages are varying as they should.  If you don't have a scope, then this can be a good way of slowing the action down, so you can use a meter [probably won't work for the voltage multiplier], but you might, at least, be able to verify switching at T1/Q1, and get a read on A1 and send it to a Serial Terminal, etc. 
Title: Re: Arduino nano v3 Solar pwm controller
Post by: bigote on Jul 09, 2018, 01:21 am
Thank you so much for your reply
Sorry one mistake on my schematic:
T1 is actually 2N3904 not 2N2222
This is the original schematic from the project.
Many people supposedly build it succesfully.
(https://forum.arduino.cc/index.php?action=dlattach;topic=557130.0;attach=265280)

I'll try your suggestions for T1
And unfortunately I don't have a scope.
Title: Re: Arduino nano v3 Solar pwm controller
Post by: ReverseEMF on Jul 09, 2018, 03:24 am
Thank you so much for your reply
Sorry one mistake on my schematic:
T1 is actually 2N3904 not 2N2222
This is the original schematic from the project.
Many people supposedly build it succesfully.

I'll try your suggestions for T1
And unfortunately I don't have a scope.
Without a scope, troubleshooting something like this, is harder.  Try my troubleshooting suggestions, and ask if you need more help [i.e. interpretation of readings, etc.]

I'm going to be "in" off and on, so I may not respond right away, but maybe someone else will pick up the slack.
Title: Re: Arduino nano v3 Solar pwm controller
Post by: Wawa on Jul 09, 2018, 06:28 am
T1 is use as constant current source.
When it's base is high (5volt), the emitter is 4.3volt, resulting in an emitter current (and collector current) of
4.35volt/220k = ~20uA.
That drives the base of T2 with ~17uA.
That results is a collector current of ~5mA (assuming β=300).
That drives the gate with 5mA.
T3 pulls the gate low when T2 is not conducting.

Not wise to use e.g. the 2N2222 here (lower gain).

The whole circuit depends on the voltage doubler generating a higher voltage than Vbat on C7.
Measure that first.
Leo..
Title: Re: Arduino nano v3 Solar pwm controller
Post by: ReverseEMF on Jul 09, 2018, 07:09 am
The whole circuit depends on the voltage doubler generating a higher voltage than Vbat on C7.
Measure that first.
It occurs to me, bigote, if your meter has a low internal impedance, it might load down that voltage, and provide a false reading.  For instance, a 1MΩ meter will, likely, give a reading that is lower than the actual voltage.  A 10MΩ meter will get it nearly right.
Title: Re: Arduino nano v3 Solar pwm controller
Post by: bigote on Jul 09, 2018, 09:03 pm
Thanks to you guys for keeping up with me.
Wawa as I explained on my second post that is a typo on the schematic for T1 I'm using 2n3904 NPN same as 2n2222 but different pinout I also tried another transistor H9013 with same characteristics and the same results, no output from D9.
I did some testing with the PWM and POT sketch, and I can confirm the reading on the output pin using my tester so I know it works.
I'm using the popular Unity 139C multimeter.

thanks again
Title: Re: Arduino nano v3 Solar pwm controller
Post by: ReverseEMF on Jul 09, 2018, 10:21 pm
... and the same results, no output from D9.
I did some testing with the PWM and POT sketch, and I can confirm the reading on the output pin using my tester so I know it works.
Did I miss something?  I looked back at previous posts, and can't find a reference to what you're saying.  
So, there's no output from D9?  I'm lost  :P
Title: Re: Arduino nano v3 Solar pwm controller
Post by: bigote on Jul 10, 2018, 02:14 am
Yes D9 remains @ 0 volts or very close to that. I even removed the transistor completely to measure this.
So I wonder could it be a software problem, knowing nothing about programming it would be impossible for me to spot the error if any.
regards and sorry about late reply

I did remove the 220k from T1 emitter and connected it directly to ground.
Title: Re: Arduino nano v3 Solar pwm controller
Post by: Wawa on Jul 10, 2018, 02:28 am
The output of D9 depends on battery voltage, so what is the voltage on C3.
And how much higher is the voltage on C7 (has been asked to measure that before).
Leo..
Title: Re: Arduino nano v3 Solar pwm controller
Post by: bigote on Jul 10, 2018, 03:38 am
Thanks Wawa, the battery voltage is @ 12.8 volts small 12v 7AH sla batt.
It looks like part of the circuit is working voltage @ C7 is 14.5 and at D4-C2 point the voltage is 17 volts.
Yet at pin D9 absolutely nothing.
feel free to ask any other measurements.
Title: Re: Arduino nano v3 Solar pwm controller
Post by: FredScuttle on Jul 10, 2018, 04:02 am
If you connected emitter straight to GND you probably blew it AND D9.
Title: Re: Arduino nano v3 Solar pwm controller
Post by: Wawa on Jul 10, 2018, 05:19 am
Oops, I see you have named the parts differently from the original diagram.
That will lead to confusion.
C7 (electrolytic, 10uF) in the old diagram (C2 in yours) should at least be 10volt higher than Vbatt.

R8 in your diagram should be 1-10k (not 220k), so you can actually see the LED.

The 7812 is a poor choice.
1) An 78xx is not low dropout, and needs at least 2volt across to regulate properly. 12.8 - 12 is only 0.8volt.
2) The Nano is rated  for 7-12volt, but people had clones blown up with 12volt.
Could use an LM7808, or an LM7805 and connect directly to the 5volt pin (like in the original diagram).

Add some print statements, so you can see what is written to D9.
Leo..

Title: Re: Arduino nano v3 Solar pwm controller
Post by: allanhurst on Jul 10, 2018, 09:51 am
1/

I see nowhere in the code where you set D9 to be an output:
You have to add pinMode( 9,OUTPUT); in the setup() part of your code. Otherwise you can't write to it.

Ditto for pins 11 and 13.

2/ I'd put a 1K between D9 and the base of T1 and ground it's emitter.

Allan
Title: Re: Arduino nano v3 Solar pwm controller
Post by: Wawa on Jul 10, 2018, 10:02 am
Code source. (https://codebender.cc/sketch:331107#Arduino%20PWM%20Solar%20Charge%20Controller.ino)
No pinMode calls in setup()... :o

2/ I'd put a 1K between D9 and the base of T1 and ground it's emitter.
That could fry the base of T2, and/or load down the voltage doubler.
As said (post#4), T1 is used as constant 20uA current sink.
Leo..
Title: Re: Arduino nano v3 Solar pwm controller
Post by: allanhurst on Jul 10, 2018, 10:36 am
Then add a 10k in series with it's collector as well.


20uA seems very small even with the gain of T2 if you want to switch a big MOSFET reasonably quickly - 3-5nF gate capacitance or more ?

suppose the gain of T2 is 100 - optimistic. Then the turn on current is only 2mA.

this means that with 5nF  I =  C dV/dT -> 0.4 V/uS, and to traverse 10 volts will take 25uS.

Pretty slow.

At 1kHz PWM this means  50uS spent in transitions per 1ms cycle or  5% of the time - a significant loss.


Allan
Title: Re: Arduino nano v3 Solar pwm controller
Post by: Wawa on Jul 10, 2018, 11:56 am
D9 is ~500Hz PWM, so one transistion per 1ms.
And from non-conducting to almost fully conducting is not the full 10volt
But there is indeed some loss there.
If that's a problem or not depends on the output power of the panel.

Gate current(s) could be increased by lowering the value of R5 and R3 to say 100k.
And maybe removing (short) R2. (Parts numbers of OP's diagram).
Needed or not depends on the gate charge of the actual mosfet used.
Leo..

Title: Re: Arduino nano v3 Solar pwm controller
Post by: FredScuttle on Jul 10, 2018, 08:05 pm
I believe the analogWrite function takes care of pinModeing the target pin, but, does the pin return to input after the analogWrite is finished?
This works on a Pro Mini:
Code: [Select]
void setup() {
 
}

void loop() {
  for(byte i = 0; i <= 240;i+= 10){
    analogWrite(6,i);
    delay(200);
  } 
}
Title: Re: Arduino nano v3 Solar pwm controller
Post by: pwillard on Jul 11, 2018, 02:35 pm
Changing a PINMODE is handled by the Analogwrite() function... but once set... it leaves it that way.  It will not change back to default  INPUT mode when the function call is completed.
Title: Re: Arduino nano v3 Solar pwm controller
Post by: TomGeorge on Jul 11, 2018, 04:22 pm
Yes D9 remains @ 0 volts or very close to that. I even removed the transistor completely to measure this.
So I wonder could it be a software problem, knowing nothing about programming it would be impossible for me to spot the error if any.
regards and sorry about late reply

I did remove the 220k from T1 emitter and connected it directly to ground.
When you did this, was a base resistor fitted to the transistor?
If you did not have a base resistor fitted, then you could have damaged the pin9 output because the 0.6V Vbe of T1 would have clamped the output pin when it was trying to output 5V.

Modify your code to control another unused PWM pin on the Nano and try it with T1 removed.
Have you made a PCB for this project?
Can you post an image of the CAD for the PCB?

Thanks.. Tom.. :)
Title: Re: Arduino nano v3 Solar pwm controller
Post by: bigote on Jul 11, 2018, 08:43 pm
Hi Tom and thanks for your interest in helping me.
No there is no resistor between D9 and T1, but I don't think it has been damaged.
Yes I did build this circuit as a etched pcb that's why it's so difficult to make changes.
I'll try running the blink led sketch on pin 9 just to make sure it still ok.
I'll be right back with this info.
regards
Title: Re: Arduino nano v3 Solar pwm controller
Post by: TomGeorge on Jul 11, 2018, 11:49 pm
Hi,
Can you post an image of the PCB pattern please?
Eagle should have the provision for you to save/export a jpg of the pattern so you can post it into this thread.

Thanks.. Tom.. :)
Title: Re: Arduino nano v3 Solar pwm controller
Post by: bigote on Jul 12, 2018, 12:11 am
Ok I can confirm the arduino board is fine, I run the blink sketch on pin D9 and wit works fine 0-5 volts reading on my meter. I'll upload the image you're asking in a few minutes i'm not on my main pc now.

So the question remains why there is no activity on D9 when running the actual pwm sketch.
Title: Re: Arduino nano v3 Solar pwm controller
Post by: Wawa on Jul 12, 2018, 12:29 am
I think I already explained that in post#9.
The question was not answered.

The whole circuit is a closed loop.
The circuit measures battery voltage, and adjusts the PWM value to that.
If battery is higher than "setpoint", then charging stops.
Leo..
Title: Re: Arduino nano v3 Solar pwm controller
Post by: bigote on Jul 12, 2018, 12:43 am
Thanks Leo but it is my understanding that charging should stop @ 13.6 not @ 12.8.

Here is a fixed typos on my schematic. and pcb that Tom ask for.


(https://forum.arduino.cc/index.php?action=dlattach;topic=557130.0;attach=265672)
(https://forum.arduino.cc/index.php?action=dlattach;topic=557130.0;attach=265674)

I have put back the 220k to the emeter of T1 to gnd.
Title: Re: Arduino nano v3 Solar pwm controller
Post by: allanhurst on Jul 12, 2018, 02:07 am
There is inherent inaccuracy of the measurement of the battery voltage.

1/ The resistors used in the divider chain. What tolerance are they?

2/ The  voltage reference itself.

Suggest you measure with an accurate voltmeter the actual voltage, and use eg serialWrite to see what adc reading you get.

Adjust constants in sw to get the correct value.

Allan

ps With a few extra components and different sw you could make this into a MPPT controller for better efficiency - but get the basic system working first.
Title: Re: Arduino nano v3 Solar pwm controller
Post by: TomGeorge on Jul 12, 2018, 02:11 am
Hi,
Thanks for the images.

You need C3 and C4 mounted as close as possible to the 7812 pins, also a 0.1uF capacitor in parallel with them, again a close as possible to the 7812 pins.

Increase your track widths, the less copper you have to remove the better, you bought that copper with the blank PCB, why etch most of it away.

I would be adding some tell-tail LEDs to vital control wires so you don't have to DMM probe all the time.
When its up and running, you just don't solder the LEDs into the PCB.

Tom... :)
Title: Re: Arduino nano v3 Solar pwm controller
Post by: Wawa on Jul 12, 2018, 03:08 am
Thanks Leo but it is my understanding that charging should stop @ 13.6 not @ 12.8.
Charging stops when the returned A/D value of the analogue pin is higher than setpoint (542).
And that depends on more than one thing.
Battery voltage, how accurate is the voltage divider, and how accurate is VCC of the Nano.

Post#12: Add some print statements, so you can see what is written to D9.
Leo..
Title: Re: Arduino nano v3 Solar pwm controller
Post by: bigote on Jul 12, 2018, 10:03 pm
Hey guys thanks for sticking with me.

Both R6-R7 sensing resistors are 1% and the actual voltage @ A1 pin is 2.683
Battery voltage now is @ 12.7 obviously not fully charged.
I don't think there are any p/s issues as the arduino's integrated regulator is doing a good job providing 5.0 volts.
If anyone has a better design, I'm ready to scrap this one and move on.
I choose this one only because it seemed like a proven tried and true design which apparently many people had already build.
So I'm all ears, I'm not interested in those complicated designs with lcd display etc.
All I want is something simple that can fit on a small pcb like the one shown above.

Thanks again
Title: Re: Arduino nano v3 Solar pwm controller
Post by: Wawa on Jul 12, 2018, 11:06 pm
And the print statements??
Title: Re: Arduino nano v3 Solar pwm controller
Post by: bigote on Jul 12, 2018, 11:52 pm
Sorry Leo, like I said I know absolutely nothing about programming.
So I have no idea how to do that.
Do you mind telling me how to do it?
Chears
Title: Re: Arduino nano v3 Solar pwm controller
Post by: Wawa on Jul 13, 2018, 12:07 am
Wow, need to go through some of the examples in the IDE to fix that.

There are two lines in the code you posted that are needed to print what the program is doing.
They are currently commented out (lines not used) with double slashes.
// Serial.begin(9600);
// Serial.println(pulseWidth);

Remove the // from those two lines, and re-upload the sketch.
The serial monitor will now print a stream of pulseWidth values (0-255), that are written to D9.
0 is not charging, 255 is max charging.
Report back.
Leo..
Title: Re: Arduino nano v3 Solar pwm controller
Post by: bigote on Jul 13, 2018, 01:05 am
Ok great, let me try that I'm as good as blind when it comes to programming.

Let you know in a few mins.
Title: Re: Arduino nano v3 Solar pwm controller
Post by: bigote on Jul 13, 2018, 01:28 am
Well did as instructed and ...
Nothing changed, I think this circuit is cursed.

any more ideas?
Title: Re: Arduino nano v3 Solar pwm controller
Post by: Wawa on Jul 13, 2018, 01:40 am
What values did you get on the serial monitor?
Title: Re: Arduino nano v3 Solar pwm controller
Post by: bigote on Jul 13, 2018, 03:39 am
Output on the serial monitor is zero going by very quickly.
Title: Re: Arduino nano v3 Solar pwm controller
Post by: ReverseEMF on Jul 13, 2018, 03:58 am
Has anyone pointed out that the pinMode is never set to OUTPUT on pin 9 [the one being used as PWM out]?

Like this:

Code: [Select]
void setup()
{
  pinMode(9, OUTPUT);   // sets the pin as output
}
Title: Re: Arduino nano v3 Solar pwm controller
Post by: Wawa on Jul 13, 2018, 04:33 am
Has anyone pointed out that the pinMode is never set to OUTPUT on pin 9 [the one being used as PWM out]?
Yes, post#13-17.
AnalogWrite apparently sets the pin to OUTPUT.
Didn't know that and wasn't sure until I tested the program on a Nano.
Leo..
Title: Re: Arduino nano v3 Solar pwm controller
Post by: Wawa on Jul 13, 2018, 04:42 am
Output on the serial monitor is zero going by very quickly.
That could mean that the voltage on A1 is more than ~2.6volt.
Measure it, and double-check the values of the resistors of the voltage divider on that pin.
Or use this sketch that prints the value of A1 and D9.
Report back.
Leo..
Code: [Select]
const int setPoint = 13.5 * 20 / (20 + 82) * 1024 / 5;
int measurement = 0;
int pulseWidth = 0;
int difference = 0;
int stepSize = 0;
int calculation = 0;
int led = 13;

void setup() {
  TCCR2A = TCCR2A | 0x30;
  TCCR2B = TCCR2B & 0xF8 | 0x01;
  analogWrite(11, 117);
  analogWrite(3, 137);
  Serial.begin(9600);
  pinMode(led, OUTPUT);
}

void loop() {
  measurement = analogRead(A1);
  Serial.print(measurement);
  Serial.print("\t");
  calculation = setPoint - measurement;
  difference = abs(calculation);
  stepSize = difference;

  if (measurement < setPoint)
  {
    pulseWidth += stepSize;
    if (pulseWidth > 255) pulseWidth = 255;
    digitalWrite(led, LOW); // LED off
  }
  if (measurement > setPoint)
  {
    pulseWidth -= stepSize;
    if (pulseWidth < 0) pulseWidth = 0;
    digitalWrite(led, HIGH); // LED on
  }
  Serial.println(pulseWidth);
  analogWrite(9, pulseWidth);
  delay(10);
}
Title: Re: Arduino nano v3 Solar pwm controller
Post by: bigote on Jul 13, 2018, 03:51 pm
Very good Leo.
I'll try your sketch when I get back from work.
Battery volts now is:12.7 and @ A1 stands at 2.681
Maybe I've got defective resistors, those are quite hard to get here where I live, I will try to get new ones today.
Thanks
Luis
Title: Re: Arduino nano v3 Solar pwm controller
Post by: ReverseEMF on Jul 13, 2018, 05:59 pm
Battery volts now is:12.7 and @ A1 stands at 2.681
Maybe I've got defective resistors, those are quite hard to get here where I live, I will try to get new ones today.
Depends on the tolerance of those resistors.
At 1%:

R#NomLowHigh
R682k081k282k8
R720k019k820k2


The formula for calculating the  A1 voltage [the voltage across the 20k resistor], if we call the 82k resistor R6, and the 20k resistor R7, and the Battery Voltage VB:

VA1 = VBR7/(R6 + R7)

And to get the Highest voltage possible, due to tolerance variation, we take the lowest possible resistance for R6 and the highest resistance for R7, like this:

VA1(max) = 12.7(20.2)/(81.2 + 20.2) = 2.53V

Which is lower than your measured value of 2.681V

BUT

Let's say your resistors are 5%.  Then it would go like this:

R#NomLowHigh
R682k077k986k1
R720k019k021k0


VA1(max) = 12.7(21.0)/(77.9 + 21.0) = 2.70V

Which is greater than 2.681V, so definitely in the valid range.


Which means, not defective.  But, merely a case of insufficient precision.
Title: Re: Arduino nano v3 Solar pwm controller
Post by: bigote on Jul 13, 2018, 08:51 pm
Ok I run the code and I get 547 on the serial monitor.
I see no reference to output D9
I even desolder the  resistors and measure:
82k shows 81.8 and 22k measures 21.94 both 1% blue type
pretty good I'll say since I got them from the junk bin.
regards
Title: Re: Arduino nano v3 Solar pwm controller
Post by: Wawa on Jul 13, 2018, 10:40 pm
22k?

The code and the diagrams show a 20k resistor.

If you use 22k, then the charger assumes a 12.7volt battery is full.

Leave the 22k resistor in, and change the first line in the code to:

const int setPoint = 13.5 * 22 / (22 + 82) * 1024 / 5;

Leo..
Title: Re: Arduino nano v3 Solar pwm controller
Post by: bigote on Jul 13, 2018, 11:19 pm
You know, I think you just found the problem.
I don't know how I could have made such mistake, but you know how it is sometimes it takes someone looking at the problem from the outside.

Le me try that again, be back shortly
Title: Re: Arduino nano v3 Solar pwm controller
Post by: bigote on Jul 14, 2018, 12:11 am
Ok Leo, thanks to you I think I made some progress.
I replaced the 22k for a 20k and now @ A1 I get 2.485 volts
and the output @ D9 is 5 volts.
Reading on the serial console shows

507               255

So I guess its working right?

Only problem I see now is battery voltage does not seem to be going up, I have a regular walwart 16 vdc simulating solar panel for now.
Title: Re: Arduino nano v3 Solar pwm controller
Post by: Wawa on Jul 14, 2018, 12:29 am
A solar panel is a current source, and you're replacing it with a voltage source.
The 16volt supply might shut down when connected (with the mosfet) to a 12.7volt load.

Post the three voltages on the mosfet.

I also would like to know how much that voltage booster is generating.
So the difference between battery voltage and voltage on C2 (the diagram in post#1).
Leo..
Title: Re: Arduino nano v3 Solar pwm controller
Post by: bigote on Jul 14, 2018, 02:06 am
Ok I think I solved that problem (bad mosfet) it seems to be charging now, albeit slowly
Battery just hit 13 volts, I just tried it with a 2 amp 18 volt p/s and mosfet got really hot real fast.
I'm gonna have to get a low RDS mosfet like the one on the original project, problem is living in the third world you don't always have access to parts so you have to hunt in the garbage bin for them.

I wanna thank everyone who reply to this thread specially you Leo and Allan and also ReverseEMF.
Thank you all so much, I'll keep checking in just in case you have any other question.

Happy now
Title: Re: Arduino nano v3 Solar pwm controller
Post by: Wawa on Jul 14, 2018, 02:38 am
You might have to play with that setpoint line to get final float charge voltage right (13.5 for sealed SLA).
I would just replace the first line in the code with:

const int setPoint = 542; // 542 should be about 13.5volt

And adjust the value proportionally if needed.

Mosfets are ESD sensitive. You might have damaged it by handling/soldering.
Short all the pins together before soldering (by weaving a bare/thin wire through it's legs).

Things that heat up mosfets are Rsd(on) and switching losses.
A mosfet with a lower Rsd(on) and higher gate charge might make things worse,
since you have very little drive current available.
Which mosfet are you using now.

And, as said, you shouldn't use a constant voltage supply to charge a constant voltage supply.
Use at least a current limiting resistor in the +line of the supply.
A 12volt/20watt car brake lightbulb can be used for that.
Leo..
Title: Re: Arduino nano v3 Solar pwm controller
Post by: bigote on Jul 14, 2018, 03:25 am
All your points are well taken.
The mosfet I'm using now is the IRF530 which has an RDS of 0.16 Ohm which is very high compared  to the IRF3205 that the original project calls for that has only 8 mOhm resistance therefore doesn't even need a heatsink (according to the designer) but that's fine as this is like the proof of concept for me, later I'll rebuild it with better parts.

Again thank you very much.

Luis
Title: Re: Arduino nano v3 Solar pwm controller
Post by: TomGeorge on Jul 14, 2018, 08:47 am
Hi,
Have you got the blocking diode D7 in the original circuit fitted, or is it in the PV array?

You need it to stop the battery discharging back thought your Q3, especially if Q3 is fitted with a protection doide/zener.

Also measure the voltage at the positive of your C2, make sure it is high enough above the battery positive to bias your Q3 fully ON.

Tom... :)
Title: Re: Arduino nano v3 Solar pwm controller
Post by: bigote on Jul 14, 2018, 10:29 pm
Good point Tom, I decided not to include the blocking diode on the pcb as this almost always go on the solar panel itself, voltage @ C2 is always above 16 volts so I guess I'm good there.
One more thing i wanted to mention if someone cares to elaborate on is:
I might wanna build this circuit for a 24 volt system how would the math change for such application.
Everything else component wise on the circuit is rated for at least 50 volts, so the only difference should be in software.
I'll appreciate anyone commenting
Thanks a bunch.
Luis
Title: Re: Arduino nano v3 Solar pwm controller
Post by: Wawa on Jul 14, 2018, 10:46 pm
voltage @ C2 is always above 16 volts so I guess I'm good there.
I have asked this several times.
What is important is the DIFFERENCE between battery voltage and the voltage on C2.
So your black meter lead goes to battery(+) and your red meter lead goes to C2(+).
You should at least have 7volt difference.

I think all you need for 24volt is to change the 82k resistor of the voltage divider.

Losses in the voltage regulator go up, so it might be wise to use a tiny switching buck regulator, set to ~7volt.
Leo..
Title: Re: Arduino nano v3 Solar pwm controller
Post by: bigote on Jul 15, 2018, 12:01 am
Yes I thought the same thing 78x would generate way too much heat and loss so one of those LM2596 modules from ebay will do fine, I've use a few and they work great.
But the real challenge for me is the exact formula in the software as well as the values for the voltage divider.

Luis

Title: Re: Arduino nano v3 Solar pwm controller
Post by: Wawa on Jul 15, 2018, 12:47 am
LM2596 is old generation, big current, but ok to use.
There are much smaller buck converters on ebay that are more efficient at low current.

The resistor values of the divider are not that critical, because the code compensates.
(tried to tell you that with the 22k resistor)

The designer used 20k:82k for a float (fully charged) voltage of 13.5volt.
That results in a voltage on the Arduino pin of 20/(20+82)*13.5 = ~2.65volt.

The code uses those resistor values to calculate "setPoint" (first line).
const int setPoint = 13.5 * 20 / (20+82) * 1024 / 5;

So about 2.65volt most also fall across the 20k resistor for a 24volt system (27volt float).
And 27-2.65 = 24.35volt must fall across the top resistor.
That's 24.35/2.65 times more than the 20k resistor = 183.77k

We are going to try a 20k:180k divider.
Tap = 20/(20+180)*27 = 2.7volt (about right).

Setpoint line becomes:
const int setPoint = 27.0 * 20 / (20+180) * 1024 / 5;

Leo..
Title: Re: Arduino nano v3 Solar pwm controller
Post by: bigote on Jul 15, 2018, 12:55 am
Very good Leo I think that's a good start, I'll try that in the next few days and see how it goes.

I'll be sure to let u know.

thanks
Title: Re: Arduino nano v3 Solar pwm controller
Post by: TomGeorge on Jul 15, 2018, 02:42 am
Good point Tom, I decided not to include the blocking diode on the pcb as this almost always go on the solar panel itself, voltage @ C2 is always above 16 volts so I guess I'm good there.
One more thing i wanted to mention if someone cares to elaborate on is:
I might wanna build this circuit for a 24 volt system how would the math change for such application.
Everything else component wise on the circuit is rated for at least 50 volts, so the only difference should be in software.
I'll appreciate anyone commenting
Thanks a bunch.
Luis

What MOSFET are you using, and that 16V means you only have 16 - 13.8 = 2.2V for gate potential when charged, to16 - 12.0 = 4.0V when battery is low.


That is not enough to turn the MOSFET, even a logic level, fully ON.

Can you post the code you are using now please?

Tom... :)
Title: Re: Arduino nano v3 Solar pwm controller
Post by: TomGeorge on Jul 15, 2018, 02:54 am
Hi,

Code: [Select]
void setup() {
  TCCR2A = TCCR2A | 0x30;
  TCCR2B = TCCR2B & 0xF8 | 0x01;
  analogWrite(11, 117);
  analogWrite(3, 137);
  Serial.begin(9600);
  pinMode(led, OUTPUT);
}

You are connected in the schematic to A3 instead of D3......
A3 is not a PWM output connected to the timer.

Look at the original schematic;
(http://forum.arduino.cc/index.php?action=dlattach;topic=557130.0;attach=266064)
Tom.... :)
Title: Re: Arduino nano v3 Solar pwm controller
Post by: Wawa on Jul 15, 2018, 04:08 am
Good catch Tom.
That means that the boosted voltage is ~4volt less than it should be.
That will heat up the non logic fet OP is using (IRF530), and reduce charging current.

Have been asking for this voltage many times...
Leo..
Title: Re: Arduino nano v3 Solar pwm controller
Post by: bigote on Jul 15, 2018, 07:26 pm
There you go Tom, another one of my newby mistakes, as I'm not very familiar with arduino pinouts.
The other problem is I was following 2 guides the one on my first post and also this one by Adam Welch:http://adamwelch.co.uk/2015/11/arduino-pwm-solar-charge-controller/ (http://adamwelch.co.uk/2015/11/arduino-pwm-solar-charge-controller/)

He made a few changes including the addition of the pulsing led connected to D5, which I also put in my eagle schematic, but in my board is not working I'm also using his version of the code.

Let my try re rewire tha A3 line to D3 and see what happens

Title: Re: Arduino nano v3 Solar pwm controller
Post by: bigote on Jul 15, 2018, 08:04 pm
As usual you guys are right again, the voltage now @ C2 is 21.4 and its charging fine.
Any idea why my led doesn't work? it just sits off no activity except it blink son startup.
The code is on the link of my previous post.
Luis
Title: Re: Arduino nano v3 Solar pwm controller
Post by: bigote on Jul 15, 2018, 11:27 pm
Ok  after the A3 to D3 fix the led seems to be working as well, it's just not what I was expecting.
I thought i was supposed to blink while charging and come to full lit when charged, but what it does is:
When battery is low the led would be off and as it becomes fully charge the led will proportionally lit.

Thank you all for all your wonderful support!

Luis