Author Topic: Control for heating with solar off grid no batteries  (Read 25317 times)

0 Members and 1 Guest are viewing this topic.

ontfarmer

  • Full Member
  • ***
  • Posts: 124
  • Country: ca
Control for heating with solar off grid no batteries
« on: July 10, 2016, 05:59:37 PM »
Put up solar panels with heating water planned. I have had a lot of help from the members
of the forum.
Planning on putting the controller together have capacitors, mosfets, opto isolater,resistors,
diodes, arduino.  to use for PWM control.
Will let you know how it goes.

OperaHouse

  • Hero Member
  • *****
  • Posts: 1064
  • Country: us
Re: Control for heating with solar off grid no batteries
« Reply #1 on: July 13, 2016, 09:29:01 AM »
Where to start......
The voltage of the solar array will have to be monitored.  Here is a way to easily calculate
the values for the voltage divider.  Determine the maximum voltage the divider will see using
the total open circuit voltage of the panels.  Lets say that is 140V.  Choose a common resistor
value for the lower resistor R2 of 22K.  The A/D value can be easily multiplied in the micro
by a whole number, avoid floating point math in a micro.  That calculation can get you close.
Adding a pot between R1 & R2 will allow you to adjust the A/D value slightly to get the calculated
voltage spot on. If you only have a 25,50 or 100K pot, a 5K or higher resistor in parallel can
reduce the effective resistance to 5K.  With the pot set to mid position, that adds 2.5K to the
value of R2 for a total of 24.5K ohms.  We are setting the max value the A/D will see at 4V to
give some safety margin.  There are 35 four volts in 140V.  One of those 4V is across R2.  That
leaves 34 four volts on R1.  24.5K times 34 gives 833K for R1.  A standard value for R1 is 820K.
I suggest a couple resistors in series to prevent flash over or a single 1W resistor. A capacitor
of .1uF at the A/D input provides noise protection and a stable low impedance for the A/D converter.


If you have at least a 36V array, the best way to power the micro is with electronic wall warts.
The most common is the 5V used for cell phones. I have a local thrift store that sells them for
29 cents each.  I use them all over my system to power meters.  They are electrically isolated
and if they fail they won't destroy your electronics like non isolated step down converters.  I
love those $2 ebay 2596 converters but won't use them anywhere near their voltage or current
ratings. Two 5V wall warts can be used in series to make 10V to supply the UNO board. An additional
5V unit in series will supply 15V for the FET driver electronics.

ontfarmer

  • Full Member
  • ***
  • Posts: 124
  • Country: ca
Re: Control for heating with solar off grid no batteries
« Reply #2 on: July 17, 2016, 08:32:27 AM »
   The wheat harvest is now done. Hope to get back to this project.

Very impressed with the detailed  instructions and diagram that you done in terms
l can understand.
 
  Will make it possible for me to put this together.

Thanks


OperaHouse

  • Hero Member
  • *****
  • Posts: 1064
  • Country: us
Re: Control for heating with solar off grid no batteries
« Reply #3 on: July 21, 2016, 09:31:33 AM »
The schematic shows how to connect three 5V electronic wall warts.  It is a good idea to add an
extra capacitor for surge capacity and maintain voltage during momentary dropouts. It is suggested
tat a diode be used ot isolate the solar panels from the capacitor bank to prevent current back
flow. Use a diode for each series string prevents back feed form other panel strings and allows
you to use smaller cheaper diodes.  Remember that once the capacitor bank voltage drops below
the set point of the micro, the current draw stops except for the bleed resistor on the capacitor
bank.  Even new capacitors will need some forming before rated currents are drawn.  VFD motor drive
instructions suggest that the unit be powered up for 24 hours before the motor is operated.  This
would be a good idea for this capacitor bank too.  Use the array to power it for a day or power up
with line voltage.

A convenient way to get signals in and out of the board is with these Dupont leads. 
http://www.ebay.com/itm/40PCS-Dupont-Wire-Color-Jumper-Cable-2-54mm-1P-1P-Male-to-Female-20cm-WC-/172024782427?hash=item280d79de5b

Buying the male and female leads allows me to cut them in half and also use them with pin headers.  Following resistor number color codes for the wires makes it easy to identify input and outputs, input1 would be a brown wire.
« Last Edit: July 21, 2016, 01:15:57 PM by OperaHouse »

ontfarmer

  • Full Member
  • ***
  • Posts: 124
  • Country: ca
Re: Control for heating with solar off grid no batteries
« Reply #4 on: July 25, 2016, 05:21:42 AM »
Picked up resistors, pot, capacitors, diodes, soldered them together I have  male and female leads.

Was  able to get old TV, PC from a drop off have to get the 5 volt wall warts.

Look forward to your reply.












OperaHouse

  • Hero Member
  • *****
  • Posts: 1064
  • Country: us
Re: Control for heating with solar off grid no batteries
« Reply #5 on: July 25, 2016, 08:07:51 AM »
This general post I had ready.  Will PM you some working software to get you started.  Sent, let me know if you got it.

One thing you will likely want to do is some data logging.  There is no need for added displays.In the Arduino software there is a TOOLS page.  Just select Serial Monitor and you can read out any data stored in active memory through the USB port onto your laptop.  In your software just use the print functions for data and to format the screen with labels.  This is not permanent memory as it will be lost when power is removed.  It is also erased every time the USB port is plugged in as that automatically sends a RESET to the micro. That problem can be worked around by putting an electrolytic capacitor from the RESET (+ of capacitor) to the GND pin of the micro.  I use a 100uF, but it probably works with a 4.7uF.  This works with all the variations of this board.  The photo shows this capacitor along with the Dupont pins and resistor leads making connections to the board. 

