Using a capacitative touch sensor with the Raspberry Pi or the Arduino

A capacitative touch sensor is simply a sensor that detects touch. Well, not actually touch. It somehow detects you and generates a response which the Pi can use anyway you want like a switch.

I’ve recently got a bunch of these.

proximity_2013_06_15_IMG_1912

 

Designed by  Adafruit.  They cost about £5 – £6.  The one used in this project is the one on the right.

Wiring

I’ve found that it’s best to connect it up and add the power supply last. It’s incredibly sensitive.

We used Conductive Paint to paint a picture.

BAR-33_1000x500-720x415

A wire was connected to the picture. You can use conductive sheet or anything that conducts – even playdough can work.

Connect the wire to the input. On the opposite side, connect a wire to one of the Pi input pins (5,7,8, 10,19 ,21,22,23
24,26,) or one of the Arduino analog inputs.

Repeat for the other inputs. Connect the ground to the GROUND and the VCC to the Power. I’ve used 3.3 V.

To test, put your hand over the conductive device. You should see an LED come on on the device. Remove your hand and it goes out.

If you read the sensor value for the Pin, the default is 1 and if contact is made, the sensor reads 0.

Use this sensor value as you want in Scratch GPIO or Scratch for Arduino

A simple switch with the Raspberry Pi and Scratch GPIO

This is a simple switch without pull up resistors as these are already enabled in the program.

You need 2 wires. Connect 1 wire to 3.3v (Pin 1) and another wire to an INPUT Pin (5,7,8, 10,19 ,21,22,23 24,26)

You need to connect a switch / button between the 2 wires.

pushuppi_bb

In this program, I have “asked” the Scratch cat to say the sensor value of Pin 7. It is normally LOW (0) but when they connect, it goes to HIGH (1).

pinlow

Connect the wires.

pinhigh

You can now use the Pin7 sensor value as a control value in the program to trigger events.

 

Using the Raspberry Pi and Scratch to make LEDs light up

Simon Walters at Cymplecy has modified Scratch so it can be used to control the GPIO pins.

In this tutorial, I will show you how to control the LEDs through Scratch and the Pi.

Install Scratch GPIO

Follow the instructions at Cymplecy to install Scratch GPIO on your computer. Once installed, start it up and you’ll see it looks similar to Scratch.

Equipment

Breadboard

Resistors (typically about 50  ohm)

LEDS

Wires – female to male

Wiring

singleLEDforworkshop_bb

Note that the long leg on the LED is positive and needs to be on the side where the wire comes from the output pins.

The Pi has a number of GPIO pins for OUTPUTS. You can use 11,12,13,15,16 or 18. The odd numbers are on the left and the evens are on the right.

The code

Scratch has a BROADCAST function. You can create a BROADCAST message for the pins.

BROADCAST PIN11HIGH

or BROADCAST PIN11ON

So when you connect a function such as

WHEN SPACE BAR PRESSED, BROADCAST PIN11HIGH

piswitch

The LED will light up. If it does not work, check your wiring. If you connect the wire from Pin11 to Pin1, this supplies 3.3V and the LED will light up.

To turn the LED off,

BROADCAST PIN11LOW

or BROADCAST PIN11OFF

You can also control Power by creating a VARIABLE

Create a VARIABLE called Power11.

You can then set the VARIABLE to a number between 0 and 100.

variablePi

You can connect multiple LEDs by using a common GROUND.

multipleLEDforworkshop_bb

Once you have control over the LEDs, you can link it to the Scratch program and make things happen.

Instead of LEDs, you can use simple buzzers as OUTPUTS. Don’t use motors as they need more power than the Pi can supply.

Video tutorial for the  Arduino

Arduino microcontroller

Using the Arduino to make an LED glow

We’ve been using both the Arduino and the Raspberry Pi to control LEDS, motors, switches and sensors. I’m going to do a series of simple tutorials explaining how both can be used as control devices and explain to teachers – especially primary teachers – how the National Curriculum for computing can be taught in the classroom in an interesting way.

The Arduino

 

Arduino microcontroller

An Arduino microcontroller. Each pin can control and input or and output.

It’s got pins which can be used for input and output. To set it up, you need the Arduino IDE which can be downloaded from the Arduino website.

Once set up, you connect it to the computer with a USB cable. You need to select the correct serial port.

Scratch for Arduino

This is a free adaptation of the popular Scratch program. It has been modified so you can turn pins on and off, give pins a variable power output, control motors and servos and also read sensors with an analogue input. This gives it a massive advantage over the Pi which can only read a digital input.

Download Scratch for Arduino here.

Once you upload the firmware in the Arduino program, you can then activate S4A. It searches for the board. Once detected, a sensor board comes up showing you 6 analogue inputs and the value of pin 2 and pin 3.

So to make an LED light up.

You need a breadboard, 2 wires, a resistor (about 400 ohm – but depends on the LED) and an LED.

Connect one wire to the 5V pin. Connect the other end to the breadboard along with the LED and resistor. The other wire connects to the GROUND  on the Arduino. Look at the diagram to see how the circuit works. If it’s correct, the LED will light up. Common mistakes include the LED being the wrong way round (long wire on the positive side) or too high an LED.

Once that works, disconnect the wire from the 5V and put it in pin 10 (or 11, 12 or 13).

singleLEDArduino

The commands are as for normal Scratch. So if you select

WHEN SPACE KEY PRESSED

DIGITAL 10 ON.

Then when you press the SPACE key, digital 10 will turn on and the LED will light up.

To turn it off, DIGITAL 10 OFF.

S4a basic LED

It’s that simple.

To make things more interesting, you can connect multiple LEDs with a common ground to pins 10, 11, 12 and 13.

If you want to alter the degree of power, use pins 5,6 and 9. In this case, you use ANALOG 5 (0 – 255) where 0 is no power and 255 is full power.