Author Topic: Operate two fridges, one at a time  (Read 4706 times)

0 Members and 1 Guest are viewing this topic.

OperaHouse

  • Hero Member
  • *****
  • Posts: 1308
  • Country: us
Operate two fridges, one at a time
« on: December 02, 2016, 02:29:18 PM »
The following program was inspired by george65 who said he had a need to
operate two refrigerators, one at a time. Scheduling loads is one way
to reduce the need to go to larger inverters and more batteries. This
could be applied to many other applications. The following code is untested,
but it should be very close except for changing some values to suit the
application. I decided not to include a maximum run time. Even if this
program is not needed it is fun to run as an example of data displays.
As shown it is in stand alone test mode.  I must be edited to function
as a power alternator.

This uses a single ACS712 5A current sensor and a mechanical relay. The
normally closed contacts go to the primary refrigerator. If the current
sensor does not detect a running fridge, it will test the other fridge
every five minutes.  If no operation is detected for one minute it
reverts power to the primary fridge.  If primary fridge is running, it
waits till it stops before testing fridge number two.  Currents below
1A are ignored allowing controls or mechanical timers to work. I am
only guessing how your fridge may work. Products with only mechanical
controls will work best. A freezer would be the ideal second load.

The A/D current sensor outputs a 2.5V signal at zero current.  The
"zero count" will be half the maximum A/d count, 512. An offset of
about 512 is subtracted from the A/D value to get the +- current
value. Use of ABS creates a positive value regardless of sign. This
signal drifts and has noise.  Any value less than 10 is just ignored.
Adding 25 values gives close to the amp value of current. Over 1A
is a good indicator the motor is running.

This program is also set up to operate two solid state relays.  In
addition, a PWM pin also allows you to use a mechanical relay at
reduced power. A PWM of 255 is fully on. If on, each program loop reduces
the current one count till a minimum is reached.  170 is a safe value.
Many relays will operate at half the PWM for additional savings of power.
Copy this into your sketch.



// ACS712-6   ALTERNATE FRIDGES BASED ON CURRENT SENSE
// Two fridge alternator with mechanical & solid state relay
// This program alternates two fridges by reading a ACS712 HALL
// sensor on pin A3 measuring AC current. Offset is subtracted
// and taking absolute value. Noise and rift are filtered out.
// load (fridge) stays on as long as that fridge is operating
// drawing more than one amp. If no load is detected for 5 minutes
// it then powers the other fridge for one minute and checks
// for current.  It stays on as long as the is a load is present.
// Mechanical relay is PWM driven to lower current.
// Serial outputs data every second & flashes LED to indicate on.

// last edit 12/02/16

 
 int minute     = 0;
 int second     = 0;
 int count      = 0;
 int relay      = 0;             // OFF NC contacts operates fridge #1
 int PWMdrv     = 0;             // PWM relay drivers
 int ACSraw     = 0;             // raw A/D of hall sensor
 int ACScount   = 0;             // ABS A/D of hall sensor
 int offset     = 512;           // offset nominal for zero
                                      // change to match sensor normal
 unsigned int amptotal   = 0;    // acumulated current
 