A power meter can be easily included in the software. In many cases the voltage will be fixed.  Since the resistance doesn't change, the power is proportional to the PWM number sent to the FET driver.   Feeding that through a 4.7K resistor to a 10uF capacitor will give a proportional voltage of 0-5V of the PWM. There are many small LED meters that can be purchased on ebay for under $2. Make sure the meter has at least two decimal places. A pot can be used to cal in the meter.  Choose at least 100K pot  to put as little loading on the capacitor as possible. Multiple data values can be displayed using a LED to identify what units they are such as peak wattage.
 
This averaging method can also be done across the heater element and it will read out the actual average heater voltage. Adjusting the voltage sense pot for the maximum voltage is the best way to determine the power point voltage.

Mounting the UNO can be a problem. Some have three mounting holes, some have none. Clearance is very tight and you are likely to short out or damage the board with metal hardware .  I have always used a slice of dense packing foam and just hot melt it to a surface. There are snap in mounts for the UNO that cost more than the board.  Go cheap and easy. 

The software isn't hard to calculate daily power.  Just add the PWM value every six minutes to the DAILY variable.  Over a day that number will likely stay under 16K The UNO has a convenient MAP function that will do the conversion for you into a 0-255 value that the PWM port can take.

               meter = map(DAILY, 0, 9180, 0, 255);

Maximum PWM = 255,  255 X 6 readings a hour = 1530 counts, 1530 counts/hr X 6 hours = 9180 counts

This falls well under the 16K limit. If you expect power to be lower, you could double the number of readings each hour.  Just choose some number of hours that will give you a realistic value for the day.  Use the power point voltage the capacitor bank runs at to obtain the maximum wattage
that could be obtained from the heater at 100% duty cycle.

Wattage at maximum set voltage = 820W X 6 hours = 4.92KWH

The maximum voltage out for the PWM is almost 5V averaged. This matches up closely with the values in the example.  0-2V, 0-3V, 0-10V and 0-20V meters are common. A resistor voltage divider can be used then to obtain voltages under 5V.  Values over 5V (5KWH) can't be obtained unless an op amp is used to multiply the voltage.





« Last Edit: July 25, 2016, 08:37:39 AM by OperaHouse »

OperaHouse

  • Hero Member
  • *****
  • Posts: 1064
  • Country: us
Re: Control for heating with solar off grid no batteries
« Reply #6 on: July 27, 2016, 02:04:44 PM »
Couldn't find a way to load the sketch file directly into the PM. You will have to copy it
into a new sketch.  The email word processor sorta clobbers it a bit with some comments ending
up on a new line. The compiling will stop at those lines as an error. Initial software can be
tested by connecting the pot to the 3.3V pin of the micro.  The transition from counting up to
counting down will probably happen with A0 at 3.0-3.1 volts at the input.  The Serial screen
in TOOLS will display the raw count and the number sent to the PWM.  The counting is slowed
down on purpose.  You will see at the two extremes the count will vary from PWM output.  This is
to prevent narrow pulses that would only result in FET heating.

The analog voltage signal is pin A0 and the PWM signal to drive the opto isolator is pin 3. The
opto isolator provides a simple way to do voltage level shifting  and isolation.  A blown FET
can never destroy the micro and the FET and capacitor bank can be as close to the heating as
possible with the controller being 100 feet away. A LED is in series with the drive and
provides an indication of drive being present. If you have 13.5 or 15V there will still be
enough voltage after subtracting the LED voltage to drive the FET.  Opto isolators are slow but
fast enough at 490Hz. The waveforms I have observed are quite clean.  The slow transition pretty
much eliminates inductive problems. I have no heating problems at 52V and doubt your supply at
over 100V will either. What FET did you choose?  A 10-20 ohm gate resistor is optional when
using multiple FET. Most often when a FET fails the Gate will short out.  This makes it easier
to figure out which FET is shorted as the bad one will have the lowest resistance to common.
I don't use them as the system already has enough resistance in it. I use a RC snubber across
the FET to eliminate any possible noise.  Your PC power supply will have at least two of these
on the AC coming in.  These X rated capacitors are suitable for the continuous surges.  Use a
15-47 1W power resistor in series.  Capacitor value is not that critical.

The first testing of the drive should be done with only one bank of capacitors and one or two
100W light bulbs. This will keep you out of extreme current conditions that might destroy things.
Available current from solar panels quickly drops off as you approach maximum panel voltage.
There will likely be enough range in the adjustment pot to hit maximum voltage and operate the
PWM mid level with just a single lamp.  If not reduce the number of panel strings connected for
the test.   The on board LED (Pin 13) will flash according to power level.  There is always a
single flash to indicate the program is working.  Then it will flash up to eight times (I think)
to indicate power level before a pause.  The TX and RX LED will flash as data is sent to the
laptop when connected.  If that all works, the other capacitor banks can be connected.  These
will be lethal voltages so wait for the voltage to drop with a voltmeter before connecting.
Breakers or light switches can be used as disconnects.  While not rated for DC, when turned off
the voltage potential across the contacts from the capacitor bank will not be that great.





ontfarmer

  • Full Member
  • ***
  • Posts: 124
  • Country: ca
