element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Project Videos
  • Challenges & Projects
  • element14 presents
  • Project Videos
  • More
  • Cancel
Project Videos
Documents Bank to the Future with Arduino & TI -- Episode 356
  • Documents
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Project Videos to participate - click to join for free!
Related
Recommended
Engagement
  • Author Author: tariq.ahmad
  • Date Created: 23 Aug 2018 9:38 PM Date Created
  • Last Updated Last Updated: 24 Aug 2018 7:24 AM
  • Views 3638 views
  • Likes 14 likes
  • Comments 9 comments

Bank to the Future with Arduino & TI -- Episode 356

image
Bank to the Future with Arduino & TI

element14 Presents  |  Bald Engineer: James Lewis' VCP Profile |  Project Videos

 

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

Until cryptocurrency replaces money, we have to deal with coins. Instead of just collecting them in a jar, this electronic coin bank lets you know how much you have. The simple part is the count counter module which detects up to 4 coin types. The tricky part is making it battery powered. Thanks to capacitive sensing technology, this coin bank can run off a single charge for months.

 

Buy Kit

 

Capacitive Coin Bank

 

Product NameManufacturerQuantity
Product Link
MSP-CAPT-FR2633 Evaluation Board CAPTIVATE Capacitive Touch Technology MCU Texas Instruments1Buy Now
Perma-Proto Breadboard Half SizeAdafruit1NA
Coin AcceptorAdafruit1NA
2465 -  Development Board, PowerBoost 1000. LiPo Battery Charger, 5V, 1A, USB BoostAdafruit1Buy Now
1578 -  Rechargeable Battery, 3.7 V, Lithium Polymer, 500 mAh Adafruit1Buy Now
6mm Copper Foil Tape3M1Buy Now

 

5v to 12v Boost

 

Product NameManufacturerQuantity
Product Link
C0805C106K4PACTU -  Multilayer Ceramic Capacitor, C Series, 10 - F, - 10%, X5R, 16 V, 0805 [2012 Metric]KEMET1Buy Now
MBR0540 -  Schottky Rectifier, 40 V, 500 mA, Single, SOD-123, 2 Pins, 620 mVON1Buy Now
4.7uH 0805 Inductor 600mATaiyo-Yuden1Buy Now
DC-DC Boost, SOT-23-5, 200mA outMicrochip1Buy Now

 

Pyramiduino

 

Product NameManufacturerQuantity
Product Link
100nF 0805 Ceramic 16V X7RKEMET1Buy Now
10nF 0805 Ceramic 16V X7RKEMET1Buy Now
22pF 0805 Ceramic 50V C0GKEMET2Buy Now
1uF 0805 Ceramic 16V X7RKEMET1Buy Now
ATmega328 QFN (Or MLF) PackageMicrochip1Buy Now
LDO 3v3 Regulator, SOT-23-5Microchip1Buy Now
Crystal 16M FA-238EPSON1Buy Now

 

Also Featured:

 

Product NameManufacturerQuantity
Product Link
RTM3K-104 -  Oscilloscope, RTM3000 Series, 4 Channel, 1 GHz, 2.5 GSPS, 40 Mpts, 350 psRohde & Schwartz1Buy Now

 

 

Touch Tutorial: Capacitive Touch Tutorial from James Lewis - Bald Engineer

 

MSP430FR2633 MCU Development Kit: Capacitive touch evaluation and rapid prototyping for MSP430FR2633 microcontroller MCU Development Kit

 

Autodesk Fusion 360: Autodesk Fusion 360

 

12 V BoostBreadboard Circuits
imageimage

 

Arduino Code:

 

// Pins
#include <Arduino.h>


const byte coinSig = A0;
const byte hvSolenoid = A1; // for turning on solenoid/coin counter
const byte battControl = 4;
const byte battRead = A3;
const byte resetButton = 3;


bool previousCoinSignal = false;
const float coinValue = 0.05;
float bankValue = 0.00;
unsigned long bankCount = 0;
const unsigned long pulseTimeOut = 75;


unsigned long armedForCount = 0;
unsigned long previousUpdateMillis = 0;
unsigned long updateInterval = 110;
bool printOnceFlag = false;


unsigned long previousEEPROMwrite = 0;  // delays writing to EEPROM
unsigned long updateEEPROMinterval = 1000;
//float EEPROMbankValue = 0.00;
unsigned long EEPROMbankCount;


unsigned long previousBatteryMillis = 0;
const unsigned long batteryInterval = 1000;
const float adcResolution = 5.00/1023.0;
bool enableCounter = true;

 

#include <Arduino.h>
#include <EEPROM.h>
#include <Wire.h>
#include <U8g2lib.h>
#include "coin-slot-arduino.h"




// u8g2 constructor
U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R2, /* reset=*/ U8X8_PIN_NONE);


void loadEEPROM() {
EEPROM.get(0, bankCount);
EEPROMbankCount = bankCount;
}


