Pages: 1 [2]   Go Down
Author Topic: Arduino vending machine project  (Read 3939 times)
0 Members and 1 Guest are viewing this topic.
NJ
Offline Offline
Newbie
*
Karma: 0
Posts: 20
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Offline Offline
Full Member
***
Karma: 1
Posts: 108
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Pictures!

I want to see what this monster looks like.
Logged

Linux and Arduino, two great things that go great together!
http://www.roboticcore.com

NJ
Offline Offline
Newbie
*
Karma: 0
Posts: 20
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Not finished yet but will post when Im done!
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 44
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

NJ
Offline Offline
Newbie
*
Karma: 0
Posts: 20
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Silly-con Valley, Ca, U.S.
Offline Offline
Sr. Member
****
Karma: 17
Posts: 420
Lernin' to tinker
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
/*
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.
« Last Edit: March 31, 2011, 04:13:27 pm by biocow » Logged

10 PRINT CHR$(7)
20 GOTO 10

NJ
Offline Offline
Newbie
*
Karma: 0
Posts: 20
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
/*
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.
Logged

Silly-con Valley, Ca, U.S.
Offline Offline
Sr. Member
****
Karma: 17
Posts: 420
Lernin' to tinker
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

but why have it run at all until they have paid fully?
Logged

10 PRINT CHR$(7)
20 GOTO 10

NJ
Offline Offline
Newbie
*
Karma: 0
Posts: 20
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It was the easiest way I could think of to get the job done. smiley-grin
Logged

Pages: 1 [2]   Go Up
Jump to: