Introduction
This example shows how you can use the PeekyPokey to control a lamp wirelessly from your Windows PC.

For this, I’ll be using a radio controlled wall outlet containing a relay-driven power switch. Simply connecting a radio transmitter will turn the PeekyPokey into a wireless remote making the wall outlet respond to your slightest bidding.

Example of receivers 

Parts needed
Only very few external parts are needed, see further down for more information on each of these items:

Parts needed 

Tech background
There are a number of different vendors of wireless power switches, each using their own protocol standard. One of the more common ones in Europe is the Nexa system using various other names (Proove, CoCo, KlikAanKlikUit and others) in different countries.

Being sold mostly in Europe, the Nexa system operates at 433.92Mhz radio frequency while as in some countries (like the U.S.) 315Mhz is used.

Here's a more in-depth analysis of how these receivers work internally:
http://articles.logicapplied.com/#post0

A few typical radio controlled wall outlets are depicted in the introductory photo (see top of this page). These all contain a radio receiver and a relay. The receiver listens for ON/OFF messages and when an ON message is received, the relay is pulled thus effectively powering the jack. When the the receiver detects an OFF message, the relay is relaxed and the jack becomes powerless. Very simple, very effective.

Normally, you'd use a remote control like this one to control the outlet:

Nexa remote

However, instead of having to operate the remote manually, a small radio transmitter module will make the PeekyPokey able to take its place in becoming a wireless remote. This allows you to operate the power switch from the comfort of your Windows PC.

Currently, the PeekyPokey API supports the Nexa, Waveman and Rising Sun type of receivers. The API also supports the Nexa self learning system including absolute dimming functionality. 

The key component is a small 433.92Mhz radio transmitter module like this one:

Typical 433 transmitter

These transmitters are available from various on-line market places for electronics. They are very cheap and pretty small, only about 10 x 20 mm in size. Despite their modest looks, they are quite versatile when it comes to the wireless control of things. Depending on power feed (3 - 12V), you can expect a range from 10 to 30 meters indoors.

Wiring
Firstly, disconnect PeekyPokey from your Windows host PC. Connect jumper wires between the PeekyPokey and radio transmitter module according to the table below: 

PeekyPokey

Transmitter

Remarks

Vdd

Vcc

Select the +5V position on the slider switch of the PeekyPokey

GND

GND

Put a small capacitor between the GND and Data pins to smoothen the signal a bit. A small ceramic capacitor in the range of 47nF to 1uF should do.

TX

Data

 

Ant

For the antenna, you can use about 170 mm of single-core wire (the long red wire shown in our images)

When done wiring, here’s what your setup should look like:

PeekyPokey  based 433Mhz transmitter 

Adding a pinch of software
Before starting to code, you need to find out what message your receiver requires for turning the power switch on or off.

There are a couple of different methods for this – some receivers have two rotating switch knobs to select a certain house code (A…P) and button (1…16) that your receiver will listen to. Others use a so called “self learning” system that allow you to pair it with a remote button of your own choosing.

In my case, I'm using a Nexa self learning receiver. Refer to the manual of your particular receiver for details on pairing it.

When you've found out what command to send, launch Visual Studio and follow these steps: 

  1. Create a “New project” of type C# Windows Forms application named "Nexa"
  2. Add a reference to the PeekyPokey.DLL file
  3. Double click the file “Form1.frm”
  4. Add two Buttons named “btnON” and “btnOff” respectively
  5. Double click on each button to create default event handlers for them
  6. Add a Trackbar slider control and name it “tbDimmer”
  7. Double click on the slider to create a default handler for it
  8. Configure the slider so that it ranges from 0 (zero) to 16.
  9. Replace the code in Form1.cs with the contents of the snippet below

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace NexaTest
{
    public partial class frmMain : Form
    {
        private PeekyPokey.Toolkit.Rf.NexaSelfLearning _nexa;

        public frmMain()
        {
            InitializeComponent();

            // create the PeekyPokey Nexa driver, choose any number
            _nexa = new PeekyPokey.Toolkit.Rf.NexaSelfLearning(2341234);
        }

        private void btnON_Click(object sender, EventArgs e)
        {
            _nexa.Send("11d", true);
        }

        private void btnOff_Click(object sender, EventArgs e)
        {
            _nexa.Send("11", false);
        }

        protected override void OnClosed(EventArgs e)
        {
            base.OnClosed(e);

           _nexa.Dispose();
        }

        private void tbDimmer_Scroll(object sender, EventArgs e)
        {
            _nexa.Send("11", tbDimmer.Value);
        }
    }

I've chosen to mimic button #1 of unit #1 of a Nexa self learning receiver with dimmer and hence, there’s a string literal “11” in my code above.

If your receiver supports dimming like mine does, the slider can be used to fade the light. If your receiver is not capable of dimming, then the slider will have no effect. The ON/OFF buttons should work in either case though. 

Connect the PeekyPokey to your Windows PC and then launch the PeekyPokey Dashboard tool. Configure the board for TX LED on Gpio7 and choose to invert the UART. Don't forget to save the profile before closing the Dashboard tool.

 

Take it for a spin
Now, plug a lamp into the power jack of your receiver and fire up the new Windows application you created earlier and you should see something like this.

PeekyPokey Windows Forms application

Have fun playing with the buttons and slider to control your lamp!

 

TIP #1: By adding a web server from the PeekyPokey API, you’ll be able to control your lamp from a networked device such as a smartphone (such as iPhone or Android) using your Windows PC as a home automation server. 

TIP #2: Remember the PeekyPokey also has a set of eight general inputs and outputs? Have a look at some of the other example projects for inspiration on things you might want to add to your smart home server.

Last edited Feb 3, 2014 at 9:02 PM by hanzibal, version 18