Erik Moran
Published © CC BY

IoT for Coins

Need to organize your coins? Get some help with this project.

IntermediateFull instructions provided20 hours14,548
IoT for Coins

Things used in this project

Hardware components

Arduino MKR1000
Arduino MKR1000
×1
ATX Power Supply
×1
Adafruit coin acceptor
×1
Adafruit Proto Screw Shield
×1
Adafruit GRAPHIC ST7565 POSITIVE LCD (128X64) WITH RGB BACKLIGHT + EXTRAS
×1
Adafruit LOCK-STYLE SOLENOID - 12VDC
×1
Seeed Studio BADGEr_v4
×1
Resistor 330 ohm
Resistor 330 ohm
×3
Resistor 22.1 ohm
Resistor 22.1 ohm
×1
Capacitor 10 µF
Capacitor 10 µF
×1
Capacitor 100 nF
Capacitor 100 nF
×2
Rotary potentiometer (generic)
Rotary potentiometer (generic)
×1
Texas Instruments lm386
×1
Buzzer
Buzzer
×1
Jumper wires (generic)
Jumper wires (generic)
A lot of wire. and a lot of colors
×1

Software apps and online services

Arduino IDE
Arduino IDE
Visual Studio 2015
Microsoft Visual Studio 2015
Microsoft Azure
Microsoft Azure
QR generator.
Circuit Maker
CircuitMaker by Altium Circuit Maker
Fritzing
EagleCAD
Seeed Studio WyoLum for Badger
paint

Hand tools and fabrication machines

Laser cutter (generic)
Laser cutter (generic)
3D Printer (generic)
3D Printer (generic)
Soldering iron (generic)
Soldering iron (generic)
Hot glue gun (generic)
Hot glue gun (generic)
Dremel Rotary tool

Story

Read more

Custom parts and enclosures

Corner for 3D print

Print 4, made for 3mm acrylic.

Frame

I created this one for 3D printing, for both screens i use

Door lock

3D print and use for 3mm Acrylic

Coin Separator for mexican pesos

Coin sorter customized for mexican pesos.

Vynil sticker

Stickr for Schoredinger bank

Schematics

Image for the schematic

This is the wiring for this project ---> Use MKR1000 instead of YUN

IoT for Coins

Schematic for this project.

Code

IoT for Coins

Arduino
The hybrid program for Azure via POST and arduino
// Erik Moran 
// IoT for Coins
//
// PINout
// pin 3 - Coin 
//
// pin 6 - GLCD
// pin 7 - GLCD
// pin 8 - GLCD
// pin 9 - GLCD
// pin 10 - GLCD
//
// pin 2 - r
// pin 1 - g
// pin 0 - b
//
// pin 5 - Locker
//
// pin 4 - Chip slct
// pin 10 - mosi /SD
// pin 8 - miso /SD
// pin 9 -sck /SD
//
// pin A1- Random seed.
//
// pin A0 - Buzzer-Sound
//

#include <SD.h>
#include <SPI.h>
#include <AudioZero.h>
#include <WiFi101.h>
#include "ST7565.h"

// Internet password
char ssid[] = "Network Name";     //  your network SSID (name) 
char pass[] = "Password";    // your network password
int keyIndex = 0;                 // your network key Index number (needed only for WEP)

int status = WL_IDLE_STATUS;
WiFiServer server(80);
String IP;

// Coin Acceptor
const int CoinPin = 3;     // the number of the pushbutton pin
int cash = 0;
int t = 0;

//Graphic Liquid Cristal display - GLCD
ST7565 glcd(10, 9, 8, 7, 6);
char Val[5]; 

unsigned long duration;

// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status
int buttonState1 = 0;   

int vx;//variable x
int vy;//resultado
int vc;//constante
int vl;//A
int re;//respuesta del usuario
int st = 0;
//2 1 0 pines r g b
int pr = 2;
int pg = 1;
int pb = 0;

int locker = 5;

void setup() {
  Serial.begin(9600);
  
  pinMode(CoinPin, INPUT);

// GLCD background color
  pinMode(pr, OUTPUT);
  pinMode(pg, OUTPUT);
  pinMode(pb, OUTPUT);

  digitalWrite(pr, LOW);
  digitalWrite(pg, LOW);
  digitalWrite(pb, LOW);

  pinMode(locker, OUTPUT); //locker

  glcd.begin(0x18);
  //pon algo de IOT
  // delay(2000);
  glcd.clear(); 

  if (WiFi.status() == WL_NO_SHIELD) {
    Serial.println("WiFi shield not present");
    while (true);       // don't continue
  }

  // attempt to connect to Wifi network:
  while ( status != WL_CONNECTED) {
    Serial.print("Attempting to connect to Network named: ");
    Serial.println(ssid);                   // print the network name (SSID);

    // Connect to WPA/WPA2 network. Change this line if using open or WEP network:
    status = WiFi.begin(ssid, pass);
    // wait 10 seconds for connection:
    delay(10000);
  }
  server.begin();                           // start the web server on port 80
  printWifiStatus();                        // you're connected now, so print out the status

  randomSeed(analogRead(1));
  genera_ec();//inicializa pw
}

void loop() {

// Read the pulse for coin
  duration = pulseIn(CoinPin, HIGH);
  if(duration > 0){
    cash++;
    }else {
        if (t != cash) {
          Serial.println(cash);
            t = cash;
        }
    }

  sprintf(Val, "%d", cash);

  char IPc[24];
  IP.toCharArray(IPc, 24);

  glcd.drawstring(0, 0, IPc);
  glcd.drawstring(0, 1, "IOT for Coins");
  glcd.drawstring(0, 2, "You have:");
  glcd.drawstring(0, 3, Val);
  glcd.display();
  //delay(2000);
  glcd.clear();
 
 // Serial.println(duration);

  WiFiClient client = server.available();   // listen for incoming clients

  if (client) {                             // if you get a client,
    Serial.println("new client");           // print a message out the serial port
    String currentLine = "";                // make a String to hold incoming data from the client
    while (client.connected()) {            // loop while the client's connected
      if (client.available()) {             // if there's bytes to read from the client,
        char c = client.read();             // read a byte, then
        Serial.write(c);                    // print it out the serial monitor
        if (c == '\n') {                    // if the byte is a newline character

          // if the current line is blank, you got two newline characters in a row.
          // that's the end of the client HTTP request, so send a response:
          if (currentLine.length() == 0) {
            // HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK)
            // and a content-type so the client knows what's coming, then a blank line:
            client.println("HTTP/1.1 200 OK");
            client.println("Content-type:text/html");
            client.println();
            
            client.print("<link rel=\"shortcut icon\" href=\"http://www.example.com/my_empty_resource\" />");
            client.print("<script src=\"//code.jquery.com/jquery-1.12.0.min.js\"></script>");
            client.print("<style>body {text-align: center; font-size: 18px; color: #333; text-shadow: 0px 0px 3px #ccc; font-family: Verdana;}</style>");

            client.print("Current cash:<br>");
            client.print(cash);

            client.print("<br/><br/>");
            if(vx != 1) client.print(vl);
            client.print("x");//vx
            if(vc < 0) {
              client.print("");
            } else {
              client.print(" + ");
            }
            client.print(vc);
            client.print(" = ");
            client.print(vy);
            client.print("<br/>x = <input type='text' id='respuesta' value=''/>");
            client.print("<input type='button' id='enviar' value='enviar'/>");

            /*
            client.print("<script>$(\"#respuesta\").keyup(function (e) {if (e.keyCode == 13) {window.location='http://'+self.location.hostname+'/'+String.fromCharCode(parseInt($(\"#respuesta\").val())+65);}});</script>");
            client.print("<script>$(\"#enviar\").click(function (e) {window.location='http://'self.location.hostname+'/'+String.fromCharCode(parseInt($(\"#respuesta\").val())+65);});</script>");
            */
            client.print("<script>$(\"#respuesta\").keyup(function (e) {if (e.keyCode == 13) {window.location='http://'+self.location.hostname+'/'+(parseInt($(\"#respuesta\").val())+65);}});</script>");
            client.print("<script>$(\"#enviar\").click(function (e) {window.location='http://'self.location.hostname+'/'+(parseInt($(\"#respuesta\").val())+65);});</script>");
            client.print("<script>$(\"#respuesta\").focus();</script>");

            // The HTTP response ends with another blank line:
            client.println();
            digitalWrite(pg, LOW);
            digitalWrite(locker, LOW);//abre locker
            // break out of the while loop:
            break;//!!!
          }
          else {      // if you got a newline, then clear currentLine:
            currentLine = "";
          }
        }
        else if (c != '\r') {    // if you got anything else but a carriage return character,
          currentLine += c;      // add it to the end of the currentLine
        }

        // Check to see if the client request was correct or wrong.
        if (currentLine.endsWith("GET /HH")) {
          digitalWrite(locker, HIGH);            
        }
        if (currentLine.endsWith("GET /LL")) {
          digitalWrite(locker, LOW);            
        }
        if (currentLine.endsWith("GET /"+String(vx+65))) {
        //if (currentLine.endsWith("GET /"+int(vx))) {
            st = 1;
            genera_ec();
            digitalWrite(pg, HIGH);
            digitalWrite(locker, HIGH);//abre locker
          }
          if (currentLine.endsWith("GET /NN")) {
            st = 1;
            genera_ec();
          }
          if (currentLine.endsWith("GET /RR")) {
            client.print("<br/>*<br/>");
            client.print(vx);
            client.print("<br/>*<br/>");
            client.print(String(vx+65));
            client.println();
            
            //digitalWrite(pg, HIGH);
            //digitalWrite(locker, HIGH);//abre locker
          }
      }
    }
    // close the connection:
    client.stop();
    Serial.println("client disonnected");
  }
 
}


String DisplayAddress(IPAddress address)
{
 return String(address[0]) + "." + 
        String(address[1]) + "." + 
        String(address[2]) + "." + 
        String(address[3]);
}

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);
  IP = DisplayAddress(ip);

  // print the received signal strength:
  long rssi = WiFi.RSSI();
  Serial.print("signal strength (RSSI):");
  Serial.print(rssi);
  Serial.println(" dBm");
  // print where to go in a browser:
  Serial.print("To see this page in action, open a browser to http://");
  Serial.println(ip);
}



void genera_ec() {
  vx = random(0, 9);
  vc = random(-20, 20);
  vl = random(1,5);
  vy = (vl*vx)+vc;
  re = 0;
}

GLCD library

This is the library for the GLCD from Adafruit.

Credits

Erik Moran

Erik Moran

1 project • 13 followers
Maker from the big city.

Comments