Countdown time using TM1637

hello fellow IT professional/Engineering, I'm a new in Arduino I need Help I want to insert timer or equivalent time for 20 php

for example:

20php is 5mins

what code i use

and where to insert the code

thank you

void loop() {
if (noCoin == false) {
noCoin = true;
lcd.setCursor(0, 0);
lcd.print(" Dayawon");
lcd.setCursor(0,1);
lcd.print(" Vendo Machine");

}

buttonState = digitalRead(button);

if (buttonState == 1 && pulse > 0 && userBalance) {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Start Disinfect");

for (int i = pulse; i > 0; i--) {
  lcd.setCursor(0, 1);
  lcd.print("   ");
  lcd.setCursor(0, 1);
  lcd.print(i);
  tone(buzzer,523);
  delay(500);
  noTone(buzzer);
  delay(500);
}

pulse = 0;
noCoin = false;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(" Thank You Bye!");
delay(1700);
lcd.clear();
tone(buzzer, 3000);
delay(200);
noTone(buzzer);
delay(50);
tone(buzzer, 3000);
delay(50);
noTone(buzzer);

}

coinSlotStatus = digitalRead(coinSlot);
delay(30);
if (coinSlotStatus == 0) {
userBalance = true;
lcd.setCursor(0, 0);
lcd.print("Press a Button");
pulse += 1;
lcd.setCursor(0, 1);
sprintf(lcdBuffer, "Bal. Php %d.00", pulse);
lcd.setCursor(0, 1);
lcd.print(lcdBuffer);
delay(30);
}
noTone(buzzer);
}

this is my project or my thesis its like a vendo machine

thanks

Hello @sai_07 - Please format your program/code and paste the formatted code in a < CODE > block. Here is what your sketch should look like:

void loop() {
  if (noCoin == false) {
    noCoin = true;
    lcd.setCursor(0, 0);
    lcd.print(" Dayawon");
    lcd.setCursor(0, 1);
    lcd.print(" Vendo Machine");
  }

  buttonState = digitalRead(button);

  if (buttonState == 1 && pulse > 0 && userBalance) {
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Start Disinfect");

    for (int i = pulse; i > 0; i--) {
      lcd.setCursor(0, 1);
      lcd.print("   ");
      lcd.setCursor(0, 1);
      lcd.print(i);
      tone(buzzer, 523);
      delay(500);
      noTone(buzzer);
      delay(500);
    }

    pulse = 0;
    noCoin = false;
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print(" Thank You Bye!");
    delay(1700);
    lcd.clear();
    tone(buzzer, 3000);
    delay(200);
    noTone(buzzer);
    delay(50);
    tone(buzzer, 3000);
    delay(50);
    noTone(buzzer);
  }

  coinSlotStatus = digitalRead(coinSlot);
  delay(30);
  if (coinSlotStatus == 0) {
    userBalance = true;
    lcd.setCursor(0, 0);
    lcd.print("Press a Button");
    pulse += 1;
    lcd.setCursor(0, 1);
    sprintf(lcdBuffer, "Bal. Php %d.00", pulse);
    lcd.setCursor(0, 1);
    lcd.print(lcdBuffer);
    delay(30);
  }
  noTone(buzzer);
}

You do not have a complete sketch/program. You are missing configurations for your peripheral devices and the setup() function required by the Arduino IDE.

Here is an example of a TM1637 project...

your sketch not complete

void setup() {
lcd.init();
lcd.backlight();
lcd.clear();
pinMode(buzzer, OUTPUT);
pinMode(10, OUTPUT);
digitalWrite(10, LOW);
pinMode(coinSlot, INPUT_PULLUP);
pinMode(button, OUTPUT);
tone(buzzer, 262);
delay(150);
tone(buzzer, 294);
delay(150);
tone(buzzer, 330);
delay(150);
tone(buzzer, 349);
delay(150);
tone(buzzer, 392);
delay(150);
tone(buzzer, 440);
delay(150);
tone(buzzer, 394);
delay(150);
tone(buzzer, 563);
delay(150);
noTone(buzzer);
delay(1000);
}

