Go Down

Topic: Arduino vending machine project (Read 5624 times) previous topic - next topic

sck2258c

It was just an error I made when I coded it. I will change the code.

TeslaFan

Pictures!

I want to see what this monster looks like.
Linux and Arduino, two great things that go great together!
http://www.roboticcore.com

sck2258c

Not finished yet but will post when Im done!

AeroNotix

I would recommend a C120 coin mech or a Klingon credit board.

The C120 is great and can be programmed to whatever credit you want your product vended at, the Klingon credit board is the same but is better if you want to design your own coin entry mechanism.

I'm an ex-engineer from arcades and these two things are perfect.

sck2258c


I would recommend a C120 coin mech or a Klingon credit board.

The C120 is great and can be programmed to whatever credit you want your product vended at, the Klingon credit board is the same but is better if you want to design your own coin entry mechanism.

I'm an ex-engineer from arcades and these two things are perfect.

Definitely not getting one of those. At their way too expensive.

biocow

#20
Mar 31, 2011, 11:10 pm Last Edit: Mar 31, 2011, 11:13 pm by biocow Reason: 1

I finished the sketch. Here it is:
------------------------------------------------------------
/*
Arduino vending machine program
*/

int mosfetPin = 8;
int coinPin = 7;
int val;


void setup() {               
  pinMode(mosfetPin, OUTPUT);     // Set mode of pin to output
  pinMode(coinPin, INPUT);     // Set mode of pin to input
}


void loop() {
  val = digitalRead(coinPin);  // Read input value and store it in val
  if (val == LOW) {  // Check if the coin hit the microswitch
  digitalWrite(mosfetPin, HIGH);   // Activate the mosfet gate
  delay(5000);              // Allow the motor to run enough to complete task
  digitalWrite(mosfetPin, LOW);    // Stop motor
  }
}
-------------------------------------------------------------
Please check out my sketch and try to point out any flaws.


I don't think that's going to work for you for 2 reasons.

1) Assuming your coin switch is open at rest and closed when a coin passes what you're saying there is "Read the coin pin. If it's LOW (Open, meaning no coin) then run the motor for 5 seconds" Basically you're motor will just run and run giving out free sodas.

2) You had said you're charging $0.75 per soda so you'll need to count the coins.

(Note: Just throwing this together. Not sure if this will work.)

Code: [Select]
/*
Arduino vending machine program
*/

int mosfetPin = 8;
int coinPin = 7;
int val;
int coinCount = 0;


void setup() {               
  pinMode(mosfetPin, OUTPUT);     // Set mode of pin to output
  pinMode(coinPin, INPUT);     // Set mode of pin to input
}


void loop() {
  val = digitalRead(coinPin);  // Read input value and store it in val
  if (val == HIGH) {  // Check if the coin hit the microswitch
    coinCount++; // add 1 to the coin count
    if(coinCount == 3) { // If we've collected 3 coins
      digitalWrite(mosfetPin, HIGH);   // Activate the mosfet gate
      delay(5000);              // Allow the motor to run enough to complete task
      digitalWrite(mosfetPin, LOW);    // Stop motor
      coinCount = 0; // reset the coinCount for the next customer
  }
}



I also foresee some problems with the if(val == HIGH) being run multiple times and causing the coin count to go into the double or even triple digits. Imagine this program is looping a thousand times a second. As the coin is about to come through it's going:

val = LOW
val = LOW
val = LOW

Then all of a sudden a coin comes through and closes your switch for say 50 milliseconds. Now it's going

val= HIGH
coinCount++
val= HIGH
coinCount++
val= HIGH
coinCount++
val= HIGH
coinCount++
val= HIGH
coinCount++

... until the switch opens again. (Actually once it hit 3 it would dispense a soda really only charging $.25 or it.) You can probably get past that by putting a delay inside that if statement.

You can also look search 'debounce' or 'debouncing' on the main Arduino site.
10 PRINT CHR$(7)
20 GOTO 10

sck2258c



I finished the sketch. Here it is:
------------------------------------------------------------
/*
Arduino vending machine program
*/

int mosfetPin = 8;
int coinPin = 7;
int val;


void setup() {               
  pinMode(mosfetPin, OUTPUT);     // Set mode of pin to output
  pinMode(coinPin, INPUT);     // Set mode of pin to input
}


void loop() {
  val = digitalRead(coinPin);  // Read input value and store it in val
  if (val == LOW) {  // Check if the coin hit the microswitch
  digitalWrite(mosfetPin, HIGH);   // Activate the mosfet gate
  delay(5000);              // Allow the motor to run enough to complete task
  digitalWrite(mosfetPin, LOW);    // Stop motor
  }
}
-------------------------------------------------------------
Please check out my sketch and try to point out any flaws.


I don't think that's going to work for you for 2 reasons.

1) Assuming your coin switch is open at rest and closed when a coin passes what you're saying there is "Read the coin pin. If it's LOW (Open, meaning no coin) then run the motor for 5 seconds" Basically you're motor will just run and run giving out free sodas.

2) You had said you're charging $0.75 per soda so you'll need to count the coins.

(Note: Just throwing this together. Not sure if this will work.)

Code: [Select]
/*
Arduino vending machine program
*/

int mosfetPin = 8;
int coinPin = 7;
int val;
int coinCount = 0;


void setup() {               
  pinMode(mosfetPin, OUTPUT);     // Set mode of pin to output
  pinMode(coinPin, INPUT);     // Set mode of pin to input
}


void loop() {
  val = digitalRead(coinPin);  // Read input value and store it in val
  if (val == HIGH) {  // Check if the coin hit the microswitch
    coinCount++; // add 1 to the coin count
    if(coinCount == 3) { // If we've collected 3 coins
      digitalWrite(mosfetPin, HIGH);   // Activate the mosfet gate
      delay(5000);              // Allow the motor to run enough to complete task
      digitalWrite(mosfetPin, LOW);    // Stop motor
      coinCount = 0; // reset the coinCount for the next customer
  }
}



I also foresee some problems with the if(val == HIGH) being run multiple times and causing the coin count to go into the double or even triple digits. Imagine this program is looping a thousand times a second. As the coin is about to come through it's going:

val = LOW
val = LOW
val = LOW

Then all of a sudden a coin comes through and closes your switch for say 50 milliseconds. Now it's going

val= HIGH
coinCount++
val= HIGH
coinCount++
val= HIGH
coinCount++
val= HIGH
coinCount++
val= HIGH
coinCount++

... until the switch opens again. (Actually once it hit 3 it would dispense a soda really only charging $.25 or it.) You can probably get past that by putting a delay inside that if statement.

You can also look search 'debounce' or 'debouncing' on the main Arduino site.

The delay of 5 seconds is not really accurate. I just put it there for now to complete the code. Later, when I time the total time and I divide it by 3 I'll put the correct value in program.So it would run for 1/3 of the time so 3 will = 1 soda.

biocow

but why have it run at all until they have paid fully?
10 PRINT CHR$(7)
20 GOTO 10

sck2258c

It was the easiest way I could think of to get the job done. :D

Go Up