Monday, 21 March 2016

Raspberry PI - Swimming Pool Solar Controller Project - Part 3

Sensor Locations 

To control the pool temperature sensors are needed. The above image shows the sensors I have installed. They are not all needed to control. I decided if I'm building my own controller then why not go all out. The middle pool and roof sensors are all I need to control and the flow was used by the old controller so I may reference that too.

Controlling Pool Pumps 

I have worked out the control logic for the pumps. 
Below I show sample code sections to give to an idea of my thinking but not the whole program. But this should be useful if you have a similar project.

Cleaning Pump Control

Cleaning/Chlorination plump needs to run AM and PM for between two and 4 hours each time depending on the time of year. 

The solution requires two schedules to do this I created an array of items as below in Schedule 1 & 2.

Schedule1=['1','06','00','On','09','00','EveryDay'] #Pump1 AM
Schedule2=['1','18','00','On','21','00','EveryDay'] #Pump1 PM

Schedule 1 array values are as follows:
Pump No 1, Start time 06:00, State On, Stop time 09:00, run every day.

The code to check the schedule against time and turn on the pump:-

PumpCMD[1] = "Off"
TimeNow =
SC_Start = datetime.time(int(Schedule1[1]), int(Schedule1[2]))
SC_Stop = datetime.time(int(Schedule1[4]), int(Schedule1[5]))
if ((TimeNow.time() > SC_Start) and (TimeNow.time() < SC_Stop)):
    PumpCMD[int(Schedule1[0])-1] = "On"

line 1/2 - Initial command value for the pumps is Off 
line 3 - Get the current time and date TimeNow
line 4 - Convert the Schedule1 values 1 & 2 to a start time date value
line 5 - Convert the Schedule1 values 4 & 5 to a stop time date value
lines 6/7 - If the time is between the start and stop time turn PumpCMD value On
lines 8/9 - if not turn the CMDPump off this value is used latter to turn on the pump.

Solar Pump Control

Solar pump needs to run during daylight. But it also needs the correct temperature conditions and run for a minimum of time so the pump is not damaged.

1. The system is activated between 09:00 and 20:00 to do this I used the same time control as the cleaning pump. This enables the variable SolarTimeCMD.
#Solar Pump Schedule
TimeNow =
SC_Start = datetime.time(int(Schedule3[1]), int(Schedule3[2]))
SC_Stop = datetime.time(int(Schedule3[4]), int(Schedule3[5]))
if ((TimeNow.time() > SC_Start) and (TimeNow.time() < SC_Stop)):
    SolarTimeCMD = True

2. Roof Temp must be 10 DGC higher than the pool temperature.(So the water will be 
heated when pumped to the roof).  
#Solar Pump variables reset
SolarReady = False
SolarRequired = False
SolarDiffOn = False
SolarPumpRunOn = False
StartSolarPump = False
RunSolarPump= False
SolarTimeCMD = False
if (Temp[1] > (Temp[3]+10)): #1=Roof Temp 3=Mid Pool Temp
    SolarReady = True

3. The Pool temperature must be below the solar setpoint
if (Temp[3] < PoolSP): #3=Mid Pool Temp
    SolarRequired = True

4. Once the pump is running it must stay on until it reaches setpoint + differential (This is to stop the pump going off and on too often and trip a breaker)
if (Temp[3] < (PoolSP + PoolSD)) and (PumpCMD[2] == "On")
    SolarDiffOn = True

5. Also it's a good idea to have a minimum pump run time of 5 minutes (Same reason as above)
if (TimeNow.time() < SolarPumpRunOnTime.time()):
    SolarPumpRunOn = True

6. If the pump is to be started the SolarpumpRunOnTime is set to current time + 5 minutes.
if (SolarTimeCMD and SolarReady and SolarRequired):
    StartSolarPump = True
    SolarPumpRunOnTime = TimeNow + datetime.timedelta(minutes = 5)

7. The CMDPump request is finally turned on if all conditions are met
if (SolarDiffOn or SolarPumpRunOn or StartSolarPump):
     PumpCMD[2] = "On"
     PumpCMD[2] = "Off"

8. Latter in the code the Raspberry Pi GPIO is used to turn on a relay that starts the pump.
9. In the actual code there is also a override section to start or stop the pump regardless of the pool conditions.

Wiring and connections