void setup() 
{
   Serial.begin(9600);           //  setup serial
   pinMode(13, OUTPUT);          // sets the digital LED pin 13 as output
   pinMode(5, OUTPUT);           // sets pin 5 as output  MECHANICAL RELAY
   pinMode(7, OUTPUT);           // sets pin 7 as output  SOLID STATE RELAY #1
   pinMode(8, OUTPUT);           // sets pin 8 as output  SOLID STATE RELAY #2
}

 
void loop()  {   
   
   
    if (count >= 25)                                // end count & make second
    {                                                   // this bracket indicates start of actions
                                                        // when IF is true
       count  = 0;                                      // reset count
       second =  second + 1;                      // 25 counts = 1 second
       amptotal = 0;                                    // reset amp count total       
    }                                                   // end of those operations
   
     count = count + 1;                                 // increment count
   
    ACSraw = analogRead (3);                            // read sensor on pin A3
   
    delay(39);                                          // waits for a 39/1000 second
    //delay(10);                                           // THIS IS SHORT FOR TESTING, A VERY FAST SECOND
   
    //ACSraw = offset + 30;                         // TEST ONLY sensor not connected .75A simulation
    ACSraw = offset;                                  // TEST ONLY sensor not connected  .00A simulation
                                                        // COMMENT OUT IN FINAL CODE
                                                       
    ACScount = ACSraw - offset;                         // get any positive or negative number of current
                                                        // offest is half of A/D maximum
    ACScount = abs(ACScount);                           // get absolute value of current
                                                        // math functions can not be done inside abs function
     
    if (ACScount > 10) amptotal = amptotal + ACScount;  // add any number greater than 10
                                                        // every A/D read is added as a positive number
                                                        // by suntracting the nominal offset and taking absolute value
                                                        // noise around zero is eliminated by ignoring values under 10
                                                        // printout divide by 1000
                                                        // 25 loops is just a multiplier to make numbers come out
                                                       
    //                       ONCE PER SECOND BLINK                                                   
    if ( count == 10) digitalWrite (13,HIGH);           // LED blink ON
    if ( count == 12) digitalWrite (13,LOW);            // LED OFF                                     
   
   
     
    //                 MECHANICAL RELAY CODE, CONNECT TO PIN #5 ON/OFF           
    digitalWrite (5, relay);                  // output relay 0=fridge #1 ON
                                              // output relay 1=fridge #2 ON
                                             
    //             LOW CURRENT MECHANICAL PWM RELAY CODE,  CONNECT TO PIN #6 
    if (relay == 0) PWMdrv = 0;                   // turn relay OFF
    if (relay == 1 && PWMdrv == 0) PWMdrv = 255;  // turn relay ON full power
    digitalWrite (6, PWMdrv);                     // output relay 0=fridge #1 ON
                                                  // output relay 1=fridge #2 ON
    if (PWMdrv >= 170) PWMdrv = PWMdrv - 1;       // reduce current each loop                                     
                                                  // till minimum reached
                                                 
                                                 
     //              SOLID STATE RELAY CODE,  CONNECT TO PIN #7 & #8             
   
    if (relay == 0) digitalWrite (7, 1);      // output relay=0 fridge #1 ON
    if (relay == 1) digitalWrite (7, 0);      // output relay=1=fridge #1 OFF     
    digitalWrite (8, relay);                  // output relay=1 fridge #2 ON   
                                              // output relay=0 fridge #2 OFF 
                                             
     //                 CYCLING OF FRIDGE, TIME                                         
                                             
    if (second >= 60)                                // check second
    {   
    second = 0;                                      // reset second
    minute = minute + 1;                             // create a new minute
    }
   
    //                  TEST AT 4 MINUTES & SET RELAY
   
    if (minute == 4 && count ==25 && amptotal < 600 && relay == 0) // test after  4 minutes
     {
       relay = 1;                                    // Turn on fridge #2     
     }
     
    if (minute == 5 &&  count ==25 && amptotal < 600 && relay == 1) // test after  5 minutes
     {
       relay = 0;                                    // Turn on fridge #1     
     }
   
   
    //                  END OF TEST PERIOD
    if (minute >= 6) minute = 0;                     // reset minute
   
   
    //                       SEND DATA TO SERIAL IN TOOLS
    //      Printing takes time.  Comment out this in final working program.
    //      data every second
   
    if (count == 25)                           // do print out data
{
    Serial.print(ACSraw);                      // raw A/D count
    Serial.print(" A/D ");         
    Serial.print(ACScount);                    // absolute A/D count
    Serial.print(" ABS ");         
    Serial.print(offset);                      // offset used 1/2 voltage aprox.
    Serial.print(" off  cur=");         
    Serial.print((float) amptotal/1000);       // amps
    Serial.print("A  ");
   
    Serial.print(minute);                      // minute
    Serial.print(":");
    Serial.print(second);                      // second
   
    if (relay == 0)Serial.print(" #1 ON ");  // status
    if (relay == 1)Serial.print(" #2 ON ");  // status
   
    Serial.println(PWMdrv);                    // drive value
   
}   // END OF PRINTING DATA
 
   
}   // END OF PROGRAM
 