byte getValueWidth(float displayValue) {
  // average character width for u8g2_font_logisoso24_tn is 14
  const byte charWidth = u8g2.getMaxCharWidth();
  byte theWidth = 4 * charWidth; //1.00
  if (displayValue >= 10.00)
    theWidth = 5 * charWidth;
  if (displayValue >= 100.00)
    theWidth = 6 * charWidth; //1.00
  if (displayValue >= 1000.00)
    theWidth = 7 * charWidth; //1.00
return ((u8g2.getDisplayWidth()-theWidth)/2);
}




void printOLED() {
u8g2.clearBuffer();     // clear the internal memory
u8g2.setFont(u8g2_font_logisoso34_tn); // choose a suitable font
byte centerHeight = (u8g2.getDisplayHeight()/2) + (u8g2.getMaxCharHeight()/2);
u8g2.setCursor(getValueWidth(bankValue),centerHeight);
u8g2.print(bankValue);
u8g2.sendBuffer();     // transfer internal memory to the display
}


void printBank() {
bankValue = bankCount * coinValue;
printOLED();
Serial.print(F("Bank Value: "));
Serial.println(bankValue);
}


void printPulses() {
Serial.print(F("Pulse coutn: "));
Serial.println(bankCount);
}




void handleSerial() {
char incomingChar = Serial.read();


switch(incomingChar) {
case '!':
Serial.println(F("Clearing..."));
bankCount = 0;
      bankValue = bankCount * coinValue;
      printBank();
      break;
    case '.':
      printPulses();
      printBank();
      break;
}
}


void checkBattery() {


// hceck battery voltage
digitalWrite(battControl, HIGH);
delay(10);
int battReading = analogRead(battRead);
digitalWrite(battControl, LOW);
// Serial.print(F("Battery: "));
// Serial.println(battReading);
if (battReading < 700) {
// battery is too low, turn off solenoid
enableCounter = false;
// turn off enableCounter
digitalWrite(hvSolenoid, LOW);
//print message
// Serial.println(F("Low Battery Disable"));
u8g2.clearBuffer(); // clear the internal memory
u8g2.setFont(u8g2_font_logisoso34_tr); // choose a suitable font
u8g2.drawStr(0, 50, "lo batt");
u8g2.sendBuffer(); // transfer internal memory to the display
while(1);
}


return;
}


void handleBankReset() {
unsigned long resetCounter = millis();
bool waiting = true;
while((digitalRead(resetButton) == HIGH) && waiting) {
if (millis() - resetCounter < 1000) {
u8g2.clearBuffer(); // clear the internal memory
u8g2.setFont(u8g2_font_logisoso34_tr); // choose a suitable font
u8g2.drawStr(0, 50, "3");
u8g2.sendBuffer(); // transfer internal memory to the display
}


if ((millis() - resetCounter > 1000) && (millis() - resetCounter <= 2000)) {
u8g2.clearBuffer(); // clear the internal memory
u8g2.setFont(u8g2_font_logisoso34_tr); // choose a suitable font
u8g2.drawStr(0, 50, "2");
u8g2.sendBuffer(); // transfer internal memory to the display
}


if ((millis() - resetCounter > 2000) && (millis() - resetCounter <= 3000)) {
u8g2.clearBuffer(); // clear the internal memory
u8g2.setFont(u8g2_font_logisoso34_tr); // choose a suitable font
u8g2.drawStr(0, 50, "1");
u8g2.sendBuffer(); // transfer internal memory to the display
}


if ((millis() - resetCounter > 3000) && (millis() - resetCounter <= 3500)) {
u8g2.clearBuffer(); // clear the internal memory
u8g2.setFont(u8g2_font_logisoso34_tr); // choose a suitable font
u8g2.drawStr(0, 50, "0");
u8g2.sendBuffer(); // transfer internal memory to the display
}


if ((millis() - resetCounter > 3500) && (millis() - resetCounter <= 4000)) {
bankCount = 0;
}


if ((millis() - resetCounter > 4000)) {
waiting = false;
}


}
printBank();
}


void setup() {
pinMode(battControl, OUTPUT);   // battery transistor
digitalWrite(battControl, LOW);
u8g2.begin();
checkBattery();
// init coin counter
pinMode(hvSolenoid, OUTPUT);
//Serial.print(F("Turning on counter..."));
  digitalWrite(hvSolenoid, HIGH);
pinMode(coinSig, INPUT_PULLUP);
u8g2.clearBuffer(); // clear the internal memory
u8g2.setFont(u8g2_font_logisoso34_tr); // choose a suitable font
u8g2.drawStr(0, 50, "Wait");
u8g2.sendBuffer(); // transfer internal memory to the display
Serial.begin(115200);
  //delay(100); // TODO is there a way to tell when coin acceptor is ready
  while(digitalRead(coinSig));  // add timeout and error.
previousCoinSignal = digitalRead(coinSig);
  //Serial.println(F("done!"));


pinMode(resetButton, INPUT);


  // init screen
  //pinMode(hvOLED, OUTPUT);
loadEEPROM();
//Serial.print(F("After Setup: "));
//Serial.println(freeMemory());
printBank();
}


