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

by techwillsaveus in Circuits > Electronics

5734 Views, 59 Favorites, 0 Comments

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

Simon Says! DIY Electro Dough

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

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.

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.

Screen Shot 2014-10-01 at 10.24.08.png

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.

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!