Re: Control for heating with solar off grid no batteries
« Reply #7 on: July 27, 2016, 06:59:00 PM »
Just got in been a busy day. Hope to work on this tomorrow. The 3 FET I got is IRFP250NPBF
 200V  30A    Phototransitors  60Ma  30V    The ones out of old TV RF 2001 200V  20A

Thanks for the details. I will send PM to you.

ontfarmer

  • Full Member
  • ***
  • Posts: 124
  • Country: ca
Re: Control for heating with solar off grid no batteries
« Reply #8 on: August 04, 2016, 07:14:01 AM »
Done the sketch for arduino followed the information you send me, having a lot of problems.

Stray 302 in program? error expected ')' before '==' token?  'serial' does not name type?

Could use some guidance, seem to be doing every thing wrong.

Thanks

OperaHouse

  • Hero Member
  • *****
  • Posts: 1064
  • Country: us
Re: Control for heating with solar off grid no batteries
« Reply #9 on: August 04, 2016, 11:45:39 AM »
That code compiles without error, I just tried it again.  When I copy it into PM or here, the word processor clobbers it.  Long lines are terminated and placed in a new line.  This is likely your problem.  Normally I suggest writing a little code, like adding onto blink, to get a feel for hoe things are ordered.

Check every line:
// are comments and ignored everything else is code.  If it reads like English, it belongs on the end of the previous line. Back it up or put a // in front of it.

Each line should begin with an if, print, void, or int.  A bracket is also ok.

Variable names followed by an = are ok.

Lines starting with a tinted word are likely ok.

Display will stop at the first error.  The error is usually the line before.

click on HELP then REFERENCE.  Every line that doesn't start with a // should follow the listed format.
time to learn a little code.  It is trial by fire.  If you don't understand it, you can't modify it later to suit your needs.  If all else fails, copy a few lines where it stops and post them here.  The problem is simply how it was copied.

When I sent you that code in a PM I went into sent messages to see what the editor had done with it.  There were no listings for any of the messages I have sent.  If they were there I could probably tell you the problem.  If you don't figure it out, send it back to me.


« Last Edit: August 04, 2016, 03:17:33 PM by OperaHouse »

ontfarmer

  • Full Member
  • ***
  • Posts: 124
  • Country: ca
Re: Control for heating with solar off grid no batteries
« Reply #10 on: August 05, 2016, 05:48:28 AM »
This is what I  have done and getting an error;
int panel = 0;
int setpoint = 546;
int blinktime = 0;
int PWMcount =0;
int PWM3 =0;



void setup()
{
  Serial.begin(9600);
  pinMode(13,OUTPUT);
 
  pinMode(10,OUTPUT);
  pinMode(3,OUTPUT);
}

 

void loop() {
panel = analogRead(0)
(panel > setpoint + 25)PWMcount = PWMcont + 1;
(panel < setpoint - 25)PWMcount = PWMcount - 1;
(panel > setpoint - 2)PWMcount = PWMcount - 1;
(PWMcount > = 255)PWMcount = 255;
(PWMcount < =0)PWMcount = 0;
PWM3 = PWMcount;
PWM3 > = 250)PWM3 = 255;
Pwm3 < = 5)PWM3 = 0;
 digitalWrite(10, 1);
 delayMicroseconds(100);
 digitalWrite(10, 0);
 delayMicroseconds(500);
 analogWrite(3,PWM3);
 (blinktime == 2) digitalWrite(13, 1);
 (blinktime == 3) digitalWrite(13, 0);
 (blinktime == 6 && PWM > = 30)digitalWrite(13, 1);
 (blinktime == 7)digtalWrite(13, 0);
 (blinktime == 9 && PWM3 >= 60)digitalWrite(13, 1);
 (blinktime == 10)digitalWrite(13, 0);
 (blinktime == 12 && PWM3 >= 90)digitalWrite)13, 1);
 (blinktime == 13 )digitalWrite(13, 0);
 (blinktime == 15 && PWM3 >= 120)gigitalWrite(13, 1);
 (blinktime == 16)digitalWrite(13, 0);
 (blinktime == 18 && PWM3 >=150digitalWrite(13, 1);
 (blinktime == 19)digitalWrite(13, 0);
 (blinktime == 21 && PWM3 >=180)digital(13, 1);
 (blinktime == 22)digitalWrite(13, 1);
 (blinktime  == 23 && PWM3 >= 210)digitalWrite(13, 1);
 (blinktime == 24)digitalWrite(13, 0);
 (binktime == 26 && PWM3 >= 240)digitalWrite(13, 1);
 (blinktime == 27)digitalWrite(13, 0);
 Serial.print("voltage is");
 Serial.print(panel*32);
 Serial.print("raw A/D is");
 Serial.print(panel);
 Serial.print("the count is");
 Serial.print(PWMcount);
 Serial.print.("PWM3 is");
 Serial.printin(PWM3);
 delay(50);
 blinktime=blinktime + 1;
(blinktime > 100)blinktime=0;
 // put your main code here, to run re
}
     


OperaHouse

  • Hero Member
  • *****
  • Posts: 1064
  • Country: us
Re: Control for heating with solar off grid no batteries
« Reply #11 on: August 05, 2016, 06:34:29 AM »
You must have copied this over by hand.  There were things misspelled, missing ; missing all the if.  Spacing is also an issue.  Sometimes you left it out, sometimes added in.  >= is a function > = is not.
Replace what you have with this and you will get farther.

