Water Heater Controller / Scheduler

6.9K8710

Intro: Water Heater Controller / Scheduler

This instructable will show you how to build a simple water heater controller using a Raspberry Pi. This is intended to be used with a knob style thermostat control found on most electric and gas tank water heaters and does not require modifying your existing thermostat control or water heater in any way.

Disclaimer: This system is not designed to be robust in any way. While it is useful for controlling the thermostat settings on a schedule one should consider using only when it can be supervised.

STEP 1: Materials Required

SOFTWARE

  • Microsoft Visual Studio 2015 Community Edition

https://www.visualstudio.com/en-us/products/visual...

  • RaspberrySharp.IO solution file

https://github.com/raspberry-sharp/raspberry-sharp...

  • Mono (on Raspbarrian) We will get to that later
  • Win32 Disk Imager (optional for writing OS images to SD cards)

http://sourceforge.net/projects/win32diskimager/fi...

  • WinSCP (for copying files to the Pi)

https://winscp.net/eng/download.php

  • Putty (for remote console access - optional if you have the Pi connected to a monitor)

http://www.chiark.greenend.org.uk/~sgtatham/putty/...

HARDWARE

  • Raspberry Pi Model B

https://www.adafruit.com/products/998

  • 4GB SD Card for Raspberry Pi Pre-installed with Raspbian Wheezy (The easy route if you do not want to download and write your own OS images to the SD card)

https://www.adafruit.com/products/1121

  • Adafruit Assembled Pi Cobbler Breakout + Cable for Raspberry Pi

https://www.adafruit.com/products/914

  • Half-size Breadboard

https://www.adafruit.com/product/64

  • Breadboard Jumper Wires

https://www.adafruit.com/product/153

  • 22AWG Solid Core wire (you can also use this for jumper wires but I recommend getting both)

http://www.amazon.com/BLUE-22AWG-Solid-300V-Hook/d...

  • Dual H-Bridge Motor Driver for DC or Steppers - 600mA - L293D

https://www.adafruit.com/products/807

  • DC 12V 0.07A 3.5RPM High Torque Gear Box Electric Motor 37mm

http://www.amazon.com/RioRand-0-07A-3-5RPM-Torque-..

  • 1 X 37mm DC Geared Motor Mounting Bracket Holder + 6mm Hex Coupling

http://www.amazon.com/Geared-Mounting-Bracket-Hold...

  • 12V 1A Power Supply

http://www.amazon.com/Wall-Adapter-Power-Supply-12...

  • If you plan on using wifi you will want an adapter for your Pi

https://www.adafruit.com/products/814

  • To protect the Pi you may also want to consider a case enclosure for Raspberry Pi Model A or B. I used the one linked below but Adafruit offers a variety of cases

https://www.adafruit.com/products/1326

CREATIVITY

The only parts I reused (did not purchase specifically for this project) is the plastic component for connecting the motor shaft to the water heater thermostat control, and the base that the motor is mounted on. This should not be a roadblock though, as I am sure there are other materials that will work just as well. I will provide some alternatives in the "Preparing the Motor" step.

Additionally not all water heater thermostat controls are the same, and not all water heaters are easily accessible or near a power source. So be sure to examine your water heater controls and accessibility before starting this project.

TOOLS

I will say now that the soldering required is minimal. You just need it to connect the wires on your motor.

  • Soldering Iron

http://www.adafruit.com/products/180

  • Soldering Iron Stand

http://www.adafruit.com/products/150

  • Solder

http://www.adafruit.com/products/145

  • Wire Cutter / Stripper

I will mention that you may be able to get away without soldering as the wires easily wrap around the leads on the motor. I recommend soldering them just to ensure good conductivity.

STEP 2: Preparing Raspberry Pi

If you are new to Raspberry Pi you can go to https://www.raspberrypi.org/help/quick-start-guide...

If you ordered the pre-installed SD card you are pretty much set. Just insert the SD card plug in a keyboard, an HDMI monitor/TV and power up the Pi. For the sake of brevity I will assume you already have the Pi powered up with an internet connection.

If you have not already enabled SSH you will want to do that.
https://www.instructables.com/id/Use-ssh-to-talk-wi...

If SSH is enabled you can use Putty to connect to your Pi over your network. This way you do not need to keep a keyboard and monitor hooked up to your Pi.

Before disconnecting the keyboard and monitor you can obtain your Pi's IP address by typing:

ifconfig

Using the IP address of your Pi you can connect remotely via SSH using Putty:

  • Double click Putty.exe and enter the IP address of your Pi, then press Open.
  • Login using your credentials (default username is pi)

This project is done in C# so you will want to install Mono. Be patient it may take a bit. Type the following:

sudo apt-get install mono-complete

The Pi is now ready to run the controller software that we will write using Microsoft Visual Studio on a Windows machine.

Beyond this project if you want to learn more about writing C# apps on the Pi (and Linux in general) check out:
https://www.maketecheasier.com/write-c-sharp-progr...

STEP 3: Preparing the Motor

