Arduino vending machine

I'm trying to make a vending machine with just one snack
For this I have a coin acceptor that I have configured, so that it only accepts coins of 1 euro and that I have connected to pin GND, Vin and 13 and it works well !
And I connect the servo motor on the 13, GND and 5V
I would therefore like to ensure that when the coin acceptor receives 1 euro the servo motor turns
I tried this code but it doesn't work (nothings is happening)
Need help
Thanks to you !


#include <Servo.h>

Servo servo;
int coinPin = 10;
int servoPin = 13;

void setup() {
  servo.attach(servoPin);
  pinMode(coinPin, INPUT_PULLUP);
}

void loop() {
  // Vérifier si une pièce a été insérée
  if (digitalRead(coinPin) == LOW) {
    delay(50);
 // Attendre une courte période pour éviter les faux déclenchements
    
    // Vérifier à nouveau pour confirmer que la pièce est toujours présente
    if (digitalRead(coinPin) == LOW) {
      // Effectuer l'action du servo-moteur
      servo.write(90);
 // Angulation de 90 degrés (rotation du servo-moteur)
      delay(1000); // Attendre 1 seconde
      
      // Réinitialiser la position du servo-moteur
      servo.write(0);
 // Angulation de 0 degré (position initiale)
      
      delay(100);
 // Délai pour éviter les rebonds de signal
    }
  }
}

Do you mean your digitalRead(coinPin) reads LOW when you give it 1EUR and it's only the servo that doesn't work?

Hi, @anonymej
Welcome to the forum.

Isn't that the servo pin?

int coinPin = 10;
int servoPin = 13;

Tom.. :smiley: :+1: :coffee: :australia:

I don’t know the servo motor works too but when i make 1 euro on my coin acceptor the servo motor don’t turn so i think there is an error in the connction between the servo motor and the coin acceptor either in the code or in the circuit

For clarity, which pin is the servo connected to and which pin is the coin acceptor connected to ?

servo motor : pin 13, pin GND, pin 5V
coin acceptor : pin 10, pin Vin, pin GND

Hi, @anonymej

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?
Hand drawn and photographed is perfectly acceptable.
Please include ALL hardware, power supplies, component names and pin labels.

Some images of your project would also help.

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

What voltage does the coin acceptor output to pin 10 ?

12v

Which Arduino board are you using ?

What is the maximum voltage that should be applied to pin 10 on your Arduino ?

[quote="UKHeliBob, post:10, topic:1134345"]
What is the maximum voltage that should be applied to pin 10 on your Arduino ?
[/quote] I use arduino uno (elegro R3)
And I don’t know but I connect the card to a 12V socket

Let me answer my own question

The maximum voltage that should be applies to pin 10 of a Uno is 5V. If you have connected 12V between the pin and GND then I will be very surprised if you have not damaged the pin and possibly other functionality

If you have not yet connected 12V to the Arduino pin then don't do it

1 Like

Hi,
Can you please post link to specs/data of the coin acceptor?

Can we please have a circuit diagram?
An image of a hand drawn schematic will be fine, include ALL power supplies, component names and pin labels.

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

So, I just want a code and a diagram that can i make a servo motor turn when 1 euro is inserted in the servo motor, I tried solutions but I am a beginner
Thanks you so much for help me :smiley:



This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.