« Last Edit: December 03, 2016, 12:21:20 PM by OperaHouse »

george65

  • Sr. Member
  • ****
  • Posts: 499
  • Country: au
Re: Operate two fridges, one at a time
« Reply #1 on: December 02, 2016, 06:48:47 PM »

Fantastic!
Thanks very much for this. I was looking on fleabay last night for something that would perform this function but I don't think I could even put in the right name of what I was looking for even if it does exist.

Just one thing,  for the idiots out there, IE, me, could you write out a parts list  of the main components please?
I found the current sensor, not sure of the relays though. Anything else component wise needed would be appreciated if you can list it so I am sure to have everything I need before starting.

I'm beginning to sound like one of those people that asks for "plans" when you show them how you nailed 2 bits of wood together.  :0(

 I have looked at the code and it seems so daunting but with something practical like this to work on, I'm sure it will help the learning curve greatly.  That said, in my total ignorance, would it be possible to use one of those relay banks  have seen and by editing a section of the base code and adding sensors ( if there are enough pins), would it be possible to control 4 devices say?

I'll have to find a simple table of commands to look them up and understand each one and what it is used for. I have seen there are batch commands that can be copied and pasted so lots to learn there too.

Thank you again for this. Hope I can get to the stage where I can help and contribute to the learning of others as you are so generous and selfless in what you contribute.

SparWeb

  • Global Moderator
  • Super Hero Member Plus
  • *****
  • Posts: 5452
  • Country: ca
    • Wind Turbine Project Field Notes
Re: Operate two fridges, one at a time
« Reply #2 on: December 02, 2016, 11:20:37 PM »
Forgive me for throwing a bomb into your ideas, but I have a KISS solution to this one already working.

Use two programmable block heater timers (each 25$ at a hardware store).  Program one to run at times that the other is programmed not to run, and vice-versa.  You can pick how long the run time for each is, and leave about 1 hour between one that goes off and one that comes on... the clocks in these things aren't very accurate.  They can switch 15 Amps AC heaters all day so they can certainly handle your refrigerators.

No one believes the theory except the one who developed it. Everyone believes the experiment except the one who ran it.
System spec: 135w BP multicrystalline panels, Xantrex C40, DIY 10ft (3m) diameter wind turbine, Tri-Star TS60, 800AH x 24V AGM Battery, Xantrex SW4024
www.sparweb.ca

SparWeb

  • Global Moderator
  • Super Hero Member Plus
  • *****
  • Posts: 5452
  • Country: ca
    • Wind Turbine Project Field Notes
Re: Operate two fridges, one at a time
« Reply #3 on: December 02, 2016, 11:39:56 PM »
OH,
As usual your code is beautiful.
I didn't know that you couldn't nest math into the abs() function.  I wonder if that's caused some of my sketches to bail in the past...
No one believes the theory except the one who developed it. Everyone believes the experiment except the one who ran it.
System spec: 135w BP multicrystalline panels, Xantrex C40, DIY 10ft (3m) diameter wind turbine, Tri-Star TS60, 800AH x 24V AGM Battery, Xantrex SW4024
www.sparweb.ca

OperaHouse

  • Hero Member
  • *****
  • Posts: 1308
  • Country: us
