Andrew asked for a write-up, but this is probably shy of that. Feel free to contact me with questions.

The motivation for the project is that our house is cold in the winter, and it’s painful to go to bed without the bed warmer on. It’s difficult to remember to turn it on every night until it’s time to go to bed, but it takes a good 45 minutes to get nice and warm. The solution? A Raspberry Pi!

Sure, an entire computer is overkill, but there’s actually not an obvious solution that’s smaller. A simple lamp timer or X10 sort of device won’t work because it’s a soft-power switch. Even if you could make it turn on when power’s applied, it’s difficult to manually override.

The bed warmer has separate controls for each side, and this solution handles them separately. I started by wiring leads to one of the warmer controls. First across the switch contacts to be able to control and, and then also across the LED so that I could detect whether or not it was on.

I was able to determine that the GPIO pins on the raspberry pi should be sufficient on their own and I didn’t need anything fancy like a gertboard for this project. I ordered a pi breakout cobbler as well as a dish and solderless breadboard and some jumper wires from Adafruit. I bought a giant pack of resistors from Amazon.

I started with a sainsmart relay module to close the contacts on the switch. I initially figured I could do it with a transistor, but I was worried about interference and strange things happening if I tried a common ground between the Pi and the warmer. I ended up needing some NPN transistors anyway because 3.3V wasn’t going to flip the relay, but the +5V available on the GPIO worked fine.

There’s a ton of ways to access the GPIO pins on a Pi (Python seems to be the most popular). Probably for the purposes of this project the /sys interface and a bash script would have been sufficient, but being the C kind of guy that I am, I was very happy with the well-documented and very robust BCM2835 C library.

After demonstrating that I could flip the relays and turn the warmer on and off, I set about figuring out how to read the LEDs. Once again, I could use a transistor, but I was still worried about interference. Some searching on the internets led me to the wonderful world of optoisolators. I’d never heard of such a thing, but it’s exactly what I needed.

Unlikely the NPN transistors I was able to pick up at the Radio Shack in Woodland Park, optoisolators turned out to be more difficult to come by. I picked up a pair of NTE3083’s from a local store in Colorado Springs I had no idea existed, but they have a huge selection of components. the NTE3083 has a darlington step-up transistor which I don’t believe was at all necessary in my case, but worked just fine. I had to play around quite a bit to find a resistor value to power the LED side of the optoisolator that was just right. Too small, and the LED on the warmer would dim noticeably. Too high, and the optoisolator wouldn’t trigger. Once I figured that out by trial and error, I had a working prototype.

I wasn’t satisfied, though. The clicking of the relays was annoying, and I didn’t want to be woken up by them. (One of the design goals is that if we forget to turn a warmer off, the Pi can do that for us as well, because it’s seriously annoying to wake up at 1am drenched in sweat because you forgot to power the thing off.) Fortunately, my discovery of optoisolators would work well for activating the switch as well. I ordered some more optoisolators from Amazon.

A week later they still hadn’t arrived and I checked the Amazon order status. I failed to notice they were being shipped from Hong Kong and were scheduled to arrive at the end of December. So I gave up and ordered from Radio Shack. This time I went with an NTE3086, which had two opto-isolators on a single 8 DIP IC. Perfect.

Today I finally got around to testing with that. The only problem with this setup is that I used the same color leads from both sides of the switch contacts, because with a relay the order didn’t matter. Now that they’re going through a transistor, it very much matters. It was even simpler to connect the optoisolators than the relays (especially with the very nice and easy-to-locate datasheets that NTE puts on the web), and so I was ready to convert the prototype into something more functional.

I got a solderable breadboard that’s nearly identical to the solderless one I had so transferring the layout would be simple. Were I planning ahead, I would have put the solderable breadboard on top of the solderless one (as it was designed to do), because then you can just lift the solderable one up, flip it over, solder the connections and be done. As it was, I had to transfer it all without forgetting what went were. Not a big deal, but I’ll know if I ever do this sort of thing again.

I’d also spent an insane amount of time ordering some 22 AWG solid-core wire, because threading stranded wire through breadboard holes is a pain. I finally found what seemed like the best value on Amazon and ordered it. When I went to use the wire today, I discovered it’s stranded! I went and looked at the Amazon order and the one I ordered is clearly labeled “stranded”, though the solid core version looks exactly the same.

Anyway, after a day of soldering, modifying the second warmer controls, and then fleshing out and cleaning up the code, it’s done and it works! It’s the first bit of electronics I’ve ever created, and if it weren’t for the existence of the raspberry pi, its great documentation and an internet full of people messing with it, it probably would never have occurred to me to even try it. I really enjoyed hacking on hardware for a change, and I’m guessing that there’s more projects to come.

The source code is nothing fancy and contains nothing non-obvious, but if you’d like to take a look, I put it up on github.

4 responses to “Raspberry Pi Bed Warmer Controller”

  1. Kelsey Avatar

    This is incredible. You also should know that these sorts of tiny projects are the kind that make people millions of dollars with the right marketing!

  2. Volya Avatar

    How it’s work? Stable?

  3. Berck Avatar

    Perfectly. No probllems.

  4. Martin Avatar

    that is a very interesting project, are there any schematics/drawings available for this with a parts list?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.