Adding Total balance

Hello everyone, I'm new to Arduino and I'm trying to make a piggy bank that tells me the total amount. I have a Pyramid 5600 Bill acceptor connected to my Arduino with a display. I was able to figure the code for displaying each bill amount on the lcd. the problem is, I'm having trouble figuring out how to add the total amount. for example I add $1 to the acceptor and the display shows $1 and when I add a 5$ bill the lcd changes to $5 instead of displaying a total of $6. I know it's probably very simple but I can't figure it out even after looking at other similar sketches and vids. and please dumb it down as much as you can because I'm still very new to this and still trying to learn. and sorry in advance if I don't post the code correctly. I posted a simalar post on here a week ago and people told me I posted it wrong

//pulse mode, 2 pulses per dollar
//pyramid apex 5600 bill acceptor
//red 12v, black & violet gnd, brown to digital 2

#include <LiquidCrystal_I2C.h>
#define BILL 2
LiquidCrystal_I2C lcd(0x27, 16, 2);
void setup() {

  lcd.init();
  lcd.clear();
  lcd.backlight();
  lcd.setCursor(0, 0);
  lcd.print("Total Balance:");
  pinMode(BILL, INPUT);
  digitalWrite(BILL, HIGH);
}

void loop() {
  lcd.setCursor(1, 1);
  while (digitalRead(BILL) == HIGH)
    ;

  int counter = 1;
  long start = millis();
  int lastRead = LOW;
  long lastChange = start;
  while (millis() - lastChange < 60) {
    delay(25);
    if (lastRead != digitalRead(BILL)) {
      counter++;
      lastChange = millis();
    }
    lastRead = digitalRead(BILL);
  }



  if (counter > 1) {
    lcd.print("$");

    int approximateDollars = counter / 4;

    if (approximateDollars > 0 && approximateDollars <= 2)
      lcd.print(1);
    else if (approximateDollars > 2 && approximateDollars <= 6)
      lcd.print(5);
    else if (approximateDollars > 6 && approximateDollars <= 12)
      lcd.print(1);
    else if (approximateDollars > 12 && approximateDollars <= 30)
      lcd.print(20);
    else if (approximateDollars > 30 && approximateDollars <= 60)
      lcd.print(5);
    else if (approximateDollars > 60 && approximateDollars <= 120)
      lcd.print(10);


    else if (approximateDollars > 120 && approximateDollars <= 240)
      lcd.print(20);
    else if (approximateDollars > 240 && approximateDollars <= 480)
      lcd.print(50);





    Serial.println(".00 detected");
  }
}

You have made a mess of posting your code

In my experience the easiest way to tidy up the code and add the code tags is as follows

Start by tidying up your code by using Tools/Auto Format in the IDE to make it easier to read. Then use Edit/Copy for Forum and paste what was copied in a new reply. Code tags will have been added to the code to make it easy to read in the forum thus making it easier to provide help.

1 Like

You're going the wrong way into programming. Get a basic course in C, or C## and learn. Details are often delicate and copying code, without understanding the details, is like jumping into the dark.

1 Like
//pulse mode, 2 pulses per dollar
//pyramid apex 5600 bill acceptor
//red 12v, black & violet gnd, brown to digital 2

#include <LiquidCrystal_I2C.h>
#define BILL 2
LiquidCrystal_I2C lcd(0x27, 16, 2);
void setup() {

  lcd.init();
  lcd.clear();
  lcd.backlight();
  lcd.setCursor(0, 0);
  lcd.print("Total Balance:");
  pinMode(BILL, INPUT);
  digitalWrite(BILL, HIGH);
}

