Bare Paint Lightswitch: Using Bare Paint to Control a Mains Relay

This is one of the most exciting tutorials we've put up yet. We're going to show you how to use a pad of Bare Paint as a capacatence sensor (as seen in this tutorial here) to trigger a mains relay. To do this we are going to be using the code below and a cool relay shield from Ciseco on top of an Arduino Uno. The shield will switch up to 10 amps at 204V AC. Its important to note that this tutorial involves mains electricity and is POTENTIALLY DANGEROUS. If you're not comfortable working with mains electricity, then you should stop here and get help from someone who is qualified. Once you've gathered your materials and are ready to build, the first step will be setting up the sheild. 

 

Components

Capacitence Sensor:

Bare Paint
*Arduino Uno (or similar) UK: RS Farnell Arduino.cc  US: Jameco Sparkfun
Ciseco 10 Amp Relay Shield UK
*Jump Wires  UK:  Maplin  US: Sparkfun 
*USB Cable  UK:  RS Farnell  US: Jameco Sparkfun
*Resistors  UK:  Maplin  US: Sparkfun
Terminal Blocks UK: RS Farnell US: Jameco

 

Enclosure and Mains Connections (As this part of the project is highly specific we won't be providing any specific information):

Project Box UK: RS Farnell US: Jameco
Mains Cable UK: RS Maplin
Plug UK: RS Farnell Maplin
Sockets: Maplin 

 

Materials

 

 

Setting up the shield

Shield Setup

We are using a shield produced by Ciseco. It's got a 240 V AC 10 amp relay so its pretty tough! Its shaped to fit any standard Arduino or clone and is well laid out. We are going to be adding a couple of little pieces to the shield to work with the code that we'll be uploading later. First we want to place our terminal blocks on pin 4 and pin 2. The block spacing is such that it fits directly into every other pin. The pins on the terminal blocks might be a bit big, so you may want to make them a bit thinner with a file or sandpaper. Once you've got the terminal blocks on the shield, solder them in. 

Terminal Block

After the terminal blocks we need to add two additional wires, one for the signal to trigger the relay and the other to ground the Arduino. The signal wire (red in these photos) goes from pin 13 to the whole marked "input" on the sheild.

Input

Once you've soldered the input wire, take a second wire and solder it to one of the ground pins (the brown wire in these photos). The other side of this wire will be placed in the "earth" terminal block of the relay on the input side (see photo below). 

GND

Now that we have the basics of the shield prepared you can put it on top of your Arduino.

Together

Next we will add the wire to pin 2 to connect to our pad of paint and a resistor between pins 2 and 4. The size of this resistor will affect the sensitivity of your sensor, so you may want to play with other sizes to get the best effect.

Wire Connection

 

 

Wiring the Sheild

Now that your shield and Arduino are complete, we move onto wiring up the mains input and output from the shield. This portion of the tutorial is POTENTIALLY DANGEROUS. If you are not experienced and are not comfortable working with mains electricity do not proceed. Get help from someone who is competent working with mains electricity. 

We will first wire the output side. Using a section of 3-core mains cable, strip the insulation back to expose the ends. Wire the cable to the relay's terminal blocks as indicated, noting Live, Neutral and Earth. Secure the cable to the shield using cable ties. Wire the other side of the output cable to a socket, again, making sure that you have appropriately placed the cables.

Next, we are going to wire the mains input to the relay. It should go without saying, but NOTHING SHOULD BE PLUGGED IN at this point. Strip the 3 core cable and wire the Live, Neutral and Earth to the appropriate places on the relay. Secure the cable to the board with a cable tie. On the other end of the cable, we are going to wire a plug, again watching that each cable is wired correctly.

Wiring

You now have a mains input to your relay, an output to a socket and a shield mounted on an Arduino, cool! Its time to put all of this project into a box so that there is no risk of making any physical contact with the Arduino or the shield. This is a safety measure. Make sure that the box is secure and NOT CONDUCTIVE (i.e. don't use a metal box!). Triple check your connections and make sure that the cables can get in and out of the box with no restriction or binding and that you leave space for a USB cable so that you can program the Arduino.

Mounted Up

You'll want to cut some holes to route the wires through as seen in the image below.

Hole in Box

You could either run the capacative sensing wire through a hole in the box, or use a post type mounting via a small screw as shown below. I did this so that it would be easy to attach different lengths of wire to the box depending on where we mounted it.

Bulkhead

Exterior Wire

Make sure that you strain relieve any wires going out of the box (I just used some cable ties below). This way, if anyone pulls on the wires, they will only be pulling against a cable tie and won't compromise the shield itself.

Strain Relief

I decided to mount the socket into the cool transparent lid of my enclosure. I cut the lid to fit the back side of the socket and then mounted it with the provided machine screws. I decided to mount the socket into the box itself so that this would exisit as a standalone unit, but you could run the mains cable out of the box and attach it to a remote socket as well. If you decide to use a remote socket, make sure that it is also properly encolsed. 

Cover Cutting and Wiring

Close up the box and leave everything unplugged and we'll move onto programming the Arduino.

 

Box

 

 

Painting a Sensor

You'll need to a paint a pad of Bare Paint to work as a capacative sensor as we did in this tutorial here. The size and shape of the paint pad aren't crucially important (though they may effect the values that you receive into the serial port). We decided to paint a 'lightswitch' onto our wall as seen in the photo below.

Pad

 

Like you may have seen in our connecting tutorial, there are a lot of ways to connect to Bare Paint, here we used a magnet so that it would be easy for us to detach wires when not in use. Because the magnet is metallic, its conductive so we glued it to the wall (using our paint) and then painted a line directly onto. This way we have an electrical connection between the pad that we touch and the wire that is connected to our box.

Connection

 

 

Programming

Now that everything is in the box, we're going to program the Arduino. Make sure again that nothing is plugged into the mains, and never reprogram the Arduino while it is attached to the mains as your computer might get a nasty shock. Make sure that you have downloaded and installed the latest version of Arduino as well as the CapSense library and the Lightswitch code. Links to all three of these can be found at the bottom of the page. Install the Capsense library, plug the Arduino into the computer and upload the lightswtich code. For more information on how to do this, make sure to check out our Capacitence Sensor Tutorial.

Now that the software is uploaded, its time to test our sensor. Leaving the arduino connected to the computer, connect the wire to the pad of paint. Touching the pad of paint should trigger the relay. If so, you'll hear a "click." If you don't the first thing to to would be to check the numbers coming into the serial port through the Arduino environment.

Within the code there is a variable called " threshold." In order for your hand to trigger the relay, the number coming to the serial port needs to be higher than the threshold. I've set the threshold at 390 (but this is a somewhat arbitrary number that is specific to my pad of paint and my chosen resistor). Lets say that without touching the paint, the number to the serial port reads 500, when touching it, it reads 5000. Your threshold number should be somewhere between these two (say 1500). In general, the higher the threshold, in comparison to your two readings, the less sensitive and slower the switch will be. If manipulating the threshold doesn't work, try playing with the resistor and seeing if you get values which are more successful.

USB Power

Once you have tested your switch and the relay is tripping reliably, you can finish setting up your light. Since the Arduino requires DC power to switch the relay, we're going to use a small mains AC-DC inverter with a USB port. Plug in the USB cable between the inverter and the Ardunio. Plug the mains input into the mains, and plug your light into the output. Hopefully touching the pad of Bare Paint will trigger the light!

 

 

Arduino Code

Download the Bare Paint Lightswitch Arduino code here

Find the CapSense Library here

If you don't have the latest version of Arduino you can grab it here