Vending machine

Hi there,

Im looking to make a vending machine. I currently went out and brought a button, a dc motor, an arduino board and a motor driver. I am aiming to be able to push a button that then turns on the motor which then turns a certain amount of time at a set speed then stopping after a certain time. And i am unsure of how to do so... is there anyone that can help me with the coding and a diagram of what i need to do????

Once i get one motor and button working im aiming to have 4 buttons and 4 motors which each motor will run when the designated button is pushed.

This design has no flexibility, but it will do exactly what you asked

const int MOTOR_PIN = 2;
const int BUTTON_PIN = 2;
const int MOTOR_ON_MS = 1000;
void setup()
{
  pinMode(BUTTON_PIN, INPUT_PULLUP);
  pinMode(MOTOR_PIN, OUTPUT);
  digitalWrite(MOTOR_PIN, LOW);
}

void loop()
{
  delay(10);
  if (digitalRead(BUTTON_PIN) == LOW)
  {
    digitalWrite(MOTOR_PIN, HIGH);
    delay(MOTOR_ON_MS);
    digitalWrite(MOTOR_PIN, LOW);
 }
}

Is there a diagram of how to put it together?

Generally when I do a project I do the design first then buy the parts. Doing it in reverse makes it much harder to accomplish. In this case you got lucky. You should be able to make a schematic from the code, we get lots of practice here here doing that.

How do I do that?

I’ll send you photos of what I have

I do not recognize the motor driver. I have worked on hundreds, mostly all different. They range from micropower to kilowatts, I realize this is nothing near that. You can solve that problem by posting links to technical information on each of the parts, the UNO I have.

the packaging of the motor says Motor 3VDC 8G/cm Hobby

Hi, @gazbaz11
Welcome to the forum.

Can you please post a link to where you purchased your motor and driver?

Thanks... Tom.. :grinning: :+1: :coffee: :australia:

@gazbaz11, I too design before spending money. Even to the extent of using no parts whatsoever, not even an Arduino board.

See

The premier (IMO) Arduino simulator, where you could do 100 percent of the software and get a very good head start on most of the hardware all with your parked on a comfortable chair in front of your desktop machine.

The real benefit to doing is that very often such zero money just time spent will inform decisions as to what, and whether, to buy.

Only more so for noobs. I can't be sure, but it looks at this point as if software is a big mystery to you, as the functionality you seek is fairly simple coding.

It seems hardware is a mystery also. Srsly consider playing with the simulator, it has plenty of "parts" you can hook together however you want all day long with no money spent and no possibility of damaging them through mistakes in wiring or power or whatever.

a7

1 Like

Motor driver

Motor is

Hmm..... that motor driver looks different then the one linked.

@gilshultz
Looks like a Keystudio L298N
Can't find more info about it.
If you google(or search engine) it you might find the Datasheet.

#define button1 2
#define servo A0
int buttonPressed;

void setup() {


  pinMode(button1, INPUT);
  pinMode(servo, OUTPUT);

}
void loop() {




  // Wait until a button is pressed
  while (true){
    if (digitalRead(button1) == HIGH) 
      buttonPressed = 1;
      delay(2000);
      break;}
    
  
switch(buttonPressed) {
case 1:
  // Rotate the helical coil, discharge the selected item
  digitalWrite(servo, 700); // rotate
  delay(1290);
  digitalWrite(servo, 1500); // stop
  delay(300);
  break;}
}
thats my code so far ill send in my circuit but, im aiming for me to be able to push the button and run the motor for a certain amount of seconds

Thats the circuit and it doesnt seem to do what i need it to do. I push the button and the motor doesnt turn on it just turns off the arduino.... is there anyone that can assist me so i can get it to do what i want it to do.

Post a schematic. Hand drawn works and is fastest and easiest.

I don't have the least doubt that it will show you are trying to provide power to the motor from a source that is inadequate.

You shoukd run power directly to the motor from batteries or a good power supply, no matter how you control that power.

a7

i dont understand????


Ive simplified it down but it still doesnt work

Spot on @alto777 You cannot use an Arduino to power a motor !! Using breadboard for it is pushing your luck too. Google will find a lot of driving motors solutions

I too design first and would re enforce that .
For a vending machine you need to work out how it will work , look at existing machines , work out the mechanics- how does it measure , how does it drop the cup , how does it heat/ cool liquids , how does it remain hygienic ??. You might find for example that a different motor type is better , or some parts can be controlled by solenoids , or it needs a Wi-Fi connection, who knows ?

Are you going to build it , how ? Or is it a desktop exercise , in which you can use leds to stand in for motors ??