void loop() {
handleSerial();


if (digitalRead(resetButton) == HIGH)
handleBankReset();


if (millis() - previousBatteryMillis >= batteryInterval) {
previousBatteryMillis = millis();
checkBattery();
}




byte currentCoinSignal = digitalRead(coinSig);


if (currentCoinSignal == HIGH) {
previousUpdateMillis = millis(); // print after pulse train is done
    previousEEPROMwrite = millis(); // don't write until pulse train is over
printOnceFlag = true;
}


  // only print after pulses stop
if (printOnceFlag && (millis() - previousUpdateMillis >= updateInterval)) {
printBank();
printOnceFlag = false;
}


// is time to update the EEPROM?


if (millis() - previousEEPROMwrite >= updateEEPROMinterval) {
// reset the clock
previousEEPROMwrite = millis();


// only write to EEPROM when a new value
if (bankCount != EEPROMbankCount) {
EEPROM.put(0,bankCount);  // writes a float to EEPROM
Serial.println(F("!!! EEPROM WRITE !!!"));
EEPROMbankCount = bankCount;
}
}


if (currentCoinSignal != previousCoinSignal) {
// Save the state for next iteration
previousCoinSignal = currentCoinSignal;


if (currentCoinSignal == HIGH) {
      // we see an edge, but is it a coin pulse?
      armedForCount = millis();
} else {
      // short timeout to make sure it was a full pulse
      if (millis() - armedForCount < pulseTimeOut) {
        bankCount++;
      }
    }
}
}

 

Full source Code, Design Files, and Schematics Attached!

Attachments:
Supporting_Files_Capacitive-Coin-Counter.zip
  • clusteredmcuch
  • multilayer ceramic capacitor
  • board connector
  • bald engineer
  • dc-dc boost
  • autodesk fusion
  • e14presents_baldengineer
  • oscilloscope
  • development kit
  • vcp_arduino
  • ardexpert
  • mcu
  • schottky rectifier
  • vcp
  • din connector
  • arduino
  • friday_release
  • surface mount
  • capacitive touch
  • solenoid
  • Share
  • History
  • More
  • Cancel
Actions
  • Share
  • More
  • Cancel
  • Sign in to reply

Top Comments

  • Fred27
    Fred27 over 7 years ago +1
    "Why are you using 2 microcontrollers?" (14:28) That's exactly what I was wondering. The MSP430FR2633 can easily do what the Arduino was doing, saving you power, components and the need to generate 5V…
  • jwore
    jwore over 7 years ago +1
    thanks for including the parts list, can't wait to go buy that $15,000 oscilloscope so I can try this project at home
  • Fred27
    Fred27 over 7 years ago in reply to jwore +1
    That is a great oscilloscope, but a DS1054Z (or a logic analyser) would do the job too.
  • baldengineer
    baldengineer over 7 years ago in reply to Sean_Miller
    what's your setup for audio?

     

    Sorry, trade secret.

     

    Just kidding. image

     

    Wireless lavalier taped under my shirt.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Sean_Miller
    Sean_Miller over 7 years ago

    I've bumped into your blogs in the past.  Nice to hear your voice.  This was great work!

     

    If you don't mind sharing, what's your setup for audio?  I don't see a boom mic on you, but your audio quality is excellent.

     

    Thanks,

    Sean

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • baldengineer
    baldengineer over 7 years ago in reply to Fred27

    I would have ended up with 5 volts anyway. The PowerBoost is my go to LiPo controller. Also, the 12v boost converter I had really struggled with the solenoid’s peak current when it’s input was directly off the battery. Putting two boost converters (3.7 to 5 and 5 to 12) in series let me use what I had on-hand.

     

    As for the the two micros, look at my reply to DAB.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • baldengineer
    baldengineer over 7 years ago in reply to jwore

    While I love my Rohde and do recommend checking them out when in the market for a scope, the RTM is overkill for this application. But it is on my desk and photographs really well. image

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • baldengineer
    baldengineer over 7 years ago in reply to DAB

    Configuring all of the msp430’s perhperials together was a challenge. My inexperience with the platform ended up with some really unshare-able code.  Since I had already prototyped the non-cap sense stuff with an Arduino, I decided to focus on cleaning that up. If I had unlimited time, I would have gotten the 430 into better shape.

     

    Regarding power, the OLED and coin counter are such hogs, another ATmega is a drop from the bucket.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • DAB
    DAB over 7 years ago

    Nice episode.

     

    You really need to look deeper at the MSP430. You do not need the Arduino to make this circuit work and it will improve your power usage just a tad.

     

    DAB

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Fred27
    Fred27 over 7 years ago in reply to jwore

    image That is a great oscilloscope, but a DS1054Z (or a logic analyser) would do the job too.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • jwore
    jwore over 7 years ago

    thanks for including the parts list, can't wait to go buy that $15,000 oscilloscope so I can try this project at home

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Fred27
    Fred27 over 7 years ago

    "Why are you using 2 microcontrollers?" (14:28)

    That's exactly what I was wondering. The MSP430FR2633 can easily do what the Arduino was doing, saving you power, components and the need to generate 5V.

     

    Other than that, a nice project and a great presentation on how you went about it.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube