Vending machine

Hey, i need help to make a vending machine and my idea is just simple I have 4 columns in my vending machine with 4 buttons and 4 servo motors but I don’t know how to connect it all I want is just that when I push button 1 first a small light blinks and the servo motor start moving for 1 sec and this applies to all 4 buttons. thanks

Hi,

Here’s a link for the connection of the components you described above on circuito.io

https://www.circuito.io/app?components=97,97,97,97,9442,11021,2345678,2345678,2345678,2345678

If you are planning to build a vending machine you should consider using continues rotation servo like f.e the Continuous Rotation Micro Servo - FS90R

the code for the scenario above is quite simple and straight forward, it can be based on the example code on the link above

Here’s a starting point:

// Main logic of your circuit. It defines the interaction between the components you selected. After setup, it runs over and over again, in an eternal loop.
void loop() 
{
    
    if(pushButton_1.read()==HIGH) {               // if the button pressed do the following:
    servo9g_1.attach(SERVO9G_1_PIN_SIG);         // 1. attach the servo to correct pin to control it.
    servo9g_1.write(servo9g_1TargetPosition);  // 2. turns servo to target position. Modify target position by modifying the 'ServoTargetPosition' definition above.
    delay(500);                              // 3. waits 500 milliseconds (0.5 sec). change the value in the brackets (500) for a longer or shorter delay in milliseconds.
    servo9g_1.write(servo9g_1RestPosition);    // 4. turns servo back to rest position. Modify initial position by modifying the 'ServoRestPosition' definition above.
    delay(500);                              // 5. waits 500 milliseconds (0.5 sec). change the value in the brackets (500) for a longer or shorter delay in milliseconds.
    servo9g_1.detach();                    // 6. release the servo to conserve power. When detached the servo will NOT hold it's position under stress.

    }
    else if(pushButton_2.read()==HIGH) {               // if the button pressed do the following:
    servo9g_2.attach(SERVO9G_2_PIN_SIG);         // 1. attach the servo to correct pin to control it.
    servo9g_2.write(servo9g_2TargetPosition);  // 2. turns servo to target position. Modify target position by modifying the 'ServoTargetPosition' definition above.
    delay(500);                              // 3. waits 500 milliseconds (0.5 sec). change the value in the brackets (500) for a longer or shorter delay in milliseconds.
    servo9g_2.write(servo9g_2RestPosition);    // 4. turns servo back to rest position. Modify initial position by modifying the 'ServoRestPosition' definition above.
    delay(500);                              // 5. waits 500 milliseconds (0.5 sec). change the value in the brackets (500) for a longer or shorter delay in milliseconds.
    servo9g_2.detach();                    // 6. release the servo to conserve power. When detached the servo will NOT hold it's position under stress.

    }
    else if(pushButton_3.read()==HIGH) {               // if the button pressed do the following:
    servo9g_3.attach(SERVO9G_3_PIN_SIG);         // 1. attach the servo to correct pin to control it.
    servo9g_3.write(servo9g_3TargetPosition);  // 2. turns servo to target position. Modify target position by modifying the 'ServoTargetPosition' definition above.
    delay(500);                              // 3. waits 500 milliseconds (0.5 sec). change the value in the brackets (500) for a longer or shorter delay in milliseconds.
    servo9g_3.write(servo9g_3RestPosition);    // 4. turns servo back to rest position. Modify initial position by modifying the 'ServoRestPosition' definition above.
    delay(500);                              // 5. waits 500 milliseconds (0.5 sec). change the value in the brackets (500) for a longer or shorter delay in milliseconds.
    servo9g_3.detach();                    // 6. release the servo to conserve power. When detached the servo will NOT hold it's position under stress.

    }
    else if(pushButton_4.read()==HIGH) {               // if the button pressed do the following:
    servo9g_4.attach(SERVO9G_4_PIN_SIG);         // 1. attach the servo to correct pin to control it.
    servo9g_4.write(servo9g_4TargetPosition);  // 2. turns servo to target position. Modify target position by modifying the 'ServoTargetPosition' definition above.
    delay(500);                              // 3. waits 500 milliseconds (0.5 sec). change the value in the brackets (500) for a longer or shorter delay in milliseconds.
    servo9g_4.write(servo9g_4RestPosition);    // 4. turns servo back to rest position. Modify initial position by modifying the 'ServoRestPosition' definition above.
    delay(500);                              // 5. waits 500 milliseconds (0.5 sec). change the value in the brackets (500) for a longer or shorter delay in milliseconds.
    servo9g_4.detach();                    // 6. release the servo to conserve power. When detached the servo will NOT hold it's position under stress.
    }
}
1 Like