Things used in this project

Schematics

Block Diagram
Screen%20shot%202016 05 25%20at%2010.13.10%20pm

Code

IoT Coin Counter CodeC/C++
#include <WiFi.h>
#include <PubSubClient.h>
#include <SPI.h> //only required if using an MCU LaunchPad + CC3100 BoosterPack. Not needed for CC3200 LaunchPad
WiFiClient wclient;

byte server[] = { 198, 41, 30, 241 }; //  Public MQTT Brokers: http://mqtt.org/wiki/doku.php/public_brokers
byte ip[]     = { 172, 16, 0, 100 };

char sensorRead[4];

#define       WIFI_SSID         "WiFi Name"//input wifi name in quotes
#define       WIFI_PWD          "WiFi Password"//input password in quotes

PubSubClient client(server, 1883, callback, wclient);

void callback(char* inTopic, byte* payload, unsigned int length){
// Handle callback here
}

#include <LiquidCrystal.h>


LiquidCrystal lcd(23, 24, 25, 26, 27, 28, 31, 32, 11, 12);

const short buttonPenny= 9;
const short buttonNickel= 10;
const short buttonDime= 29;
const short buttonQuarter= 30;

short pennyButtonState = 0; 
short nickelButtonState = 0; 
short dimeButtonState = 0; 
short quarterButtonState = 0; 

unsigned  int numPennies = 0;
unsigned  int numNickels= 0;
unsigned  int numDimes= 0;
unsigned  int numQuarters = 0;
double totalValue=0;
int points= 0;

const int coinInt = 39; 


int pulseCount = 0;
unsigned long time;
unsigned long current = 0;


void setup()
{
   lcd.begin (16, 2);
  Serial.begin(9600);
  
  pinMode (buttonPenny, INPUT_PULLUP );
  pinMode (buttonNickel, INPUT_PULLUP );
  pinMode (buttonDime, INPUT_PULLUP );
  pinMode (buttonQuarter, INPUT_PULLUP );
  
 Serial.println("Start WiFi");
  WiFi.begin(WIFI_SSID, WIFI_PWD);
  while(WiFi.localIP() == INADDR_NONE) {
    Serial.print(".");
    delay(300);
  }
  Serial.println("");
  
     printWifiStatus();
  
  attachInterrupt(coinInt, coinInserted, RISING);   

}

void coinInserted()    
{
    current = millis();
     pulseCount++;
}

void loop()
{
     
       time = millis();
  lcd.setCursor  (0, 0);
  
   pennyButtonState =   digitalRead  (buttonPenny);
   nickelButtonState =   digitalRead  (buttonNickel);
   dimeButtonState =   digitalRead  (buttonDime);
   quarterButtonState =   digitalRead  (buttonQuarter);
    
     //time = millis();
     if (current != 0)
   {
        if (time - current > 130) {
          
   if (pulseCount == 1 ){  
     lcd.clear();
     numPennies++;
     lcd.print("Penny");
     //delay (200);
   }
   
     else if (pulseCount == 2){  
     lcd.clear();
     numNickels++;
     lcd.print("Nickel"); 
     //delay (200);
   }
   
     else if (pulseCount == 3){ 
     lcd.clear(); 
     numDimes++;
     lcd.print("Dime"); 
     //delay (200);
   }
   
     else if (pulseCount == 4){  
     lcd.clear(); 
     numQuarters++;
     lcd.print("Quarter"); 
     //delay (200);
   }
   
 current = 0;
 pulseCount = 0;
   
        }
   }
   
    totalValue =  numPennies*0.01 + numNickels*0.05 +
                         numDimes*0.1 + numQuarters*0.25;
    
    points=numPennies - (numNickels*5) - (numDimes*10) - (numQuarters*25);
    
    lcd.setCursor  (0,1);
    lcd.print ("$");
    lcd.print (totalValue);
    lcd.setCursor  (8,0);
    lcd.print(points);
    lcd.print("pts");
    
  String total = (String) totalValue;
        int pos = 0;
        int len = total.length();
        while ((pos < len-1) && (total.charAt(pos) == '0'))
            pos++;
        total = total.substring(pos);
   
   String str = (String) total;
   
   if(totalValue< 1){
   str = (String)"0" + total; 
 }

  int str_len = str.length() +1;  // Length (with one extra character for the null terminator)
  char char_array[str_len];  // Prepare the character array (the buffer) 
  str.toCharArray(char_array, str_len);  // Copy it over 
  
  String str1 = (String) points + " pts"; 
  int str1_len = str1.length() +1;  // Length (with one extra character for the null terminator)
  char char_array1[str1_len];  // Prepare the character array (the buffer) 
  str1.toCharArray(char_array1, str1_len);  // Copy it over 
  
     if (current != 0)
   {
        if (time - current > 130) {
          
   if (pulseCount == 1 ||  pulseCount == 2|| 
   pulseCount == 3 || pulseCount == 4)  
    {
    Serial.print("$");
    Serial.println (totalValue);
    Serial.print(points );
    
    if(points ==1)
    {
      Serial.println(" Point");
    }
    
    else
    {
    Serial.println(" Points");
    }
    
            if (client.connect ("LaunchPadClient")) {
    client.publish ("topicOne", char_array);//input topic desired
    client.publish ("topicTwo", char_array1);//input second topic desired
    Serial.println("Publishing successful!\n"  );
    client.disconnect ();
    }

  }
        }
   }

    
    
}
    
    void printWifiStatus() {
  // print the SSID of the network you're attached to:
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());

  // print your WiFi shield's IP address:
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);

    
}

Credits

Mjoyqfasn0zslpeg4vrc
Ali Soomar

Student at the University of Texas at Austin

Contact

Replications

Did you replicate this project? Share it!

I made one

Love this project? Think it could be improved? Tell us what you think!

Give feedback

Comments

Similar projects you might like

ArduRadio AlarmClock
Intermediate
  • 1,708
  • 2

Full instructions

Build an FM radio with alarm clock.

Arduino: Switching ON/OFF Appliances Using IR Remote
Intermediate
  • 94
  • 2

Press 'Power' to switch everything ON/OFF. Press '1' for the fan and '2' for the lights.

Cat Door with Pet Recognition
Intermediate
  • 4,437
  • 21

Full instructions

Use object detection to let your cat in and out of the house with a motion-activated pet door.

Simple Digital Voltmeter Circuit with PCB using ICL7107
Intermediate
  • 38
  • 1

Here I built a simple digital voltmeter circuit with a PCB using ICL7107.

Web-Based Voice-Controlled Robot!
Intermediate
  • 53
  • 1

Full instructions

Add voice control to your Arduino robot!

UTC IoT Clock
Intermediate
  • 725
  • 10

Full instructions

This is a UTC Clock that displays UTC and PST time, syncs to the internet and has APIs for displaying messages or setting brightness.

UTC IoT Clock

Team Ayzenberg

ProjectsCommunitiesTopicsContestsLiveAppsBetaFree StoreBlogAdd projectSign up / Login