Re: Operate two fridges, one at a time
« Reply #4 on: December 03, 2016, 01:51:20 AM »
I had a long post and I lost it.  Almost 2am, too late to start over.  This is what I just purchased.  I always match up pictures.  Some of the descriptions on the Chinese listings really make you wonder.  These are the only things I buy now.  Same pin spacing as a UNO and two additional A/D inputs. They come without pins attached.  I mount them on top so I can use the dupont connectors.  You need a spare board just to see the labels.

http://www.ebay.com/itm/112183544832?_trksid=p2057872.m2749.l2649&ssPageName=STRK%3AMEBIDX%3AIT

george65

  • Sr. Member
  • ****
  • Posts: 499
  • Country: au
Re: Operate two fridges, one at a time
« Reply #5 on: December 03, 2016, 04:40:31 AM »

NFI what a block heater timer is but they don't sell them here.

I did find a couple of interesting timers though once the penny dropped what to look for.
Came up with this:
http://www.ebay.com.au/itm/New-Digital-2Channel-Programmable-Relay-PLC-Board-Cycle-Delay-Timer-Module-R5F5-/252636090232?hash=item3ad248cf78:g:jFwAAOSwr2RYKafc

And even more interestingly, this:

http://www.ebay.com.au/itm/Programmable-4-Channel-Relay-Module-PLC-Board-Adjustment-Signal-Trigger-New-M4C3-/262722948116?tfrom=252635960090&tpos=top&ttype=price&talgo=undefined

I can't tell if they can be set to switch alternately from the descriptions ( although perhaps they may be)  but could be set as separate timers anyway.
Incredible how cheap they can do these things but I'm kinda feeling it's just not cricket at this point.

I'd like to try and build my own especially now opera has gone to the trouble of writing the code for one. I may not be successful but I'll give it a go anyway.

That said, Today I realised there is a bigger picture to what I really want.
Today was mostly sunny but a bit cooler and cloudy till about mid morning.  I have been trying to test just what I can suck out of the panels  by loading them with lights as well as the fridge to up the draw and pull some amps.  Today we went out house shopping so I left the fridge on on it's own so as not to over draw on the batteries which were only getting about half the amps they were supplying from the panels.

Shortly after I left, the sun came out bright and strong but the fridge then only required a fraction of what was available. Hence my total power draw for the day has only been 19ah.

What occurs now is rather than just a switching off the supply, what would be hugely beneficial and in a range of applications would be monitoring of the input from the panels, the draw of each load and comparing them to a total max current.  This way, if say the fridge was running but it's only using 200W of the 500w Available and the batteries are floating, It could switch in another load to make the best use of all the power available.

I know motors have a high amp start but this could still work if the other load was on another inverter.  I have several so this would work fine for me.
Another useful function would be the ability to switch from solar to mains power. In the case of my Fridge, it's running off a UPS atm so I change it over at night to make sure I don't over discharge the car batteries at night.  When the solar input as nil, a relay could be tripped that kicked in the mains power so the fridge was never left unpowered.

As getting the most from your household grid tied set-up is also important, this set-up would be useful here.  If you are generating say 5 KW, the thing kicks in the water heater. You have say 2 Kw left so it kicks in the Clothes Dryer but that isn't pulling any current so it goes to the next priority in line which is the pool pump.  You have a few hundred watts left so It goes to the septic circulation pump to give that a stir.  And so it goes. Each channel could be prioritised and checked every so often so if it's cloudy and then the sun comes out, one load that was missed could be come back to.

I think something like this would have great appeal given all the solar being installed these days.  New inverters can sense when the PV is working and kick in the water heater and there are modules to add it in but their cost is inflated and they are single channel. Something Arduino could be made cheap and multifaceted.

Maybe in 10 years I'll be up to speed enough to give it a go!  :0)

I'll start with the diverter as a base and go from there!

ontfarmer

  • Full Member
  • ***
  • Posts: 198
  • Country: ca
