Controller – BME280 Sensor

This is the most challenging phase of the hub project – implementing the BME280 Sensor. This sensor is an amazing piece of electronics: providing temperature, humidity and pressure measurements all for under £10. There is one small snag however; the sensor comes with I2C and SPI interfaces which are designed for very short distance communications e.g. where the sensor is mounted on the same pcb as the controlling processor.  This conflicts with our requirement to have sensors many metres from the controlling Pi.

The Pi has I2C and SPI interfaces, so we might be tempted to use a pi zero as a slave bridge, but this is slight overkill and would be a software maintenance overhead.

All is not lost however. The Pi also has a a serial interface, and this is much more suitable for transmission over long distances, especially if we can operate at low baud rates. So all we require is a serial to SPI converter. A quick trawl of the electronics catalogues didn’t throw up any suitable candidates, so I decided to make one with a PICAXE programmable chip. Once you overcome the apprehension of working with yet another programming language (the PICAXE is programmed in a proprietary form of BASIC), the implementation is straightforward. The setup has been working flawlessly in my installation for many months.

You can download the PICAXE program from here.

I used the smallest of the PICAXE family – the PICAXE-08M2. This is an 8-pin device, which after power and serial tx/rx leaves 4 pins to use for the custom SPI interface. Some of the larger devices have SPI capability built in, but in the interest of economy this design uses software.  Here is the circuit diagram:

You will need a prototyping board and download cable in order to transfer the program to the picaxe chip, but these are very reasonable and can be reused for other projects. The circuit can be built on veroboard, or alternatively, you can find details of a custom PCB here:

I would recommend using sockets for the picaxe chip and the sensor, as lightning-strike damage is not unheard of.

I was fortunate to have a redundant overflow pipe in my property, which served as a convenient conduit for exposing the sensor to the external environment.

In the next post we will install the Sensor Helper.

Impulse Electronics

A simple switch connected between a spare GPIO pin and ground will be sufficient to test impulses, however, in real life it will likely prove to be very unreliable. Depending on the length of the wires, and the amount of electrical noise in the locality you can expect false triggers.

The code uses the RPi.GPIO library’s event detection facility, to register a callback function which is invoked when a button is pressed. The feature has a debounce parameter, however it can be difficult to set this to the optimum value.

The solution is to add an opto-coupler such as the ILQ74 quad package. The led input side is fed from the pi’s 5V supply, through the switch and a 1k resistor to ground, and the output transistor connects the GPIO input pin to ground.  The principal here is that a much larger current is required to light the led and trigger the input. Extraneous noise will be insufficient to trigger it.

Now we have the electronics sorted we can configure our impulse.

Electronics – Add Actuator

Second only to the buzz you get from making real-time temperature measurements with your raspberry pi, turning on relays has to be up there!  When they are controlling actual fans, boilers and valves then the rewards keep coming, on a daily basis.

A polite warning here.  Doing real work in the home will involve messing with mains electricity. Please please please get a professional or competent person to install the necessaries if you are at all unsure.

Connecting relays to the pi is even easier than sensors. there are some gotchas to watch out for, but a quick search on google/amazon/ebay will return plenty of sources and information. The type I favour come in single/dual/multiple banks and are opto-isolated, so cooperate nicely with the 3V output from the pi. They need 5V and Ground connections, but apart from that should be quite straightforward to interface. Here is my development setup:

When you have your relay connected you can install the necessary software. This is described in the next post.