panel = analogRead(0);
if (panel > setpoint + 25) PWMcount = PWMcount + 1;
if (panel < setpoint - 25) PWMcount = PWMcount - 1;
if (panel > setpoint - 2) PWMcount = PWMcount - 1;
if (PWMcount >= 255) PWMcount = 255;
if (PWMcount <= 0) PWMcount = 0;
PWM3 = PWMcount;
if (PWM3 >= 250) PWM3 = 255;
if (PWM3 <= 5) PWM3 = 0;

Almost every line had a mistake.  They can be hard to see first off.  Things like gigitalWrite, printin, an extra . and binktime.  gigitalWrite is likely too big for a micro! Comments in the code will help you a lot later.  I've corrected the errors and it does run.  Just go one line at a time.  By the end, the lesson will be learned.
« Last Edit: August 05, 2016, 06:55:27 AM by OperaHouse »

ontfarmer

  • Full Member
  • ***
  • Posts: 124
  • Country: ca
Re: Control for heating with solar off grid no batteries
« Reply #12 on: August 05, 2016, 06:56:36 AM »
This is what I received. Thanks I will try again, copying by hand is the only way I know.

This is a simple pwm driver to keep solar panel voltage
// at power point and prevent short pulses. A blinking LED
// gives heating status. Outputs a PWM drive to a FET.
// This project had a boost converter that boosted 12V panel voltage to 35V
// and was then PMW into water heater element for performance data.
// 4/26/15 Opera House
// 3/3/2016 Unknown version. Found with some mistakes that were corrected
// Compiles but untested. Unknown performance. Sent 7/25/16

int panel     = 0;           // calculated panel voltage in mv
int setpoint  = 546;         // power point raw data count, set for power point
int blinktime = 0;           // blink loop counter
int PWMcount  = 0;           // PWM counter value
int PWM3      = 0;           // PWM3 output value

void setup() 
{
 Serial.begin(9600);        // setup serial port speed
 pinMode(13, OUTPUT);       // sets the digital LED pin 13 as output, onboard LED
 pinMode(10, OUTPUT);       // digital pulse for timing loop OPTIONAL
 pinMode(3, OUTPUT);        // sets the digital pin 3 as PWM output to drive FET
}


void loop()  {
   
    // A resistive voltage divider produces about 2V-3V at pin A0
    // Typical operating voltage gives an A/D count of about 500
    // These values are for single 12V panel.  Adjust for your array.
   
    //  READ ANALOG VALUE AT PIN A0
    panel = analogRead(0);                 
    // A/D values go from 0 to 1023
   
   
    // ADJUST PWM COUNT UP OR DOWN
   
    // FAST RECOVER from high panel voltage at startup or cloud passing
    // These first two just add/subtract an extra count each loop.  Count could be increased.
   
    // FAST RECOVER from high panel voltage
    if (panel > setpoint + 25) PWMcount = PWMcount + 1;
   
    // FAST RECOVER from low panel voltage
    if (panel < setpoint - 25) PWMcount = PWMcount - 1;
   
   
    // NORMAL UP DOWN CORRECTION 4 COUNT DEADBAND
    // NORMAL HIGH VOLTAGE RAMP UP
    if (panel > setpoint + 2) PWMcount = PWMcount + 1;             
    // voltage is over setpoint
   
    // NORMAL LOW VOLTAGE RAMP DOWN
    if (panel > setpoint - 2) PWMcount = PWMcount - 1;             
    // voltage is under setpoint
   
   
    // CHECK COUNT LIMITS This is the up down count
    // is count too high?
    if (PWMcount >= 255) PWMcount = 255;               
   
    // is count too low?
    if (PWMcount <= 0) PWMcount = 0; 

    // Set count to output.  This is the output value not to be confused with count value.
    PWM3 = PWMcount; 
   
    // PREVENT NARROW DRIVE PULSES that cause FET heating.
     
    // is count too high and makes narrow pulse?
    if (PWM3 >= 250) PWM3 = 255;  // FULLY ON             
   
    // is count too low and makes narrow pulse?
    if (PWM3 <= 5) PWM3 = 0;      // FULLY OFF

    // ROUTINE FOR DETERMINING LOOP TIME & PWM INTERACTION  Must have done this to check
    // time it takes to make program loop.
    // This section could be eliminated.
    digitalWrite(10, 1);
    delayMicroseconds(100);
    digitalWrite(10, 0);
    delayMicroseconds(500);    // delay for viewing analogWrite
   
   
    // PWM FET DRIVER OUTPUT PIN #3   Output Heater PWM                     
    analogWrite(3,PWM3);                       
    // PWM values are between 0 and 255



    //  BLINKING LED STATUS DISPLAY
    // The following is not necessary but provides useful visual information on how the program is running
    // One blink indicates program is running. Up to 8 additional blinks indicates drive level.
    // blinktime counts the number of program loops
                                               
    // FIRST BLINK - JUST TO SHOW THAT THE PROGRAM RUNNING
    if (blinktime == 2)  digitalWrite(13, 1);                 // pin #13 is the on board LED, 1 is ON   
    if (blinktime == 3) digitalWrite(13, 0);                 // turn off LED = 0
    // turns the LED off so it blinks
   
    // PWM STATUS OF POWER LEVEL more blinks higher level
    // SECOND BLINK - IF DRIVE GREATER THAN
    if (blinktime == 6 && PWM3 >= 30) digitalWrite(13, 1);                                 
    if (blinktime == 7) digitalWrite(13, 0);                // sets the LED off so it blinks
   
    // THIRD BLINK - IF DRIVE GREATER THAN 60
    if (blinktime == 9 && PWM3 >= 60) digitalWrite(13, 1);   
    if (blinktime == 10) digitalWrite(13, 0);   
   
    // FOURTH BLINK - IF DRIVE GREATER THAN 90
    if (blinktime == 12 && PWM3 >= 90) digitalWrite(13, 1);   
    if (blinktime == 13) digitalWrite(13, 0);   
   
    // FIFTH BLINK - IF DRIVE GREATER THAN 120
    if (blinktime == 15 && PWM3 >= 120) digitalWrite(13, 1);   
    if (blinktime == 16) digitalWrite(13, 0);   
   
    // SIXTH BLINK - IF DRIVE GREATER THAN 150
    if (blinktime == 18 && PWM3 >= 150) digitalWrite(13, 1);   
    if (blinktime == 19) digitalWrite(13, 0);
 
    // SEVENTH BLINK - IF DRIVE GREATER THAN 180
    if (blinktime == 21 && PWM3 >= 180) digitalWrite(13, 1);   
    if (blinktime == 22) digitalWrite(13, 0);   
       
    // EIGHTH BLINK - IF DRIVE GREATER THAN 210
    if (blinktime == 23 && PWM3 >= 210) digitalWrite(13, 1);   
    if (blinktime == 24) digitalWrite(13, 0);   
       
    // NINTH BLINK - IF DRIVE GREATER THAN 240
    if (blinktime == 26 && PWM3 >= 240) digitalWrite(13, 1);   
    if (blinktime == 27) digitalWrite(13, 0); 
   
    // A single blink indicates processor is running but no heating
   
   

    // PROGRAM DATA SENT TO ARDUINO SERIAL SCREEN IN TOOLS
    // send calculated voltage to TOOLS debug screen. This will give a real
    // time read of voltage. A pot can be adjusted matching the computer value
    // to the digital voltmeter.
    if (blinktime == 100) {
    Serial.print("voltage is ");              // identify variable
    Serial.print(panel * 32);                 // print voltage raw data X 32         
                                              // will need to be adjusted for other panels
    Serial.print("  raw A/D is ");            // identify variable
    Serial.print(panel);                      // print raw voltage A/D variable
    Serial.print("  the count is ");          // identify variable
    Serial.print(PWMcount);                   // print PWM counter value 
    Serial.print("  PWM3 is ");               // identify variable
    Serial.println(PWM3);                     // print PWM output value and do line feed
    }
   
    delay (50);                               // once per loop delay
    blinktime = blinktime + 1;                // LOOP COUNTER
    if (blinktime > 100) blinktime = 0;       // reset the counter
   
   
 }                                            // end of program





