Tomasz HulkaAri Greenberg
Published © GPL3+

LofT Group 810 Particle Photon Sensor

Using a Photon in a custom enclosure, we are testing the frustration levels of peoples paying money to play a game that has a delayed start.

IntermediateFull instructions provided18 hours222
LofT Group 810 Particle Photon Sensor

Things used in this project

Hardware components

Photon
Particle Photon
×1
SparkFun Coin Acceptor - Programmable (3 coin types)
×1
SparkFun Flex Sensor 2.2"
×1
Pushbutton switch 12mm
SparkFun Pushbutton switch 12mm
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Resistor 10k ohm
Resistor 10k ohm
×1
Breadboard (generic)
Breadboard (generic)
×1
LED (generic)
LED (generic)
×1
SparkFun Servo
×1
SparkFun 5V Wall Adapter
×1
12V Battery
×1
12"x12" Acrylic Sheet (preferably clear)
×2

Software apps and online services

Particle Pi
Particle Pi

Hand tools and fabrication machines

Laser cutter (generic)
Laser cutter (generic)
Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Custom parts and enclosures

Case Files

acryllic810finalfix_WTtBedx5NE.ai

wood810_2_6DYeB169M0.ai

Schematics

Fritzing Diagram

This diagram shows the hookup instructions for all parts except the coin acceptor, which is powered separately using a 12V adapter, and whose data cable connects to D7

Code

Code for Coin Acceptor Game

Arduino
Comments are provided with the code to help understand it
// This #include statement was automatically added by the Particle IDE.
#include <SparkFunPhant.h>

const int coinpin = D7;
const int targetcents = 600;
volatile int cents = 0;
/*  Flex Init */

const int flexPin = A0; 
int tempFlexValue;

/* Servo Init */

Servo ourServo;
int servoPin = D0; 
int servoPos = 180; 

/* Leds Init */

int yellowLeds = D2;
int greenLed1 = D5;
int greenLed2 = A4;
int greenLed3 = A5;
int greenLed4 = A3;
int greenLed5 = A2;

/* Button Init */

int dudButton = D1;
int buttonPress = 0;
int buttonPressed = 0;

int win = 0; // value will change to one to signal a player has won
int gameStart = 0; // value will change to one to signal a game is in progress

const char server[] = "data.sparkfun.com"; // Phant destination server
const char publicKey[] = "OGMRNXK6MncMlVwD2yW1"; // Phant public key - HAS TO BE CHANGED
const char privateKey[] = "8bKBDomzK7udEBmpnkoR"; // Phant private key  - HAS TO BE CHANGED
Phant phant(server, publicKey, privateKey); // Create a Phant object

const int POST_RATE = 3000; // Time between posts, in ms.
unsigned long lastPost = 0;




void setup() {
    
     Serial.begin(9600);
    pinMode(D7, INPUT_PULLUP);
    attachInterrupt(digitalPinToInterrupt(coinpin), coinInterrupt, FALLING);
    delay(100);
    
    /* Flex Setup */
    tempFlexValue = analogRead(flexPin);
     pinMode(D1, INPUT_PULLUP);
    attachInterrupt(digitalPinToInterrupt(dudButton), buttonCode, CHANGE);
    delay(100);
    
    /* Servo Setup */
    ourServo.attach(servoPin); 
    ourServo.write(servoPos);  
    delay(500);
    // Detaching our servo to avoid jittering, will be reattached when needed
    ourServo.detach();
    
    /* Leds Setup) */
    pinMode(yellowLeds, OUTPUT);
    pinMode(greenLed1, OUTPUT);
    pinMode(greenLed2, OUTPUT);
    pinMode(greenLed3, OUTPUT);
    pinMode(greenLed4, OUTPUT);
    pinMode(greenLed5, OUTPUT);

    
    

}

