Arduino Stack Mat

by Invents_Studio in Circuits > Arduino

416 Views, 0 Favorites, 0 Comments

Arduino Stack Mat

image001.jpg

Stackmat is a tool to time your rubik’s cube solves or cup stackings. In this project, we are doing just that. Making a cheap stackmat with Arduino with some other basic materials you have lying around your house.

Supplies

2 1M Ohm resistors + 220 Ohm resistor

1 Push-button

1 Ruler (or whatever long and non-conducting)

Wires

Tin foils + tape (ideally wrapping conducting material that can be soldered)

Arduino

​Wrap Your Ruler With Tin Foils

image002.jpg

Other similar materials that can be used to wrap and conduct electricity and solderable. In the later step, if possible, solder your wires to it.

​Tape Wires on Each Side and Also Secure the Foils on the Ruler

image003.jpg

Make sure the wire is in contact with the tin foil.

​Wire Your Breadboard As Shown in the Image.

image004.gif

For your information, those pins with 1MOhm resistor attached used for connecting with the foil are called a capacitive sensor or touch sensor.

Program the Arduino

codecode.jpg

Code as below or download this file: https://drive.google.com/file/d/12SJhsdVNekENgSdL...

#include

CapacitiveSensor csLeft = CapacitiveSensor(4,3);

CapacitiveSensor csRight = CapacitiveSensor(12,13);

boolean started = false;

long startTime = 0;

long solveTime = 0;

long placeHandTime = 0;

long totalLeft, totalRight;

enum state_t {WAIT_TO_START, START, SOLVING, END};

state_t state = START;

void setup() {

// put your setup code here, to run once:

Serial.begin(9600);

pinMode(6, INPUT);

}

void loop()

{

long start = millis();

totalLeft = csLeft.capacitiveSensor(30);

totalRight = csRight.capacitiveSensor(30);

Serial.print('\t');

Serial.print(millisToTime(solveTime)); // print sensor output 3

// print sensor output 1

Serial.print('\t');

switch(state)

{

case WAIT_TO_START:

if (isTouched())

{

state = START;

placeHandTime = millis();

}

break;

case START:

if (!isTouched())

{

if(millis() - placeHandTime > 500)

{

state = SOLVING;

startTime = millis();

}

else

{

state = WAIT_TO_START;

}

}

else

{

if(millis() - placeHandTime > 500)

{

Serial.print("\tStart at anytime");

}

}

break;

case SOLVING:

if (isTouched())

{

state = END;

}

solveTime = millis()-startTime;

break;

case END:

Serial.print("Press button to reset");

break;

}

if (digitalRead(6) == HIGH)

{

state = WAIT_TO_START;

solveTime = 0;

}

Serial.print("\n");

delay(10); // arbitrary delay to limit data to serial port

}

String millisToTime(long millisec)

{

int totalSecs = millisec/1000;

int hours = totalSecs / 3600;

int minutes = (totalSecs % 3600) / 60;

int seconds = totalSecs % 60;

int mili = millisec %1000;

return String(String(hours) +":"+ String(minutes) +":"+ String(seconds)+ ":" + String(mili));

}

boolean isTouched()

{

return totalLeft > 300 && totalRight > 300;

}

Then upload to Arduino and save.

​Final Product Should Look Like This

image005.jpg

Enjoy, here is my demo of the stack mat

https://drive.google.com/file/d/1lDcPcrXZjifQzWkgSoDj4jNCBydAqcox/view?usp=sharing