Report To Admin







Pages: [1]

ontfarmer

  • Full Member
  • ***
  • Posts: 124
  • Country: ca
Re: Control for heating with solar off grid no batteries
« Reply #13 on: August 05, 2016, 07:32:32 AM »
Just learned how to copy and paste.  Error code  type ?

This is a simple pwm driver to keep solar panel voltage
// at power point and prevent short pulses. A blinking LED
// gives heating status. Outputs a PWM drive to a FET.
// This project had a boost converter that boosted 12V panel voltage to 35V
// and was then PMW into water heater element for performance data.
// 4/26/15 Opera House
// 3/3/2016 Unknown version. Found with some mistakes that were corrected
// Compiles but untested. Unknown performance. Sent 7/25/16

int panel     = 0;           // calculated panel voltage in mv
int setpoint  = 546;         // power point raw data count, set for power point
int blinktime = 0;           // blink loop counter
int PWMcount  = 0;           // PWM counter value
int PWM3      = 0;           // PWM3 output value

void setup() 
{
 Serial.begin(9600);        // setup serial port speed
 pinMode(13, OUTPUT);       // sets the digital LED pin 13 as output, onboard LED
 pinMode(10, OUTPUT);       // digital pulse for timing loop OPTIONAL
 pinMode(3, OUTPUT);        // sets the digital pin 3 as PWM output to drive FET
}