The controller requires internet (Well it doesn't really need it but I wanted to connect the controller to the network and run a web site from it). The problem is WIFI does not work well through a metal shed so I had to find another way. I used PowerLine plug in modules from D-Link and they work a treat sending Ethernet over my electrical power supply.

The controller has now been installed in my pool shed. This is when I realised that having connections bottom and both sides may of been a mistake. I had to make room for the connections at the bottom. I know it looks a mess but I will refine it latter. The pumps are not connected in this picture they plug in the bottom of the unit.

Putting sensors in the pool was tricky. I used a plastic coated garden stake (Used for tomatoes) bent it 90 degrees and cable tied sensors (Water proof 10K NTC with 1.5 meter cables) to it then solders the cable to the sensors and used heat shrink to protect the connections.

This is what it looks like installed the wires and pole are held in the wall expansion then they are threaded under the bricks in a round conduit to the controller in the shed.

Monday, 7 March 2016

Raspberry PI - Swimming Pool Solar Controller Project - Part 2

Project issue to be resolved in this part

The devices worked quite well but there are a few issues
1. All the wires on the soldered board were looking messy 
2. The connections are becoming a bit unreliable. 
3. Its too big for most boxes

4. The keypad and screen need mounting some how

Building a custom PCB

It became clear as I added more inputs and outputs that the board was becoming messy and was too big so I downloaded Eagle software and designed a custom PCB and got it built here it is without components.
Link to Design and make a custom PCB

I was happy with the board and soldered the components and added headers for the keyboard, real time clock, outputs and LCD display. 

Board testing success below.

All the parts required for the build laid out. I got the relays from Ebay and the power supply from Element 14. 

Now just a box to house the parts. I decided to buy this from a Jaycar shop it was a bit more expensive but I could pick it up and look at it before buying.
Power input on the left with fuse and the pump outputs at the top.

The Lid is to hold the LCD display and keypad. I could of done a better job of cutting the holes but it will be covered. 

The display, keyboard, LED's and switches installed in the lid.

The custom PCB power supply, relays and outlets installed in the box. The Raspberry PI will go on to of the main board on the left. I tried to keep the power on the right away from the electronics.

Working mounted in the box

Created a cover sheet for the lid using paper and a laminator. Now it's looking better.

Ok that works quite well but its still on my desk so more work is required.

Raspberry PI - Swimming Pool Solar Controller Project - Part 1

Project goal

1. Build a controller that will control my swimming pool's temperature using a Raspberry PI. 2. The system will need to have manual overrides for the pool pumps that anyone can use.
3. It will need to be controlled at the device with a keypad and display by anyone. 

4. The controller will need to turn on the cleaning pump by time schedule. 
4. The controller will need to turn on solar pumps by time schedule and depending of temperatures. 

External Components

Solar Panels.
Solar Pump.
Chlorination/cleaner pump.
Pool pump flow temperature sensor.
Pool Top temperature sensor.
Pool temperature sensor.
Outside air temperature sensor.
Roof temperature sensor.
Unit temperature sensor.
Internet connection for remote access.

System control components

Keypad (up,down,left, right and ok buttons).
4 x 20 LCD Display.
240 VAC supply plug for system and pump systems.
2 x 240 VAC 10 A relay outputs for the two pumps.
Override switches one for each pump (5V logic not power).
LED's for run status, pump status and alarms.
Real time clock.
Fuse 20A Slow blow (Pumps pull a large current starting)

Software requirements

1. Two start and stop schedule periods for cleaning pump.
2. One time schedule period for solar pump (Day light hours).
3. Pool temperature setpoint.
4. LCD Display and keypad with temperature and settings must be easy to use.
5. Web interface for access using mobile phone or PC.

Stage 1 - Bread board the concepts

I built a small bread board circuit of each item I needed and tested it until I was happy with the connections and operation.
3. Shift output chip for outputs - Link to Adding more outputs using the 74HC595
4. Shift input chip for the basic keypad - Link to Adding more inputs using the 74HC165
5. All of the item together

You can see a 16 x 2 LCD at the top. The sensor chip bottom left, shift output chip top right, shift input chip bottom right and a bread board keypad on the right. I was using pots for sensors.

Stage 2 - Solder on a PCB board

I then re-built the circuit on a standard PCB and soldered wires and components.

I then decided that a 20 x 4 LCD would be better. I decided that I would need to mount the LCD and keypad in the lid so I put them on ribbon cables.

The devices worked quite well but there are a few issues here
1. All the wires are starting to look messy 
2. The connections are becoming a bit unreliable. 
3. Its too big for most boxes
4. The keypad and screen need mounting some how