Arduino nano v3 Solar pwm controller

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:

void setup() {
  
}

void loop() {
  for(byte i = 0; i <= 240;i+= 10){
    analogWrite(6,i);
    delay(200);
  }  
}

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.

bigote:
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.. :slight_smile:

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

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.. :slight_smile:

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.

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

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.


I have put back the 220k to the emeter of T1 to gnd.

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.

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... :slight_smile:

bigote:
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..

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

And the print statements??

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

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

Ok great, let me try that I'm as good as blind when it comes to programming.

Let you know in a few mins.

Well did as instructed and ...
Nothing changed, I think this circuit is cursed.

any more ideas?

What values did you get on the serial monitor?

Output on the serial monitor is zero going by very quickly.

Has anyone pointed out that the pinMode is never set to OUTPUT on pin 9 [the one being used as PWM out]?

Like this:

void setup()
{
  pinMode(9, OUTPUT);   // sets the pin as output
}