Re: Operate two fridges, one at a time
« Reply #6 on: December 03, 2016, 06:18:21 AM »
You guys make this very interesting and educational to read.  All the different ideas and
approaches without reinventing.  It can change the way to achieve.

OperaHouse

  • Hero Member
  • *****
  • Posts: 1308
  • Country: us
Re: Operate two fridges, one at a time
« Reply #7 on: December 03, 2016, 09:33:51 AM »
The trouble with timers is the time they are switched to a non operating device is time that power is not available to another load.

You have hit upon the problem with most solar systems.  Once the battery goes to float, all that excess energy is wasted.  That energy could be used to vent an attic or living space.  Run the refrigerator a few degrees colder so it doesn't have to come on when another device is powered or heat water.  All of these are alternative storage to a battery.

My wife wants a dishwasher at the camp. She was not amused when I told her I married one.  A conventional dishwasher takes a lot of power.  She doesn't care if it takes more than two hours.  I can slice operations into small units of time.  Remember, everything runs on a single car battery.  I just run the dishwasher pump for 3 minutes and stop.  Then I reheat the water with whatever excess solar I have till I can run the pump again.  Longer soaks will actually get it cleaner.  A cloud comes, it stops.  I remember getting our first front load laundry washer. I just pulled up a chair and watched.  It would turn a little and then stop.  Then the same thing in the opposite direction.  I saw the power in being able to control every movement.   

OperaHouse

  • Hero Member
  • *****
  • Posts: 1308
  • Country: us
Re: Operate two fridges, one at a time
« Reply #8 on: December 03, 2016, 12:34:41 PM »
                    TEST PROCEDURE

To test this software two 100W lamps are needed to simulate the load. A
100W lamp represents about .8 amps. Start out with both lamps unscrewed.
With the micro plugged into the laptop USB, go into TOOLS in the Arduino
program and click on SERIAL MONITOR.  Data should start appearing on the
screen. To the right will be the timer data in minute : seconds format.
Initially it will say #1 ON.   At four minutes it will change to #2 ON.
The far right number is the PWM of the relay. 0 is off and 255 in totally
on, but you will not see that number. The number decreases with each loop
of the program and drop about 25 each time the data reads out till it reaches
169 where it will stay. Play around with that number in the program till
you see the relay drop out. It is surprising how low it will go.  At really
low currents it will be unreliable and mechanical vibration can make it
unlatch.  Stay at least 40 counts above drop out for reliable operation.
At 5 minutes it will turn off (0) and #1 ON will appear.

Go into the program and comment out // the line that sets raw data to the
offset value and reload.  The program will now read current sensor data.

Raw data number should closely match the offset.  Offset can be changed
later to match the most common raw data value. Screw in lamp #1. The raw
data will be changing. If load is DC it will stabilize around one number.
The ABS is the absolute value of the last reading. AC will have + and -
currents. ABS makes both values positive.  Otherwise adding all these
numbers would be zero.  Current is the total of 25 samples in ma. It is
divided by 1000 to get amps. Trip current is about .7A at this time.
Simulators are in the program for these currents.  With #1 lamp screwed
in at 4 minutes the relay will not activate. At 6 minutes the minute timer
will reset.  Unscrew lamp #1 and screw in lamp #2.  At four minutes lamp
#2 will light and stay on.

Screw in lamp #1.  Lamp #2 will stay on.  Unscrew #2 and lamp #1 will then
light when 5 minutes is reached.

george65

  • Sr. Member
  • ****
  • Posts: 499
  • Country: au
Re: Operate two fridges, one at a time
« Reply #9 on: December 05, 2016, 01:30:04 AM »
Quote
This uses a single ACS712 5A current sensor and a mechanical relay.

Looking at these sensors, does one run the line  to be measured through them?
I notice they come in 30A models but the terminals look a bit doubtful at that amperage.

I don't see any mention of connecting them to a coil so they appear to be direct connection..... which doesn't seem great at the higher amperages.