Go Down

Topic: general questions to my Counting Machine (Read 195 times) previous topic - next topic

X3sA

Nov 06, 2018, 10:59 pm Last Edit: Nov 08, 2018, 07:32 pm by X3sA
Hi there,
im quite new to Arduino. Im working as Pizzadriver, besides school, so I have a lot of small coins. I want to buy a machine that sorts and counts. The sorting is done mechanical.

My Idea for counting was this:
every coin conduct electricity, so if a coin passes 2 wires it closes the circle, the Arduino detects the voltage and count one coin plus.
I used the program for a button. And it kind of works but sometimes it counts but the wires arent touching.

Maybe you have a smarter Idea? Mine is probably not the best...
P.s. sorry for bad englisch :D




Code: [Select]

//define variables
int count= 0;
int buttonPin1= 2;
int buttonState1 = 0;
int gesamt=0;

void setup()
{
  Serial.begin(9600);
  pinMode(buttonPin1, INPUT);
}
 
void loop()
{
  buttonState1 = digitalRead(buttonPin1);
  if(buttonState1==0 )  //if there is a voltage he goes in here
  {
    count++;            //counts my variable
    delay(500);         //buffer because the coin takes some time to fully past the wire, program should not count more then 1
    Serial.print(count);//test
    Serial.print(" ");
    delay(300);
  }

  if(count==100)        //abort condition
  {
    gesamt=count*2;
    Serial.print("Der Gesamtbetrag beträgt:");
    Serial.print(gesamt);
    while(1);           //endless loop to end program
  }
}

Delta_G

Quote
I don´t know where to put my code so i just copy it:
There was a thread just above where you posted this called "How to use this forum - please read".  Did you even consider looking for instructions or reading them?



You have your pin configured as "INPUT" instead of "INPUT_PULLUP".  How do you have it wired?  Is your pin floating when the circuit isn't closed?   
|| | ||| | || | ||  ~Woodstock

Please do not PM with technical questions or comments.  Keep Arduino stuff out on the boards where it belongs.

PaulS

Code: [Select]
    delay(500);         //buffer because the coin takes some time to fully past the wire, program should not count more then 1
Stuffing your head in the sand for a fixed length of time is NOT the correct way to deal with this situation.

Look at the state change detection example. Increment the count when the switch BECOMES "pressed".
The art of getting good answers lies in asking good questions.

X3sA

@Delta_G
Sorry I didnt saw that post, gonna read it now.
Thanks for your answer. And its a simple circuit, and 2 cables arent pluged in, i hold them together when they should count and else they are floating.

X3sA


X3sA

Thanks a lot!
First I only Used StateChangeDetection. Worked but not like i wanted it.
Then I also changed it to INPUT_PULLUP and now it works fine.
But I still have one question. I thougt that "HIGH" means there is a Voltage but it somehow its "LOW"... why so?

Delta_G

#6
Nov 08, 2018, 08:51 pm Last Edit: Nov 08, 2018, 11:11 pm by Delta_G
High means 5V and Low means connected to ground.  Not connected is floating and that can read anything at random.

Most of the time we wire our buttons and switches so that they connect to ground when made so LOW usually means a pressed button.  That is done so that the wires going to the buttons aren't carrying voltage.  That way we avoid so many hot wires that could short to ground. 

EDITED per #7
|| | ||| | || | ||  ~Woodstock

Please do not PM with technical questions or comments.  Keep Arduino stuff out on the boards where it belongs.

florinc

#7
Nov 08, 2018, 09:32 pm Last Edit: Nov 08, 2018, 10:06 pm by florinc
Quote
connectedness
connection? connectivity?

johnwasser

#8
Nov 08, 2018, 10:05 pm Last Edit: Nov 08, 2018, 10:05 pm by johnwasser
Coins are dirty and might not make good contact with wires.  They do, however, block light quite well.    I would recommend a photo interrupter to sense the passage of coins.
 http://www.martyncurrey.com/connecting-an-photo-interrupter-to-an-arduino/
Send Bitcoin tips to: 1G2qoGwMRXx8az71DVP1E81jShxtbSh5Hp

florinc

Quote
every coin conduct electricity, so if a coin passes 2 wires it closes the circle, the Arduino detects the voltage and count one coin plus.
This solution just counts the number of coins, regardless of the coin value. Is this what you want?
A coin acceptor uses Hall sensors to "calculate" the signature of a coin, thus distinguishing between coins.
You put the coins through a coin acceptor to calculate a specific amount (of money) rather than count the coins.


Delta_G

connection? connectivity?

Sorry.  Just connected.   Typing on a little phone keyboard and dealing with autocorrect. 
|| | ||| | || | ||  ~Woodstock

Please do not PM with technical questions or comments.  Keep Arduino stuff out on the boards where it belongs.

X3sA

No, the coins are getting sorted. In every storage is one "detector" and stores the counting in different variables.

Go Up