Bring Touch Control to the Arduino. Use interesting touch sensors like Carrots or Beets to make a "Beetbox". In this project you will learn: * How to use the Cap Sense library to make Arduino responsive to touch * How adding a Wave Shield (and some root vegetables), you can make a "Beetbox"
For the Beetbox we use three sense channels. To start we'll implement one touch sense channel and activate an LED when Arduino senses touch. Wire up the circuit as shown in the Fritzing diagrams and photo's. Get and Install the Capacitive Sense library for Arduino from here: http://goo.gl/EpSX0
The Cap Sense circuit is made by the resistor between Arduino pins 6 and 9, and also the capacitance to ground on the Touch Sensor. When the CapacitiveSensor arduino library is asked to read the sensor value, pulses are Output on Pin 9 and Input into pin 6. The library routine measures the delay between when the pulses are transmitted and when they are received. The measured delay is proportional to the Resistor value R and the Capacitance C. i.e. Delay = R*C (strictly speaking there's a scaling factor too depending on the voltage level you're measuring from, but that's just a detail for us). The Capacitance on the sensor varies as you bring your finger close to the sensor and as you touch it. Touching the sensor gives you the largest capacitance and the longest delay. In order to make the delay large enough to be detected by Arduino you need a large resistor e.g. 4.7Meg Ohms.
There are a couple of Key Concepts in the Arduino code.
Activate an LED when the sensor is touched.
To do that we need to measure the delay (total1) and compare it to a Threshold value e.g.
That's pretty straightforward. But what should the THRESHOLD value be?
The total1 value of delay we read back varies from day to day because it's very sensitive to capacitance (which is the whole idea), but it means we can't just put in any fixed THRESHOLD value because it will be different under different conditions.
To make sure we have an appropriate THRESHOLD value, we need to measure the THRESHOLD value during a calibration sequence at the start of the code.
We do this as follows. We initialise i=0 during setup() and calibrate for the first 50 iterations of loop(). The LED flashes during calibration and we need to touch the sensor to determine the appropriate THRESHOLD value.
calVal1= 0.1*float(total1) + 0.9*calVal1;implements a digital filter. It works by weighting it's output 90% in
favour of old outputs; new data only accounts for a 10% weighting .
This gives us a reliable calibration value, calVal1 by filtering out any noise on the readings.
In the code we print the calVal1 to the Serial Monitor. Take a look at it to see how it increases smoothly towards the total1 value.
The Next Step shows the Full Arduino Code for this Experiment
If we want to go further and add sound, attach the Wave Shield to the Arduino.
I've used three Cap Sense Channels on pins 6,7 and 8.
Put some .wav files on the sound card. I used "BUFF1.WAV" etc.. as shown in the code.
Add some vegetables of choice and off you go.....
Full Arduino Code in the Next Step.
It's very similar to the one channel example with some routines added for SD card file reading and playback.
The code uses the
#define DEBUG construct to add in some Serial Monitor output for debug. Uncomment that line for debug.
The calibration cycle in this version is as follows:
LED ON : Touch channel 1 sensor
LED OFF : Touch Channel 2 sensor
LED ON : Touch channel 3 sensor
Enjoy playing your beetbox
Why not expand on capacitive touch sensing?
- Use a higher resistor value to sense when you are close to the sensor, not just touching it.
- Make a sound that varies in pitch as you got closer to the sensor.
- Use a Matrix of sensors arranged to sense the postion of your finger on a surface (a smart phone touch screen works like this)