void loop() {
if (noCoin == false) {
noCoin = true;
lcd.setCursor(0, 0);
lcd.print(" Dayawon");
lcd.setCursor(0,1);
lcd.print(" Vendo Machine");

}

buttonState = digitalRead(button);

if (buttonState == 1 && pulse > 0 && userBalance) {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Start Disinfect");

for (int i = pulse; i > 0; i--) {
  lcd.setCursor(0, 1);
  lcd.print("   ");
  lcd.setCursor(0, 1);
  lcd.print(i);
  tone(buzzer,523);
  delay(500);
  noTone(buzzer);
  delay(500);
}

pulse = 0;
noCoin = false;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(" Thank You Bye!");
delay(1700);
lcd.clear();
tone(buzzer, 3000);
delay(200);
noTone(buzzer);
delay(50);
tone(buzzer, 3000);
delay(50);
noTone(buzzer);

}

coinSlotStatus = digitalRead(coinSlot);
delay(30);
if (coinSlotStatus == 0) {
userBalance = true;
lcd.setCursor(0, 0);
lcd.print("Press a Button");
pulse += 1;
lcd.setCursor(0, 1);
sprintf(lcdBuffer, "Bal. Php %d.00", pulse);
lcd.setCursor(0, 1);
lcd.print(lcdBuffer);
delay(30);
}
noTone(buzzer);
}

here my code

#include <Wire.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27, 16, 2);

#define coinSlot 6
#define buzzer 13
#define button 4

int coinSlotStatus;
int pulse;

boolean userBalance = false;
boolean noCoin = false;

char lcdBuffer[16];

int buttonState;

void setup() {
  lcd.init();
  lcd.backlight();
  lcd.clear();
  pinMode(buzzer, OUTPUT);
  pinMode(10, OUTPUT);
  digitalWrite(10, LOW);
  pinMode(coinSlot, INPUT_PULLUP);
  pinMode(button, OUTPUT);
  tone(buzzer, 262);
  delay(150);
  tone(buzzer, 294);
  delay(150);
  tone(buzzer, 330);
  delay(150);
  tone(buzzer, 349);
  delay(150);
  tone(buzzer, 392);
  delay(150);
  tone(buzzer, 440);
  delay(150);
  tone(buzzer, 394);
  delay(150);
  tone(buzzer, 563);
  delay(150);
  noTone(buzzer);
  delay(1000);
}

void loop() {
  if (noCoin == false) {
    noCoin = true;
    lcd.setCursor(0, 0);
    lcd.print(" Insert Coin");
  }


  buttonState = digitalRead(button);

  if (buttonState == 1 && pulse > 0 && userBalance) {
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Pumping Liquid");

    for (int i = pulse; i > 0; i--) {
      lcd.setCursor(0, 1);
      lcd.print("   ");
      lcd.setCursor(0, 1);
      lcd.print(i);
      tone(buzzer,523);
      delay(500);
      noTone(buzzer);
      delay(500);
    }

    pulse = 0;
    noCoin = false;
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print(" Thank You Bye!");
    delay(1700);
    tone(buzzer, 3000);
    delay(200);
    noTone(buzzer);
    delay(50);
    tone(buzzer, 3000);
    delay(50);
    noTone(buzzer);


  }


  coinSlotStatus = digitalRead(coinSlot);
  delay(30);
  if (coinSlotStatus == 0) {
    userBalance = true;
    lcd.setCursor(0, 0);
    lcd.print("Press a Button");
    pulse += 1;
    lcd.setCursor(0, 1);
    sprintf(lcdBuffer, "Bal. Php %d.00", pulse);
    lcd.setCursor(0, 1);
    lcd.print(lcdBuffer);
    delay(30);
  }
  noTone(buzzer);
}

You must put your code into a < CODE > block. You should have paid attention to your training to get this account, but here is what you ignored:

  1. Edit your post with the code.
  2. CUT your code from the post.
  3. PASTE your code in your IDE.
  4. FORMAT your code in the IDE with CTRL-T.
  5. Cut or copy your code from the IDE
  6. In the edited post, click the < CODE > button
  7. PASTE your formatted code where you see ```type or paste code here```
  8. Click "submit" in your edited post to publish your edit.

See post 2 and 6.

#include <Wire.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27, 16, 2);

#define coinSlot 6
#define buzzer 13
#define button 4

int coinSlotStatus;
int pulse;

boolean userBalance = false;
boolean noCoin = false;

char lcdBuffer[16];

int buttonState;

void setup() {
  lcd.init();
  lcd.backlight();
  lcd.clear();
  pinMode(buzzer, OUTPUT);
  pinMode(10, OUTPUT);
  digitalWrite(10, LOW);
  pinMode(coinSlot, INPUT_PULLUP);
  pinMode(button, OUTPUT);
  tone(buzzer, 262);
  delay(150);
  tone(buzzer, 294);
  delay(150);
  tone(buzzer, 330);
  delay(150);
  tone(buzzer, 349);
  delay(150);
  tone(buzzer, 392);
  delay(150);
  tone(buzzer, 440);
  delay(150);
  tone(buzzer, 394);
  delay(150);
  tone(buzzer, 563);
  delay(150);
  noTone(buzzer);
  delay(1000);
}

void loop() {
  if (noCoin == false) {
    noCoin = true;
    lcd.setCursor(0, 0);
    lcd.print(" Insert Coin");
  }


  buttonState = digitalRead(button);

  if (buttonState == 1 && pulse > 0 && userBalance) {
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Pumping Liquid");

    for (int i = pulse; i > 0; i--) {
      lcd.setCursor(0, 1);
      lcd.print("   ");
      lcd.setCursor(0, 1);
      lcd.print(i);
      tone(buzzer,523);
      delay(500);
      noTone(buzzer);
      delay(500);
    }

    pulse = 0;
    noCoin = false;
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print(" Thank You Bye!");
    delay(1700);
    tone(buzzer, 3000);
    delay(200);
    noTone(buzzer);
    delay(50);
    tone(buzzer, 3000);
    delay(50);
    noTone(buzzer);


  }


  coinSlotStatus = digitalRead(coinSlot);
  delay(30);
  if (coinSlotStatus == 0) {
    userBalance = true;
    lcd.setCursor(0, 0);
    lcd.print("Press a Button");
    pulse += 1;
    lcd.setCursor(0, 1);
    sprintf(lcdBuffer, "Bal. Php %d.00", pulse);
    lcd.setCursor(0, 1);
    lcd.print(lcdBuffer);
    delay(30);
  }
  noTone(buzzer);
}


1 Like

I see you have an Arduino, an LCD, a button and something like a coin counter. Is there anything missing? Would you post a drawing? Also, what is your question?

Buttons are normally INPUT_PULLUP or INPUT. What kind of output button is this? An LED?

Except for the button, your code works. It counts PHP every time a "coin" makes a LOW.

1 Like

there a fog machine and UV light that controlled by Arduino using a relay

my question is if i inserted a coin equivalent time

for example i inserted 20 PHP the coin i inserted will be equivalent in 5mins

thanks

switch limiter such as a sensor for all code before they run

Does the coin counter send out more than one pulse if the coin is 10, 20, 50php?

Please, write in your natural language and use TRANSLATE.GOOGLE.COM to translate into English. Your writing is difficult for me to understand.

ang gusto kung mangyari ay pag nag hulog ako ng 20 pesos sa coinslot may equivanlent na oras at bago mag procced at umandar ang makina ay iprepress nya ang button at pag naubos na ang binigay na oras para magamit ang vendo mag insert sya ulit ng coin or ng pera

ang nangyayari ngayon sa program ko is kada isang pulse ay isang segundo lang

kung baga pag 10 = 10 sec , 20 =20 sec, etc. pano gagawin ko may isa pang pin ang coinslot ko apat na pin

12v
gnd
coin
counter

Translate to English.

What I want to happen is that when I deposit 20 pesos in the coinslot, there is an equivalent amount of time and before the machine starts up, he will press the button and when the time given to use the vendo is up, he will insert a coin again or of money

what is happening now in my program is that each pulse is only one second

if 10 = 10 sec, 20 = 20 sec, etc. how do I make my coinslot four pins have one more pin?

12v
gnd
coins
counter

How many pulses does 10php give?
How many pulses does 20php give?

You can not... or I do not understand.

10
20

sorry typo error