void loop()  {
   
    // A resistive voltage divider produces about 2V-3V at pin A0
    // Typical operating voltage gives an A/D count of about 500
    // These values are for single 12V panel.  Adjust for your array.
   
    //  READ ANALOG VALUE AT PIN A0
    panel = analogRead(0);                 
    // A/D values go from 0 to 1023
   
   
    // ADJUST PWM COUNT UP OR DOWN
   
    // FAST RECOVER from high panel voltage at startup or cloud passing
    // These first two just add/subtract an extra count each loop.  Count could be increased.
   
    // FAST RECOVER from high panel voltage
    if (panel > setpoint + 25) PWMcount = PWMcount + 1;
   
    // FAST RECOVER from low panel voltage
    if (panel < setpoint - 25) PWMcount = PWMcount - 1;
   
   
    // NORMAL UP DOWN CORRECTION 4 COUNT DEADBAND
    // NORMAL HIGH VOLTAGE RAMP UP
    if (panel > setpoint + 2) PWMcount = PWMcount + 1;             
    // voltage is over setpoint
   
    // NORMAL LOW VOLTAGE RAMP DOWN
    if (panel > setpoint - 2) PWMcount = PWMcount - 1;             
    // voltage is under setpoint
   
   
    // CHECK COUNT LIMITS This is the up down count
    // is count too high?
    if (PWMcount >= 255) PWMcount = 255;               
   
    // is count too low?
    if (PWMcount <= 0) PWMcount = 0; 

    // Set count to output.  This is the output value not to be confused with count value.
    PWM3 = PWMcount; 
   
    // PREVENT NARROW DRIVE PULSES that cause FET heating.
     
    // is count too high and makes narrow pulse?
    if (PWM3 >= 250) PWM3 = 255;  // FULLY ON             
   
    // is count too low and makes narrow pulse?
    if (PWM3 <= 5) PWM3 = 0;      // FULLY OFF

    // ROUTINE FOR DETERMINING LOOP TIME & PWM INTERACTION  Must have done this to check
    // time it takes to make program loop.
    // This section could be eliminated.
    digitalWrite(10, 1);
    delayMicroseconds(100);
    digitalWrite(10, 0);
    delayMicroseconds(500);    // delay for viewing analogWrite
   
   
    // PWM FET DRIVER OUTPUT PIN #3   Output Heater PWM                     
    analogWrite(3,PWM3);                       
    // PWM values are between 0 and 255



    //  BLINKING LED STATUS DISPLAY
    // The following is not necessary but provides useful visual information on how the program is running
    // One blink indicates program is running. Up to 8 additional blinks indicates drive level.
    // blinktime counts the number of program loops
                                               
    // FIRST BLINK - JUST TO SHOW THAT THE PROGRAM RUNNING
    if (blinktime == 2)  digitalWrite(13, 1);                 // pin #13 is the on board LED, 1 is ON   
    if (blinktime == 3) digitalWrite(13, 0);                 // turn off LED = 0
    // turns the LED off so it blinks
   
    // PWM STATUS OF POWER LEVEL more blinks higher level
    // SECOND BLINK - IF DRIVE GREATER THAN
    if (blinktime == 6 && PWM3 >= 30) digitalWrite(13, 1);                                 
    if (blinktime == 7) digitalWrite(13, 0);                // sets the LED off so it blinks
   
    // THIRD BLINK - IF DRIVE GREATER THAN 60
    if (blinktime == 9 && PWM3 >= 60) digitalWrite(13, 1);   
    if (blinktime == 10) digitalWrite(13, 0);   
   
    // FOURTH BLINK - IF DRIVE GREATER THAN 90
    if (blinktime == 12 && PWM3 >= 90) digitalWrite(13, 1);   
    if (blinktime == 13) digitalWrite(13, 0);   
   
    // FIFTH BLINK - IF DRIVE GREATER THAN 120
    if (blinktime == 15 && PWM3 >= 120) digitalWrite(13, 1);   
    if (blinktime == 16) digitalWrite(13, 0);   
   
    // SIXTH BLINK - IF DRIVE GREATER THAN 150
    if (blinktime == 18 && PWM3 >= 150) digitalWrite(13, 1);   
    if (blinktime == 19) digitalWrite(13, 0);
 
    // SEVENTH BLINK - IF DRIVE GREATER THAN 180
    if (blinktime == 21 && PWM3 >= 180) digitalWrite(13, 1);   
    if (blinktime == 22) digitalWrite(13, 0);   
       
    // EIGHTH BLINK - IF DRIVE GREATER THAN 210
    if (blinktime == 23 && PWM3 >= 210) digitalWrite(13, 1);   
    if (blinktime == 24) digitalWrite(13, 0);   
       
    // NINTH BLINK - IF DRIVE GREATER THAN 240
    if (blinktime == 26 && PWM3 >= 240) digitalWrite(13, 1);   
    if (blinktime == 27) digitalWrite(13, 0); 
   
    // A single blink indicates processor is running but no heating
   
   

    // PROGRAM DATA SENT TO ARDUINO SERIAL SCREEN IN TOOLS
    // send calculated voltage to TOOLS debug screen. This will give a real
    // time read of voltage. A pot can be adjusted matching the computer value
    // to the digital voltmeter.
    if (blinktime == 100) {
    Serial.print("voltage is ");              // identify variable
    Serial.print(panel * 32);                 // print voltage raw data X 32         
                                              // will need to be adjusted for other panels
    Serial.print("  raw A/D is ");            // identify variable
    Serial.print(panel);                      // print raw voltage A/D variable
    Serial.print("  the count is ");          // identify variable
    Serial.print(PWMcount);                   // print PWM counter value 
    Serial.print("  PWM3 is ");               // identify variable
    Serial.println(PWM3);                     // print PWM output value and do line feed
    }
   
    delay (50);                               // once per loop delay
    blinktime = blinktime + 1;                // LOOP COUNTER
    if (blinktime > 100) blinktime = 0;       // reset the counter
   
   
 }                                            // end of program








OperaHouse

  • Hero Member
  • *****
  • Posts: 1064
  • Country: us
Re: Control for heating with solar off grid no batteries
« Reply #14 on: August 05, 2016, 08:00:18 AM »
It may stop at the first line if // was not copied.


This is a simple pwm driver to keep solar panel voltage
// at power point and prevent short pulses. A blinking LED

Editing the old code to get it to work would be good practice for learning to find errors.
« Last Edit: August 05, 2016, 08:11:18 AM by OperaHouse »

ontfarmer

  • Full Member
  • ***
  • Posts: 124
  • Country: ca
Re: Control for heating with solar off grid no batteries
« Reply #15 on: August 05, 2016, 08:19:48 AM »
Thanks I will spend time on that to learn.

OperaHouse

  • Hero Member
  • *****
  • Posts: 1064
  • Country: us