Using the AWG22 wire:

  • Cut 2 wires about 4" in length
  • Using the cable stripper remove the plastic insulator exposing about 1/8" to 1/4" of the copper
  • Connect these to the leads on motor by wrapping the exposed copper wire through and around the hole

Now heat up the soldering iron and apply a small amount of solder on the wire and leads. Don't worry it does not need to be perfect.

If you have no experience soldering this is a good start since it is not really risky or difficult.

If you refine this project or have another project that requires more soldering I suggest taking a look at:
https://learn.adafruit.com/collins-lab-soldering

Mounting the Motor to a Base

Time to get creative...

One part that I reused was a stainless steel base from a paper towel holder as a base for my motor. If you ordered the Motor Mounting Bracket Holder then all you need is something heavy that you can screw the mounting bracket to.

Of course, this will depend on how much space you have where your water heater is located. I also used a small stool that I sat my base on.

One alternative is to simply use a wood block of some sort, like a 1 foot section of 4x4. That should be heavy enough and easy to screw the mounting bracket to. While I did not test this myself, I am confident it will work. The base is just something for the motor to sit on that will provide stability.

For other ideas on creating a base, stand or both I suggest browsing through other instructables. PVC looks like a versatile material that is easy to work with:

https://www.instructables.com/id/How-To-Make-Cheap-...

Connecting the Motor Shaft to the Water Heater Control

I also used a spare plastic part from a toy to connect my motor shaft to the water heater thermostat control. Your water heater control may be different so you will want to examine your control first before going this route.

One alternative is to use the top of a prescription medicine bottle. Really any plastic bottle top with large enough radius and sufficiently strong should work. The idea is to cut a small hole that will fit tightly over the motor shaft. Then connect it to the water heater control using two 3/4" wood screws. NOTE: The screws should barely be longer than the bottle top. You do not want to screw too far into your thermostat control.

  • Mark the center with a marker
  • Start cutting a small hole and check to see how close it fits

Do not cut the hole too big. It should be just large enough where you can force it onto the motor shaft.

Once you have a good fit remove it. It will be easier to screw to the water heater control.

Using a screwdriver (power tools not necessary or recommended):

  • Begin screwing into the bottle top on each side on a flat surface.
  • Place the bottle top over you water heater control and firmly continue screwing into it.
  • Force your motor shaft back into the top.

STEP 4: Wiring Up the Pi

Using your jumper wires, follow the layout above to connect your motor, power supply, L293D chip to the Pi. This is from an Adafruit tutorial, the only modifications is that we are using a 12V 1A power supply rather than a battery pack.

Source:
https://learn.adafruit.com/adafruit-raspberry-pi-l...

If you have never wired up a breadboard before, do not fear. The wire colors in the case do not matter. Just emulate the diagram above by using your jumper wires. Your L293D chip will pop right into place. If you are still uncomfortable I suggest watching this video - it will make you feel better:

https://learn.adafruit.com/collins-lab-breadboards...

For the power supply I simply cut the connector off the end to expose the wires. I then stripped the wires and plugged them directly into the breadboard. If you do not want to cut your power supply you can get an adapter at Adafruit:

https://www.adafruit.com/products/368

STEP 5: Prepare Visual Studio: Raspberry Sharp IO Solution

If you have not installed Microsoft Visual Studio 2015 Community Edition on a Windows machine you will want to do that now. It is free although you will have to create a Microsoft account to continue using after 30 days of installing.

Once you have Visual Studio 2015 installed you will want to extract and open the Raspberry Sharp IO solution file.

  1. Right click on raspberry-sharp-io-master.zip (download link in Step 1) and choose Extract all.
  2. In Visual Studio go to File -> Open Project/Solution
  3. Browse to where you extracted the raspberry-sharp-io-master folder and open the RaspberrySharp.IO.sln file.

STEP 6: Prepare Visual Studio: Scheduler Project

Download and extract the Scheduler.zip file (Attached Below). It contains the Scheduler program Visual Studio project. For organization purposes I suggest extracting the Scheduler into the raspberry-sharp-io-master folder that you previously extracted.

In Visual Studio add the Scheduler.csproj to the current solution:

  1. In the Solution Explorer right click on Solution Items and select Add -> Existing Project. Browse inside the Scheduler folder that you extracted and open the Scheduler.csproj file.

This should open the project and the Program.cs file.

STEP 7: Editing and Building the Scheduler Program

Edit

Before building the Scheduler you may want to change some things.

You can change the path to the schedule file by editing this line at the top of Program.cs

const string SCHEDULE_FILE_PATH = @"/home/pi/scheduler/schedule.txt";

To change the log paths alter these lines in Logger.cs

const string SCHEDULE_LOG_PATH = @"/home/pi/scheduler/logs/pi_schedule.log";<br>const string ERROR_LOG_PATH = @"/home/pi/scheduler/logs/pi_error.log";

Once you have made your changes, or if you leave the default, be sure to create the directories and files using the path and name you defined in the code.

To create a directory when you are logged into the Pi type:

mkdir /home/pi/scheduler

To create a new blank file type:

touch /home/pi/scheduler/schedule.txt

Do the same for the log files.

Build

