Arduino signal timer

Hello friends

I am working on a project

I have a soda dispensing machine which dispenses soda when soda valve is pressed and it triggers a relay which switches on valves and soda gets dispensed

So I want to make a digital counting meter which can detect no. Of glasses dispensed so I can track my sales.

Can you please help me with this?

Yes I can help. My way of helping is help to selfhelp

You may not believe it but I'm really sure. You will have a lot of wishes to modify and exapnd your code again and again.
When to reset the counter. Having multiple counters. Keep counted value even if power was off accidently etc. etc. etc.

Doing this through posting new posts "can somebody make the following changes to my code" again and again and again. Will take weeks and months. That's the reason why I recomend learning the basics. You don't have to become a very advanced programmer but at least you should know some basics.

I recommend reading this tutorial

Arduino Programming Course

Arduino Programming Course

It is easy to understand and a good mixture between writing about important concepts
and get you going.

best regards Stefan

rohit7508:
I have a soda dispensing machine which dispenses soda when soda valve is pressed and it triggers a relay which switches on valves and soda gets dispensed

So I want to make a digital counting meter which can detect no. Of glasses dispensed so I can track my sales.

Does each button press dispense one glass? If so, you just want to count the number of button presses. If not, what are you counting?

johnwasser:
Does each button press dispense one glass? If so, you just want to count the number of button presses. If not, what are you counting?

Each button doesn't mean a glass dispensed as we need to press it 2-3 times because co2 gas builds above soda so 2-3 presses are needed.
But I have observed one thing that it takes a fix time to dispense fix quantity for example it takes 4 seconds to dispense 200ml in 2 times

rohit7508:
Each button doesn't mean a glass dispensed as we need to press it 2-3 times because co2 gas builds above soda so 2-3 presses are needed.
But I have observed one thing that it takes a fix time to dispense fix quantity for example it takes 4 seconds to dispense 200ml in 2 times

Well, there is the solution. Now all you have to do, is sense whether it's on. If it's on, increment a timer, otherwise do not. I think the comments in reply #1 are right on. This is the perfect learning task, there is nothing really tricky about it, that we need to give advice. Many starting examples deal with timing, so everything you need is there. When you finish working on your sketch, you can post it here if there are specific problems.

If you're wondering about the method, realize that you can sample the tap at fixed time intervals. At that time you can use an if statement to either increment a variable (add 1 to it), or else don't. After some time frame has elapsed during which the tap was on and off, the counter variable will then contain the sum of all the time intervals during which it was on. Some simple math will then get you the liquid volume.

aarg:
Well, there is the solution. Now all you have to do, is sense whether it's on. If it's on, increment a timer, otherwise do not. I think the comments in reply #1 are right on. This is the perfect learning task, there is nothing really tricky about it, that we need to give advice. Many starting examples deal with timing, so everything you need is there. When you finish working on your sketch, you can post it here if there are specific problems.

If you're wondering about the method, realize that you can sample the tap at fixed time intervals. At that time you can use an if statement to either increment a variable (add 1 to it), or else don't. After some time frame has elapsed during which the tap was on and off, the counter variable will then contain the sum of all the time intervals during which it was on. Some simple math will then get you the liquid volume.

hello sir after speding aprox 5days i made this

now i only need one thing that is when every times there is a increase in value of l or o or a or f a beep or buzzer should ring can u help me with this

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

// Set the LCD address to 0x27 for a 16 chars and 2 line display
LiquidCrystal_I2C lcd(0x27, 16, 2);
/*

*/

// constants won't change. They're used here to set pin numbers:/ the number of the pushbutton pin

unsigned int lemon =EEPROM.read(1)*50;
unsigned long int orange =EEPROM.read(2)*50;
unsigned long int fruit =EEPROM.read(3)*50;
unsigned long int apple =EEPROM.read(4)*50;
int l=EEPROM.read(1);
int o= EEPROM.read(2);
int f= EEPROM.read(3);
int a=EEPROM.read(4);

// variables will change:
int buttonState1 = 0;
int buttonState2 = 0;
int buttonState3 = 0;
int buttonState4 = 0;
int buttonState5 = 0;

void setup() {

pinMode(2, INPUT_PULLUP);
pinMode(4,INPUT_PULLUP);
pinMode(6,INPUT_PULLUP);
pinMode(8,INPUT_PULLUP);
pinMode(10,INPUT_PULLUP);

lcd.begin();
lcd.backlight();
lcd.print("SHARMA SODA");
lcd.setCursor(0,1);
lcd.print("POINT");
delay(2000);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("BEST QUALITY");
lcd.setCursor(0,1);
lcd.print("GUARNTEED");
delay(2000);

lcd.clear();

}

void loop() {
lcd.setCursor(0,0);
lcd.print(l);
lcd.print(" LEM");

lcd.setCursor(6,0);
lcd.print(o);
lcd.print(" ORNG");

lcd.setCursor(0,1);
lcd.print(f);
lcd.print(" FRT");

lcd.setCursor(6,1);
lcd.print(a);
lcd.print(" APL");

buttonState1 = digitalRead(2);
buttonState2 = digitalRead(4);
buttonState3 = digitalRead(6);
buttonState4 = digitalRead(8);
buttonState5 = digitalRead(10);

// check if the pushbutton is pressed. If it is, the buttonState is HIGH:
if (buttonState1 == LOW) {

l=lemon/50;
lemon ++;
EEPROM.update(1,l);

delay(10);

}
if (buttonState2 == LOW) {

o=orange/50;
orange ++;
EEPROM.update(2,o);

delay(10);
}
if (buttonState3 == LOW) {

f=fruit/50;
fruit ++;
EEPROM.update(3,f);

delay(10);
}
if (buttonState4 == LOW) {

a=apple/50;
apple ++;
EEPROM.update(4,a);

delay(10);
}

if (buttonState5 == LOW) {

EEPROM.write(1,0);
EEPROM.write(2,0);
EEPROM.write(3,0);
EEPROM.write(4,0);

}

}

This combination of operations is not making any sense to me. You have two counters for each flavor: X and XTimes50. You initialize both from EEPROM. When the button is pushed you set X to (XTimes50 divided by 50), increment XTimes50, and store X in EEPROM. The EEPROM value won't change until you have pressed the button 51 times!

Let's say that EEPROM[1] contains the number 3.

unsigned int lemon = EEPROM.read(1) * 50;  // Set 'lemon' to 150.
int l = EEPROM.read(1);  // Set 'l' to 3.

    // When a button is pushed...
    l = lemon / 50;  // Set 'l' to 3 until 'lemon' gets to 200, then set 'l' to 4 (200/50).
    lemon ++;  // Set 'lemon' to 151, 152, 153...  199, 200
    EEPROM.update(1,l);  // Store a 3 in EEPROM (unless there were 50 previous button presses