void loop() {
  lcd.setCursor(1, 1);
  while (digitalRead(BILL) == HIGH)
    ;

  int counter = 1;
  long start = millis();
  int lastRead = LOW;
  long lastChange = start;
  while (millis() - lastChange < 60) {
    delay(25);
    if (lastRead != digitalRead(BILL)) {
      counter++;
      lastChange = millis();
    }
    lastRead = digitalRead(BILL);
  }



  if (counter > 1) {
    lcd.print("$");

    int approximateDollars = counter / 4;

    if (approximateDollars > 0 && approximateDollars <= 2)
      lcd.print(1);
    else if (approximateDollars > 2 && approximateDollars <= 6)
      lcd.print(5);
    else if (approximateDollars > 6 && approximateDollars <= 12)
      lcd.print(1);
    else if (approximateDollars > 12 && approximateDollars <= 30)
      lcd.print(20);
    else if (approximateDollars > 30 && approximateDollars <= 60)
      lcd.print(5);
    else if (approximateDollars > 60 && approximateDollars <= 120)
      lcd.print(10);


    else if (approximateDollars > 120 && approximateDollars <= 240)
      lcd.print(20);
    else if (approximateDollars > 240 && approximateDollars <= 480)
      lcd.print(50);





    Serial.println(".00 detected");
  }
}

Thank you! that helps out a lot

I know, I'm trying to study everything but with work I barely have free time and the little time I do have, I just want to get a project going. I'm actually learning a lot through other peoples codes and youtube vids but yes you are correct I need to go about it the right way

Then hiring professionals to do the job is an option. As #7 tells, You're out on deep water.

This Forum is no help at all. If everyone had time to take classes we wouldn't need a Forum in the first place. Yes I need to learn program properly and do watch courses when I can but I don't spend too much time programming. I like to build things and every now and then i need an Arduino to run something I'm building. in this case I'm trying to make something to help me save money and yes I need the Arduino to run it And yes Knowing everything about programing would help and be a lot faster but I don't see the point in spending weeks learning everything about programing just to add a total especially now when I'm this close to it working. I figured the rest out on my own and I guess I'll figure this out on my own. thanks anyway

No I wasn't asking you to do work for me I was asking for advice on how to do it.
You know, asking questions like everyone else on here. only difference is, they got help and good advice and I got keyboard warriors telling me to go take classes and figure it out myself. just like the last post. I don't see the difference in my posts compared to others so I don't seen how I get the negative feedback. I learn by watching and asking questions. Not by sitting through long courses that mostly have nothing to do with what I'm trying to do. My project mostly works from the hard work i put in already other than not adding total. I figured out counting pulses from the bill acceptor and learned as I went. I simply asked for advice on it. I didn't say "hey write my code for me" It just blows my mind. When kids ask ya'll a question do you say "go read a book and figure it out yourself"?

@southatlantagaragedoor ,
I usually stay away from programming questions because I'm not very good at reading other people's code, but here goes with questions intended to help you without just doing it for you.

In your code which variable do you think keeps a running total?
Do you know what 'scope' means?
Do you know what 'static' means?

The answers to those questions will take you closer to a solution, so I suggest you consider them in your search for a solution.

1 Like

Thank you for the response. and no I wasn't expecting anyone to write a code for me I was just looking for how to. I don't mind researching and figuring it out, I just wanted a starting point and this helps a lot because it gives me a starting point

What is the worth of 1 pulse? If you inserted a $5 bill, how many pulses would the acceptor emit?

1 Like

Is your bill acceptor going LOW when a bill is inserted? I think these two lines:

  pinMode(BILL, INPUT);
  digitalWrite(BILL, HIGH);

should be this one line:

  pinMode(BILL, INPUT_PULLUP);

My guess is, when you insert a bill, the device pulses low depending on the denomination (I do not know how it sees 5 or 20 or 100).

1 Like

For the curious: PYRAMID APEX 5000 SERIES INSTALLATION & OPERATION MANUAL Pdf Download | ManualsLib

1 Like

I was able to get it working correctly by using A coin acceptor sketch and changing some things around. And the Bill acceptor can be programed to whatever pulse you choose. I had to set it to 1 pulse per dollar and set the pulse speed to slow.
Thank you for the positive response

1 Like

I used a similar one but thank you. I was able to Get it working properly. and if anyone is interested in the code or has had the same problem I can post the code to help you out.

It can be set for different pulses. I have it set to 1 pulse per dollar.
I was able to get it working properly though. Thanks for the reply

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.