Watch the demonstration here!
My brother is a passionate gamer. Sometimes, things get a little heated. In a (not serious at all) attempt to get my brother to be more calm when he games, I thought it might be useful to detect when he rages. Introducing the Rage Gauntlet.
The ElectronicsThe circuit for this project is simple. I added an LED and resistor as a visual indicator of sensor activation (and because it's fun) but you can skip this and opt exclusively for your serial monitor.
Here's what the electronics look like in person...
...and here's your schematic.
Next, let's put the sensor on a glove. I accomplished this with needle and thread.
I stitched it in one corner just so it wouldn't be impossible to get off later.
The CodeFirst, let's set up our project. We'll open the serial port at 9600 bps so we can check to see if our electronics are in order.
void setup()
{
Serial.begin(9600);
}
I've created the necessary variables for the project. myLED is an output, and knock is an input.
const int myLED = 1; // defines the digital pin for the LED
const int knock = 2; // defines the digital pin for the knock sensor
int state; // defines the state of the knock sensor
int flag = 0; // we'll change this when we detect a knock, that way we won't send multiple requests to IFTTT.
void setup()
{
pinMode(myLED, OUTPUT);
pinMode(knock, INPUT);
Serial.begin(9600);
}
Next, let's work on the logic. When the state of knock is detected as HIGH, a conditional statement will print 'DETECT' to the serial monitor and publish the request 'ragedetected'.
const int myLED = 1;
const int knock = 2;
int state;
int flag = 0;
void setup()
{
pinMode(myLED, OUTPUT);
pinMode(knock, INPUT);
Serial.begin(9600);
}
void loop()
{
state = digitalRead(knock);
if (state == HIGH) {
digitalWrite(myLED, LOW);
}
else {
digitalWrite(myLED, HIGH);
Serial.printlnf("DETECT");
Particle.publish("ragedetected", "now");
}
}
But wait! With this setup, the knock sensor will vibrate around and we'll see it activate multiple times. To combat this, we'll create a flag to prevent ragedetected from being published after one instance of a knock is detected. IFTTT won't send multiple emails within a fairly long timespan -- for one gaming session, a single email is more than sufficient.
const int myLED = 1;
const int knock = 2;
int state;
int flag = 0;
void setup()
{
pinMode(myLED, OUTPUT);
pinMode(knock, INPUT);
Serial.begin(9600);
}
void loop()
{
state = digitalRead(knock);
if (state == HIGH) {
digitalWrite(myLED, LOW);
}
else {
digitalWrite(myLED, HIGH);
if (flag == 0){
Serial.printlnf("DETECT");
Particle.publish("ragedetected", "now");
flag = 1;
}
}
}
Finished!
IFTTT IntegrationNext, we'll create an IFTTT applet. IFTTT's a simple way to connect APIs to do interesting things. In this case, we'll connect the ragedetected publish to an email.
If all goes well, after slamming your fist into the table, you should receive this email.
Comments
Please log in or sign up to comment.