Something for the weekend: Input dependant radio controlled sockets project on Scratch

20th November 2015

When it comes to using an Energenie radio controlled socket, there are a number of ways you can do so. Options for controlling these sockets include hand controllers, a Raspberry Pi or an Mi|Home gateway, each of which offer benefits.

However, using your Raspberry Pi to control one of these sockets is incredibly simple and allows you to control sensors, lights, switches and motors from a computer. This means you can ensure that all settings are as you want them, making controlling a socket much easier.

So what is the best way to do this? Scratch GPIO has been designed to make using Scratch on your Raspberry Pi much more straightforward. You are able to perform all of the functions listed above by using the GPIO pin. You can find out how to set up the ScratchGPIO here.

This guide will help you input dependent radio-controlled sockets on Scratch. We’d like to thank Trevor Olsson at for this project.

What you will need:

- A Raspberry Pi A,A+,B,B+ or 2
- Mouse, Keyboard, HDMI, monitor
- An Energenie Pi HAT
- Pimote:
- Radio controlled socket:
- Or the Pimote starter kit:


You will need to transmit 6 commands:
- Channel 1 ON
- Channel 1 OFF
- Channel 2 ON
- Channel 2 OFF
- All ON
- All OFF

How it is controlled by Software:

weekend 3 #2

The pin header connects to the add-on board as follows to allow you to control the GPIO lines as outputs to drive the radio frequency transmitter.

weekend 3 #3

Each board transmits a frame of information using On-Off-Keying (OOK) which is a basic form of Amplitude Shift Keying (ASK). This frame includes source address (20 bits) and control data (4 bits). See Appendix 1. The source address is randomly selected (so unique for that board), pre-programmed and cannot be changed. The socket will accept commands frames that have the source address that it learns during the learning process described later.

Here are the pairs of codes using D0-D3 signals that can be sent to control sockets:

weekend 3 #4

The pcb can, therefore, control a maximum of 4 Energenie radio sockets independently. However, more that one socket may be controlled by the same control code.

There are two parts to the transmitter. The encoder and the modulator.
1) The encoder will accept 4 input signal levels programmed onto 4 of the GPIO lines (D0-D3) as shown above. It will then serialise them on a single line to the modulator part.
2) The modulator transmits the serialised signal. It needs to be programmed in Amplitude-Shift Keying (ASK) mode for the sockets using a GPIO signal. It also needs to be enabled by a separate GPIO signal.

Create subroutines for each command like so:

weekend 3 #5

You will now be able to fully use Scratch on your Raspberry Pi to control a number of functions quickly and easily. This will help you get the most from your Energenie tech without the ability to do so being complicated.

Once again, we’d like to express our gratitude to Trevor Olsson for this project. You can find sample Scratch and Python programs in the Code Library section of the GPIO website.

Look out for our next project.

Get in Touch

Please use the form below to get in touch