Re: Control for heating with solar off grid no batteries
« Reply #16 on: August 05, 2016, 03:27:00 PM »
Once you have that working and are more comfortable,it will be time to modify the code
to more suit your application.  The A/D converter has a range of 0-1023. As I said before
the typical A/D value we are shooting for is between 500 and 700. With your panel string
being about 100V for the power point, a simple multiplier of two would give an nice
number down to a tenth of a volt. 1132 would be 113.2 volts. It would be even nicer if
that number was averaged.  This routine does that.  The divisor becomes the multiplier.
In reality with the number of bits used it is only accurate to the quarter volt.  This
code should be placed after the A/D read statement.



// MULTIPLY A/D VALUE TO OBTAIN PANEL VOLTAGE IN TENTH OF A VOLT

panel  = panel - panel / 2;
       
// Sum the readings by subtracting one average reading first   
// It isn't obvious but this routine effectively multiplies the A/D reading
// by the divisor. It can be any number, First a fraction of the total is
// subtracted.  Then new rawdata is added.

panel  = panel + rawdata;
             
// Add latest A/D reading to panel total. This makes a running average.



A new variable has to be added, rawdata, to the program.

int rawdata = 0     // raw A/D panel value

And in that declared variable section the setpoint value now has to be doubled.

This has to be placed up where the other variables are declared and the panel
variable in the analogRead statement has to be replaced with rawdata.  Near the end
of the program in the print statement where the panel variable is multiplied, that
* 32 multiplier is deleted.  panel variable is read out directly.

OperaHouse

  • Hero Member
  • *****
  • Posts: 1064
  • Country: us
Re: Control for heating with solar off grid no batteries
« Reply #17 on: August 05, 2016, 07:10:05 PM »
You may not think it from your first experience, but the compiler is very helpful in
finding errors in your code.  It stops at the first statement it has trouble with. The
problem may be in that line or a couple of lines before. It might even be at the beginning
of the program where everything is declared.  You made about all of the common mistakes.
I make the same ones. Your mind is set up to speed read and it quickly ignores things that
are a litttle off like spelling.  The compiler is unforgiving with that.  Brackets are
another issue.  Each one has to have a mate.  If you click on the first one, the compiler
will put a box around the closing one.  I use copy and paste to save a lot of typing. That
can be deadly as yo can miss a beginning or end piece of a statement.  It is pretty easy
to forget to change a variable in a snippet of code.  Operations like if, print, digitalRead,
etc. are highlighted in color.  If you type digitalread it won't be highlighted. I haven't
given you everything at once.  I want you to understand the code so you can comfortably modify
the code as you understand your unique operating situation.  It is a good idea to have every
line of code stand on its own instead of nesting one routine instead of another.  It is much
easier to debug if a problem arises. 

The SERIAL screen in TOOLS allows you to write out the variables as the program progresses.
Sometimes your thought process is a little off and you count 11 times instead of 10.  Or
maybe you don't count at all.  Pin 13 controls the on board LED.  Always have some routine
that flashes the LED every so many loops of the program.  Nothing worse than looking at a
micro and wondering what it is doing.  Be aware that printing to a screen in TOOLS really
slows doen a program.  It helps to do that every so many loops.  It doesn't help to have
data flying past you faster than you can see.  That SERIAL screen can hold a lot of data.
You can always use the cursor to go back and see how things progress. In most situations
there needs to be a delay in the program. The standard PWM of the UNO is 490Hz. It wouldn't
be good to be updating it all the time.  Try to understand how the loop counters work in
the program.  It is a good way to sequence things in the program like blinking a LED or
reading data.

When you get some code that is working, even if not a full implementation, save it with a
version number after the name.  Also note in the header the last date it was modified
and what changes were made.  That gives you something to go back to when the code really
goes south.  Note what in the code was changed in the header.  I don't always do it, but
I do wish I had when I start looking at multiple versions.  Use lots of comments to explain
what is happening in the code.  Six months from now you will be trying to figure out what is
happening and what variables mean.

ontfarmer

  • Full Member
  • ***
  • Posts: 124
  • Country: ca
Re: Control for heating with solar off grid no batteries
« Reply #18 on: August 06, 2016, 05:48:30 AM »
Spent time checking code corrected a few things you pointed out. What a good feeling that it complies.
It took hours for me to hand type. If my wife was here she would of done it correct in a few
minutes, lost here a couple years ago.
I will keep you updated.

Thanks

DamonHD

  • Administrator
  • SuperHero Member
  • *****
  • Posts: 3646
  • Country: gb
    • Earth Notes
Re: Control for heating with solar off grid no batteries
« Reply #19 on: August 06, 2016, 07:26:37 AM »
What OperaHouse says about keeping versioned copies and good comments is excellent practice.

Rgds

Damon
« Last Edit: August 06, 2016, 07:34:48 PM by DamonHD »

Mary B

  • Hero Member
  • *****
  • Posts: 784
Re: Control for heating with solar off grid no batteries
« Reply #20 on: August 06, 2016, 02:54:30 PM »
I remember trouble shooting 10,000+ lines of code for a trucking company. Compiler wasn't helping find the error so I had to sit down and go through the program line by line. Second tie through I found a missing .

ontfarmer

  • Full Member
  • ***
  • Posts: 124
  • Country: ca
Re: Control for heating with solar off grid no batteries
« Reply #21 on: August 06, 2016, 05:53:34 PM »
That makes what I done seem very small. Great hearing from you, thanks for the warning about the capacitors.

