LCD Display Coin Counter and Buttons Demo

This demo utilizes the LCD display and four momentary button switches to simulate the different coins sensed by the LDC1000. Each button represents a different coin (first button is a penny, second is a nickel, third is a dime, fourth is a quarter). After each button is pressed, the LCD display will show which coin was “inserted” and will calculate the total monetary value of the coins counted.

Furthermore, at the Texas Instruments’ United Way Penny Wars fundraiser there is a point system that allows teams to compete against one another in donations. Each team has a jug, and every penny counts as +1 points, but a nickel counts as -5 points, a dime counts as -10 points, and a quarter counts as -25 points. Therefore, teams put pennies into their own jugs to increase their score and put the other coins into the other teams’ jugs to decrease their score. At the end of the donation period, the team with the highest score wins the competition. This competitive nature all of us have is what drove us to also adding the point system to our demo as well. The competition will raise momentum, causing people to donate more.

Here is a video of the demo working!

Check out our Blog tab to see the problems we dealt with for this demo and how we solved them!

Below is the source code for the demo constructed (Note: the text in green are comments added in).

// include the library code:
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(23, 24, 27,28, 29, 30, 34, 33, 32, 31);

const short buttonPenny= 19;
const short buttonNickel= 18;
const short buttonDime= 15;
const short buttonQuarter= 14;

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;
unsigned int totalDecimal=0;
unsigned int totalDollar=0;
unsigned int decimal=0;
int points= 0;

void setup() {
 // set up the LCD's number of columns and rows: 
 lcd.begin (16, 2);
 pinMode (buttonPenny, INPUT_PULLUP );
 pinMode (buttonNickel, INPUT_PULLUP );
 pinMode (buttonDime, INPUT_PULLUP );
 pinMode (buttonQuarter, INPUT_PULLUP );

void loop() {
 // set the cursor to column 0, line 1
 // (note: line 1 is the second row, since counting begins with 0):
 lcd.setCursor (0, 0);
 pennyButtonState = digitalRead (buttonPenny);
 nickelButtonState = digitalRead (buttonNickel);
 dimeButtonState = digitalRead (buttonDime);
 quarterButtonState = digitalRead (buttonQuarter);
 if (pennyButtonState == 1){ 
 delay (200);
 if (nickelButtonState == 1){ 
 delay (200);
 if (dimeButtonState == 1){ 
 delay (200);
 if (quarterButtonState == 1){ 
 delay (200);
 totalDecimal = numPennies+(numNickels*5)+(numDimes*10)+(numQuarters*25);
 totalDollar = totalDecimal/100;
 decimal = totalDecimal-100*totalDollar;
 points=numPennies - (numNickels*5) - (numDimes*10) - (numQuarters*25);
 lcd.setCursor (0,1);
 lcd.print ("$");
 lcd.print(totalDollar );
 if(decimal < 10)

 lcd.setCursor (8,0);
 lcd.print(" pts");