Electronic Coin Bank

Overview

The coin bank mechanically sorts US currency coins and electronically keeps track of its balance. It displays the balance on an LCD, and a user set password must be entered via Bluetooth for withdrawal. Any changes in the balance will be tracked and recorded to SD card upon a detected change.

Team Members

  • Justin Cheung
  • Hayoung Jeong
  • Grayson Noah

Components

  • MBed LPC1768
  • uLCD-144-G2 128 by 128 Smart Color LCD
  • 4x Pololu Sharp GP2Y0A02YK0F Analog Distance Sensor
  • SparkFun MicroSD Transflash Breakout Board
  • Adafruit Bluefruit LE UART Friend
  • RC Servo
  • External power source (for the RC Servo), e.g. 5V DC 2A AC adapter with a barrel jack adapter
  • Breadboard and short wires (for breadboard connections)
  • Cardboard, hot glue, X-Acto knife (building materials and tools for sorter)

Building Physical Coin Sorter

Circuit Diagram

/media/uploads/hjeong64/screen_shot_2017-12-12_at_11.06.09_pm.png

mbeduLCD
gndgnd
VU(5V)5V
p11Reset
p14 (Serial RX)TX
p13 (Serial TX)RX
mbedMicroSD
p8CS
p5DI
VoutVCC
p7SCK
gndgnd
p6DO
mbedAdafruit BLE
gndgnd
VU(5V)Vin(3.3-16V)
ncRTS
gndCTS
p27 (Serial RX)TXO
p28 (Serial TX)RXI
mbedRC Servo
gndgnd(black)
p21yellow
4.8V - 6Vpower(red)
mbedIR Sensor
gndgnd(black)
p17-20yellow
4.5V - 5.5Vpower(red)

Code

Electronic Coin Bank

#include "mbed.h"
#include "SDFileSystem.h"
#include "uLCD_4DGL.h"
#include "Servo.h"
#include <Timer.h>

uLCD_4DGL LCD(p13, p14, p11);
SDFileSystem sd(p5, p6, p7, p8, "sd"); //SD card
Serial  blue(p9,p10);
Servo lock(p21);
AnalogIn IR1(p17), IR2(p18), IR3(p19), IR4(p20);
char pw[] = {'p','a','s','s','w','o','r','d'};
int mode=0; //0=not logged in, 1=logged in, 2=logged in and inputting new pw
bool locked=1;
float savings=0.0f;
FILE *sd_file;
Timer t;

void blue_recv(){
    while(blue.readable()){
        switch(mode){
            case 0: {
                int newmode=1;
                for (int i=0; i<8; i++){
                    if (blue.getc()!=pw[i])
                        newmode=0;
                }
                if(newmode==0){
                    LCD.cls();
                    LCD.printf("\n\rIncorrect password. Try again.\n\r");
                }
                mode=newmode;
                break;
            }
            case 1: {
                char select=blue.getc();
                switch(select){
                    case '1': {
                        locked=!locked;
                        break;
                    }
                    case '2': {
                        mode=2;
                        break;
                    }
                    case '3': {
                        savings=0.0;
                        break;
                    }
                    case '4': {
                        mode=0;
                        break;
                    }
                }
                break;
            }
            case 2: {
                for (int i=0; i<8; i++){
                    pw[i]=blue.getc();
                }
                LCD.cls();
                LCD.printf("\n\rNew password has been set.\n\r");
                wait(2);
                mode=1;
                break;
            }
        }
    }
}

int main(){
    t.start();
    blue.baud(9600);
    blue.attach(&blue_recv, Serial::RxIrq);
    int oldmode=-1;
    float oldsavings=-2.0f;

    while(1){
        if(locked){
            lock=1.0;
        }else{
            lock=0.0;
        }
        if(IR1<0.3){
            savings+=0.10;
        }else if(IR2<0.3){
            savings+=0.01;
        }else if(IR3<0.3){
            savings+=0.05;
        }else if(IR4<0.3){
            savings+=0.25;
        }
        if(oldmode!=mode || oldsavings!=savings){
            LCD.cls();
            switch(mode){
                case 0: {
                    LCD.printf("\n\rPlease enter password to log in.\n\r");
                    break;
                }
                case 1: {
                    LCD.printf("\n\rYou're logged in.\n1=lock/unlock\n2=reset password\n3=reset balance\n4=log out\n\r");
                    break;
                }
                case 2: {
                    LCD.printf("\n\rPlease enter your new 8-character password.\n\r");
                    break;
                }
            }
            LCD.printf("\n\rTotal savings:\n\r$%.02f\n\r", savings);
            oldmode=mode;
            if(oldsavings!=savings){
                sd_file = fopen("/sd/savings.csv","a");
                fprintf(sd_file, "$%.02f, %d\n", savings, t.read_ms());
                oldsavings = savings;
                fclose(sd_file);
            }
        }
    }
}

Testing Demo


The coin sorter saves any changes of the balance to the SD as a .csv file.

/media/uploads/hjeong64/savingslog.png


The bank door can be unlocked using Bluetooth by inserting the correct an user-set password.

Before Logging In
pic1

After Inserting Password
pic3 pic2
Error message is displayed when wrong password is inserted (left).
Setting options is shown when successfully logged in (right).

Changing Pssword
pic4


Please log in to post comments.