OUTLINE

After purchasing an electric 3 seater triple recliner from a UK company (DFS) the press and hold buttons to raise and lower the seat seemed rather old fashioned. It should at least be semi-automatic in that a tap of a button takes the seat to the next or previous pre-defined position. Having it controlled over HTTP would also mean that it could be controlled from any device capable of doing an HTTP GET request.

PROJECT GOAL

INITIAL TESTING

ELECTRONICS

It seems that most electric recling sofas and armchairs use a stanard 5 pin din plug between the control system and motor. I'm not sure if there is a standard or not but I believe it is just because the 5 pin din connector can handle high power throughput. This brings me onto the pinout.

3. Live
5. Down button / Motor terminal 1
2. Up button / Motor terminal 2
Shield. Ground / Negative

The sofa requires 32V DC and uses in the region of 2A. All power travels via the switches directly to the motor. The switches are connected to one of two terminals on the motor and when open (not pressed) are connected to ground. When a button is pressed the live current is sent to the motor allowing the buttons to power the motor in either direction. This is easily controlled via a SPDT (single pole, double throw) relay which will allow for the motor to be connected to ground until one the relays is thrown to live. Each seat will require two relays so the sofa will require a total of 6 for movement. I have young neices so a 7th relay will also be used to turn the power off to the switches enabling a "parental mode".

I purchased a SainSmart 8 Channel DC 5V Relay Module which it turns out isn't made by SainSmart but can be purchased from 101 different companies on eBay for far lower prices. I chose this board for several reasons.

API

I chose to develop the API using Ruby. I hadn't previously used Ruby but as it is very easy to create RESTful API's using Sinatra and there's a great Pi GPIO library called PiPiper it seemed like a great choice. Ruby is well known as a language for creating RESTful API's on Linux.

CIRCUIT DESIGN

The circuitry can be broken down into two parts. The motors driver and the switch listening. The motor driver is very simple as I'm cheating and using a relay board which can plug into the RaspberryPi. The switch listening side is a bit more complex. As mentioned previously in its default configuration all power to the motors runs through the switches at 32V. The RaspberryPi GPIO header runs at 3.3V. I could use the 3.3V from the RaspberryPi and pass that through the switches but they have LEDs showing their active/pressed status which I wanted to keep. As the circuitry in the switchs is designed to accept 32V I need to make the voltage acceptable for the RaspberryPi.

Two possible options would be either using a voltage divider circuit to bring the voltage down to 3.3V or seperate them completly using optocouplers. If I had used a voltage divider and the powersupply spiked or one of the resistors blew the Pi would be toast. When the voltage can't be 100% trusted physical seperation is the way to go. The optocouplers I used come with two in a DIP package which is perfect as I need two per seat.

I used a great peice of software called Fritzing to design the breadboard. To the left side is the motor driver end which connects to the relay board. The right side is the switch sensing which takes the 32V from the sofa and sends the Pi 3.3V which it can work with.

For some reason I wanted to use 5 pin DIN connectors on the circuit board to match the sofa connectors. This really wasn't necessary as the seats require extension cables to reach the board anyway. But more on improvements later.

Now it was time to put this onto a real breadboard. As the circuit is repeated 3 times I only tested it with a single seat. In the picture below all three seats are plugged into the relay board but only one switching circuit is on the breadboard.

IT WORKS! As you can tell I'm far from good at building tidy breadboaords. Also with Pets and this sitting behind the sofa it would only be a matter of time before part of the breadboard was disassembled.

Another great feature in Fritzing is it can design a PCB which can then be produced by them in Germany. It even tells you how much your board will cost based on it's size. So for €30 I could get a high quality custom circuit board for my project! Fritzing can auto route your traces on the circuit board but it doesn't do a fantastic job. I'd recommend either running the traces manually (as I did for the V2 board) or using the autotrace feature and then improving it youself.

Finished V1 Design

Below is V1 Board Installed. It takes 2-3 weeks for Fritzing to build and ship the PCB by which time I had seen several flaws in my design, hence the use of jumper wires and missing connectors.

Improvements for Version 2

ANALYZING THE RELAY BOARD

From looking at the relay board and it's PCB design which is readily available I was able to reproduce it. This is basic stuff for anyone with electronics knowledge of which I have extremely little. Skip the next paragraph if you have a good understanding of transistors.

The relays I'd be using on the V2 board run at 5V so can be powdered by the 5V from the Pi. The activation needs to be controlled via the 3.3V pins on the Pi so we're trying to trigger a high voltage device with a lower voltage. This can be achieved with a transistor. Plug 5V into the + side of the relay and connect the - to the collector leg of the transistor. Connect the emitter leg to ground on the Pi and when a current is passed into the base leg a multiple of that current is allowed to pass from the collector to emittor. I used BC550 transistors which are rated at a minimum of 400 hFE. This is the minimum ratio between the current applied to the based leg and the current allowed through the collector to emitter. The relays I used require 35mA of power so I need to apply at least 0.08mA of power to the base leg. Easily managed by the Pi. This isn't enough to saturate the transistor so the gate is completely open so I used 2.2K resistors from the GPIO pins to apply 2mA to the base leg.