In Visual Studio to build the project go to Build -> Build Scheduler

This will build the Scheduler.exe file and place all the dependent files in the bin\Debug directory of your project. Your project will be under the raspberry-sharp-io-master folder.

For instance the bin\Debug directory of the Scheduler project on my development machine it is:
C:\pi_dev\raspberry-sharp-io-master\raspberry-sharp-io-master\Scheduler\bin\Debug

STEP 8: Running the Scheduler on the Pi

Using WinSCP you can easily copy your build project files to the Pi. Browse to your bin\Debug folder on the Windows machine and then to your folder on the Pi (/home/pi/scheduler).

Copy all of the files from the bin\Debug folder on the Windows machine to your directory on the Pi.

Now create your schedule in the schedule.txt file. Be sure to enter your schedule in the format of ScheduleTime, ScheduleCommand with each time being on a new line:

6:39 PM, HEATUP
6:40 PM, HEATDOWN

You can add as many scheduled events as you want. You might want to start by testing.

Use Putty to connect to your Pi for remote console access so you can run the scheduler.

The scheduler has a few arguments you can run besides just the schedule.

To test running the motor forward:

sudo mono Scheduler.exe Forward

To test running the motor reverse:

sudo mono Scheduler.exe Reverse

To test reading the schedule file:

mono Scheduler.exe Schedule

When you are ready to run the scheduler run it without any arguments and append an & so it will run in the background:

sudo mono Scheduler.exe &

Once the scheduler is running you can logout of the Pi. As long as the Scheduler program is never killed (which should only be because of power failure or a reboot) it will run indefinitely.

If you modify the schedule.txt file you will need to kill the Scheduler program start it again so it will re-read the schedule.txt file. Unfortunately since I did not include a script to restart it you will have to kill it manually.

STEP 9: Troubleshooting

Build Errors

If you receive an error building your project and it is related to missing Raspberry.IO.GeneralPurpose reference you may need to add it to your project:

  1. Right click on the Scheduler project and select Add -> Reference
  2. In the Reference Manager click to toggle on Raspberry.IO.GeneralPurpose and click OK

Runtime Errors

If the Scheduler throws an exception when the timer fires or when trying to test the motor using the supported arguments, it may be because you are not running with necessary privileges. Be sure to run it as sudo.

Motor Unresponsive

These type problems can be difficult, however, many times it is something simple.

  • Check to ensure power is supplied for the motor (this is the 12V 1A power supply)
    • If the power supply wire is stranded (not solid) it can be a pain, twist the wire so to get it as straight as possible
  • Ensure all your jumper wires are connected fully (reseat them to ensure)
  • Check your wiring, review the diagram and ensure all the pins are connected correctly.
  • Unplug the motor from the breadboard and wire it directly to your power supply to ensure they both work (if so then you know it is definitely something wrong in your circuit) Be sure to match the hot and neutral wires.

STEP 10: Wrap Up

The Pi is extremely overpowered for this project, however, that power provides flexibility to add onto it. For instance it is not difficult to write a web app on the Pi to control the water heater using a web browser - on a phone as well.

I plan to add those sort of capability to this project as well as experimenting with servos. I believe the best and safest implementation would be to use a servo with analog output to allow detection of the beginning and end of the thermostat. This would prevent the possibility of burning out the motor and allow it to be calibrated so that the program could keep track of the temperature. That is outside of my ability for now but I will update this instructable with any additions/changes.

9 Comments

Have you been using it long enough to see any results in terms of energy savings? I'd be curious to know what kind of difference this makes. This might also be something to try with Windows IoT Core though you'd need to use a Raspberry Pi 2 for that.

No about 3 weeks. I am in the process of downloading all my natural gas usage to for the past 12 months. I will be comparing.

I had the same idea for my water heater. With winter coming, it should make a fairly significant difference. Please post what kind of energy/$$$ savings you have for this system.

Really cool! Thanks for sharing.

More of an experiment and learning exercise for myself, just thought I would share.

I find that I do not need a 60 gallon tank always heated. So I just wanted to see if I could have it be set to 'vacation' for the majority of the day and then turn up near the evening so I have enough for a shower, laundry, dishwasher, etc.

I did mention that using the Pi is a bit overkill but it makes adding functionality (like remote control) easier.

When I have the money I plan to install a tankless water heater. So yea perhaps this is a bit absurd.
It was the wrong time for me to be commenting upon anything. Sorry!

This is probably not feasible for gas water heaters in the US, and one
should take into consideration the following points.

Soldering in an enclosed space with gas. Maybe not a good
idea.

When turning gas heater on, a “push and hold” action is
required. Perhaps not turning the gas completely off, rather very low may work.

The idea could work
well for an electric water.

Mine is gas and it works fine. I just scheduled it to turn down to the 'vacation' setting during the night and most of the day. It turns up for about an hour in the afternoon, just enough to supply hot water for a couple of showers. I have a 60 gallon heater and I am experimenting to see if I can save some $$.

I guess I did not do a good job explaining. You want to assemble the device away from the water heater. I did the soldering in my shop not near my water heater.

This is such a fun idea! I love automating anything and everything!