OperaHouse

  • Hero Member
  • *****
  • Posts: 1064
  • Country: us
Re: Control for heating with solar off grid no batteries
« Reply #22 on: August 07, 2016, 07:59:01 AM »
Now that you have been able to compile the progrm, have you tried loading it into the UNO?
Connect the 3V3 pin to the A0 analog input pin through a 100K to 400K resistor. The USB
cable from your computer will supply power to the board without using any external power.
Click on TOOLS and select SERIAL. The screen will appear and data will start to appear
every thirty seconds or so.  My screen will be a little different since making changes.
The 3V3 pin connected to A0 give a raw A/D count of about 657 to simulate panel voltage.
That will be doubled and give a panel count of about 1314, representing 131.4 volts.
Now touch one finger to the resistor lead on A0 and eith the other hand touch the metal
connector body.  The panel voltage will drop as this places a load on the resistor. Remove
your finger and the voltage will climb up again. When the panel number is above the setpoint
the PWM will count up.  When the panel number is below that the PWM will count down. This
will happen very quickly.  The PWM can change more than 80 counts for each time SERIAL
data can be printed to the screen. This

If things don't happen as expected.  Hit the RESET button on the board.         


OperaHouse

  • Hero Member
  • *****
  • Posts: 1064
  • Country: us
Re: Control for heating with solar off grid no batteries
« Reply #23 on: August 07, 2016, 12:54:44 PM »
Did I tell you testing was important and cut and paste was dangerous?  Finally got around
to actually testing in detail.  I was checking out a thermal tracking circuit using diodes.
Noticed that it took a bigger differential with panel and setpoint than I was expecting.
In the up down counting routine that adds or subtracts 1 is reversed.  Anyone can make
mistakes in logic.  TEST, TEST, TEST. It should read:

    // NORMAL LOW VOLTAGE RAMP DOWN
    if (panel < setpoint - 2) PWMcount = PWMcount - 1;             
    // voltage is under setpoint

The power point of solar panels changes with temperature.  Mornings are cooler, winter is
colder.  Solar panels are just a bunch of diodes.  In this circuit I have 6 forward biased
diodes in series.  This produces about 3.5 volts.  Lower temperature produces a higher
reference voltage.  A 1K to 2K resistor produces a couple ma of current through the diodes.
If the total loading on the diodes is greater than 200K it will track pretty well. A 20-50K
and 150K resistor would give a nice adjustable range.  But all that for later.  Correct the
code in your program.
« Last Edit: August 07, 2016, 03:29:59 PM by OperaHouse »

OperaHouse

  • Hero Member
  • *****
  • Posts: 1064
  • Country: us
Re: Control for heating with solar off grid no batteries
« Reply #24 on: August 08, 2016, 10:02:08 AM »

See, you're getting used to it.  I've made some more changes to the program.  These will
make it functionally easier to set up.  The pot that reads the panel voltage will be
adjusted so that the voltage on the SERIAL screen matches your DVM reading of the capacitor
bank.  Now that that adjustment is set, there needs to be a way to change the setpoint
voltage. A second pot is added to the system to change the setpoint. Each end of the pot
is connected to GND and +5V, the wiper is connected to A1 of the uno. This will allow
a new variable, pot, to range from 0-1023.  The variable setpoint has to go higher than
that so the variable pot will be doubled just like we did with panel. The variable pot
will have to be declared.  The A/D routine and multiplier can be copied and the variable
names changed.

A word of caution.  The worst thing that can happen is to lose the ground connection to
the board.  There are three ground pins and I suggest they ALL be connected to the external
common.  If you have access to the power plugs common, I suggest you connect to that too.
This will be the best protection for the board.  The GND pins are next to other supply
voltages.  Tripple check before applying power so it doesn't short out those.

Add the setpoint reading to the print section.  As the line may be getting a little long,
the other identifiers could be shortened by using an = instead of "is" and eliminating a
space.  Everything in blue including spaces is literally printed as you see it.

I thought the blinking was a little less than pleasing.  All the blinks I made one count
long.  After the first blink, the one that indicates the program is running, I waited 13
counts.  Then between each blink after that I waited 5 counts.

I made the program loop run a little faster.  The loop counter now resets after 80 counts
instead of 100.  You will have to make sure the print routine still works.

I'm not trying to be mean.  There is a purpose to all this. I want you to gain a familiarity
with the system so you will be comfortable with it and be able to make changes that suit
your circumstance.  Hopefully you will be able to see other applications to use this board
on.

ontfarmer

  • Full Member
  • ***
  • Posts: 124
  • Country: ca
Re: Control for heating with solar off grid no batteries
« Reply #25 on: August 08, 2016, 05:08:34 PM »
I uploaded the uno and the tx and the light started blinking. Connected 3.3 pin and Ao pin
tried what you said but must of done something wrong.

The panel is 124 open volt, raw A/D count 689  Hooked up Opto and FET surprised when I
plugged in the drill and it worked!!   A/D count dropped about twenty points.

Corrected the mistake you mentioned.  Very fortunate for what I have learnt from you but
 a long way too go.  Getting a little familiar will some terms.

I will need a couple days to get things under control.

Already have new projects planned with the UNO when this one is finished. Will get the
 attention of some of the "smart" people.

  Thanks

                     










ontfarmer

  • Full Member
  • ***
  • Posts: 124
  • Country: ca
Re: Control for heating with solar off grid no batteries
« Reply #26 on: August 08, 2016, 05:13:40 PM »
May not pass code?