void loop() {
        Serial.println(cents);
    if (cents >= 10) {
    
    Serial.print(cents);
    Serial.print(" cents entered");
    gameStart = 1;
    delay(200);
    countDown();
    servo();
        int flexPosition;    // Input value from the analog pin.
        flexPosition = analogRead(flexPin);
        if ((flexPosition - tempFlexValue > 200) || (tempFlexValue - flexPosition > 200)) {
            Serial.println("A ball has passed");
             win = 1;
             postToPhant();
             victoryLights();
             }
        Serial.println("Flex sensor reading: ");
        Serial.println(flexPosition);
        delay(100);
        gameStart = 0;
        cents= 0;
        buttonPressed = 0;
    }
}
        int postToPhant() {
        phant.add("button", buttonPressed);
        phant.add("insert", cents);
        phant.add("win", win);
        TCPClient client;
        char response[512];
        int i = 0;
        int retVal = 0;
        if (client.connect(server, 80)) { 
            Serial.println("Posting!"); 
		    // phant.post() will return a string formatted as an HTTP POST.
	    	// It'll include all of the field/data values we added before.
		    // Use client.print() to send that string to the server.
            client.print(phant.post());
         } 
}
/* User defined functions */
 void coinInterrupt(){
  
    if (gameStart == 0) {// Each time a pulse is sent from the coin acceptor, interrupt main loop to add 1 cent and flip on the LED if a game has not been previously started
        cents = cents + 1; }
  
} 
// triggered when a ball enters the victory area, yellow leds go on to indicate you won
int victoryLights() {
    
    digitalWrite(yellowLeds, HIGH);
    delay(500);
    digitalWrite(yellowLeds, LOW);
    delay(500);
    digitalWrite(yellowLeds, HIGH);
    delay(500);
    digitalWrite(yellowLeds, LOW);
    delay(500);
    digitalWrite(yellowLeds, HIGH);
    delay(500);
    digitalWrite(yellowLeds, LOW);
    delay(500);
    digitalWrite(yellowLeds, HIGH);
    delay(3000);
    digitalWrite(yellowLeds, LOW);
    delay(500); 
}

// triggered after a coin is entered, the green leds proceed with a countdown that stalls halfway through


int countDown() {
    delay(1000);
    digitalWrite(greenLed1, HIGH);
    delay(1000);
    digitalWrite(greenLed1, LOW);
    digitalWrite(greenLed2, HIGH);
    delay(1000);
    digitalWrite(greenLed2, LOW);
    digitalWrite(greenLed3, HIGH);
    buttonPress = 1;
    delay(10000);
    digitalWrite(greenLed3, LOW);
    buttonPress = 0;
    postToPhant();
    digitalWrite(greenLed4, HIGH);
    delay(1000);
    digitalWrite(greenLed4, LOW);
    digitalWrite(greenLed5, HIGH);
    delay(1000);
    digitalWrite(greenLed5, LOW);
    delay(500);
    // green led 1 go, delay .5s, green led 1 off and  green led 2 go, delay .5s, green led2 off and green led3 go, delay 15s, green led 3 off and green led 4 go, delay .5s, green led 4 off and green led 5 go, delay .5s, green led 5 off, delay .5s
    // all leds go, delay 1s, all leds go, delay .5s, repeat 2 more times
    // during long delay, button checks inputs to monitor possible pushing
    // servo go as line above executes
    // servo close after 5 seconds
    
}
int servo() {
    ourServo.attach(servoPin);
    int servoPos = 180;
    ourServo.write(servoPos);
    delay(1500);
    servoPos = 80;
    ourServo.write(servoPos);
    delay(10000);
    servoPos = 180;
    ourServo.write(servoPos);

}
void buttonCode() {
        if (buttonPress == 1){
        buttonPressed = buttonPressed + 1;
        Serial.println("button press:");
        Serial.println(buttonPressed); }
}
// triggered when the countdown is stalled, the reset button is 'unlocked' and pushes data to the database when pressed

Credits

Tomasz Hulka

Tomasz Hulka

1 project • 1 follower
High school senior at Lane Tech
Ari Greenberg

Ari Greenberg

3 projects • 2 followers
Lane Tech Senior '18

Comments