Introduction: Create Your Own Simon Says Game With DIY Electro Dough and Arduino!

Getting Started

The goal of this Instructable is to turn your electro dough into a touch capacitive button with Arduino using the CapSense arduino library and then using it to create a Simon Says game. We’ll be using a capacitive start button and three capacitive buttons for our game.

You will need:

Start Arduino Kit

The Start Arduino kit contains these components that you will need:

Lots of Jumper Wires

3 x LED

1 x Buzzer

4 x 1M resistor

1 x Breadboard (to house all our resistors)

Also download the CapSense Arduino Library http://playground.arduino.cc/Main/CapacitiveSenso...

Make some 'Electro Dough' - you can find the recipe on our website http://tinyurl.com/muy8uxf

Step 1: Setting Up

Setting up: Once you download the CapSense library, unzip the file and put it into the Arduino > Libraries folder. Open Arduino and you should see the library if you go to Sketch > Import Library. Click on the CapacitiveSensor library to import it into your sketch.

Step 2:

Mix up your electro dough and create your doughy scene. The electro dough recipe can be found here http://tinyurl.com/muy8uxf. The LEDs that accompany our buttons have polarity and will need separated positive and nevagtive legs so you will need both conductive and insulating dough to complete the circuit.

The electro dough works like the breadboard that came with your Arduino but the dough has some resistance in it already so you wont need any resistors with your LED.

Step 3:

Picture of

Connect your LED to arduino pins 9,10,11, and connect your buzzer to pin 12 (remember we don’t need resistors with the dough)

The capacitive touch sensing on the arduino works by detecting changes in a current flowing through our piece of dough. We will be using four separate capacitive buttons but they will all share the same input, pin 2. Run a jumper wire from pin 2 to your breadboard and run your four 1M resistors from there to new rows and connect to the dough with another jumper wire. Once you have that done, then run a jumper wire from each button back to pins 4, 5, 6 and 7.

Step 4: Start Coding!

Start coding!

Open your Arduino Software and start a new sketch. The first thing we need to include is the CapSense Library. Go to Sketch > Import Library > CapacitiveSensor, this should add a line to the top of your sketch that says #include <CapacitiveSensor.h>

Copy the following code into the sketch:

#include <Capacitive.Sensor.h>

#define CAP_THRESHOLD 20

#define NUM_OF_SAMPLES 1

const int MAX_LEVEL = 100;

int sequence[MAX_LEVEL];

int your_sequence[MAX_LEVEL];

int level=1;

int velocity = 1000;

CapacitiveSensor cs_2_4 = CapacitiveSensor(2,4);

CapacitiveSensor cs_2_5 = CapacitiveSensor(2,5);

CapacitiveSensor cs_2_6 = CapacitiveSensor(2,6);

CapacitiveSensor cs_2_7 = CapacitiveSensor(2,7);

void setup()

{

cs_2_4.set_CS_AutocaL_Millis(0xFFFFFFFF); // turn off autocalibrate on channel 1 - just as an example

pinMode(9, OUTPUT);

pinMode(10, OUTPUT);

pinMode(11, OUTPUT);

pinMode(12, OUTPUT); //Buzzer

digitalWrite(9, LOW);

digitalWrite(10, LOW);

digitalWrite(11, LOW);

digitalWrite(12, LOW);

}

void loop()

{

if (level == 1)

generate_sequence();

if (cs_2_7.capacitiveSensor(NUM_OF_SAMPLES) > CAP_THRESHOLD || level != 1)

{

show_sequence();

get_sequence();

}

}

void show_sequence()

{

digitalWrite(9, LOW);

digitalWrite(10, LOW);

digitalWrite(11, LOW);

for (int i=0; i< level; i++)

{

digitalWrite(sequence[i], HIGH);

delay(velocity);

digitalWrite(sequence[i], LOW);

delay(200);

}

}

void get_sequence()

{

int flag = 0;

for (int i = 0; i < level; i++)

{

flag = 0;

while(flag == 0)

{

if (cs_2_4.capacitiveSensor(NUM_OF_SAMPLES) > CAP_THRESHOLD)

{

digitalWrite(9, HIGH);

your_sequence[i] = 9;

flag = 1;

delay(200);

if (your_sequence[i] != sequence[i])

{

wrong_sequence();

return;

}

digitalWrite(9, LOW);

}

if (cs_2_5.capacitiveSensor(NUM_OF_SAMPLES) > CAP_THRESHOLD)

{

digitalWrite(10, HIGH);

your_sequence[i] = 10;

flag = 1;

delay(200);

if (your_sequence[i] != sequence[i])

{

wrong_sequence();

return;

}

digitalWrite(10, LOW);

}

if (cs_2_6.capacitiveSensor(NUM_OF_SAMPLES) > CAP_THRESHOLD)

{

digitalWrite(11, HIGH);

your_sequence[i] = 11;

flag = 1;

delay(200);

if (your_sequence[i] != sequence[i])

{

wrong_sequence();

return;

}

digitalWrite(11, LOW);

}

}

}

right_sequence();

}

void generate_sequence()

{

randomSeed(millis());

for (int i = 0; i < MAX_LEVEL; i++)

{

sequence[i] = random(9,12);

}

}

void wrong_sequence() //Beep Three Times

{

for (int i = 0; i < 3; i++)

{

digitalWrite(12, HIGH);

delay(250);

digitalWrite(12, LOW);

delay(250);

digitalWrite(12, HIGH);

delay(250);

digitalWrite(12, LOW);

delay(250);

digitalWrite(12, HIGH);

delay(250);

digitalWrite(12, LOW);

delay(250);

}

level = 1;

velocity = 1000;

}

void right_sequence() //One short beep

{

digitalWrite(12, LOW);

delay(250);

digitalWrite(12, HIGH);

delay(250);

digitalWrite(12, LOW);

delay(500);

if (level < MAX_LEVEL);

level++;

velocity -= 50;

}

Upload your sketch and get playing! To begin press your start button. Your lights will then begin to flash, copy them and each time you get one right another light will be added to the sequence.
Once you’ve become a Simon Says expert try adding more buttons to your game or maybe some sound to accompany each LED, then start thinking up your own games with capacitive touch buttons!

Comments

SofiaR (author)2015-09-27

I got this error :(

___________

simon.ino:1:31: fatal error: Capacitive.Sensor.h: No such file or directory

compilation terminated.

Compilation error

_____

what can I do?

laurski11 (author)2014-12-10

I got a huge error code and followed all the steps

Sasando_Rote (author)2014-11-22

nice project

techwillsaveus (author)2014-11-18

you are right! for some reason this part of the sketch did not copy over, its been fixed now - thank you for letting us know!

No prob :) I am happy to help

valentina.chinnici (author)2014-11-09

I just tried it and I realised there is a mistake in the sketch... You have to declare which library you have to include. So the sketch actually begins with:

#include <CapacitiveSensor.h>

zhangweilong (author)2014-10-21

beautiful colors with LED.

MsSweetSatisfaction (author)2014-10-21

That's so cool, I love all the colors. I wonder if you put the opposite color dough with the LED's if that would make it significantly harder. Thanks for sharing!

Great Idea! Never thought about that

About This Instructable

4,381views

56favorites

License:

Bio: Technology Will Save Us is a haberdashery for making technology in everyday life. We design, manufacture and sell DIY technology Kits and run workshops to ... More »
More by techwillsaveus:DIY Speaker Pieizo Plate ReverbDIY Speaker Talk BoxDIY Speaker Kit Spring Reverb
Add instructable to: