Help me with my 1st project (my deadline for this is tommorow please help)

good day. im currently working on my 1st project, it is a vendo machine. and i am having a hard time on it because my && operator is being skipped and also when inserting coins to the coinslot it gives different value it is much less from the value it should be for example i inserted 10pesos the only value that it gives is 5 or 6

#include <Servo.h>

#define coinSlot 11  // coin slot pin
#define button1 3    // button 1 pin
#define button2 4    // button 2 pin
#define button3 5    // button 3 pin
#define button4 7    // button 6 pin
#define servoPin1 8  // servo 1 pin
#define servoPin2 9  // servo 2 pin

Servo servo1;       // create servo 1 object
Servo servo2;       // create servo 2 object
int coinCount = 0;  // variable to store coin count

void setup() {
  Serial.begin(9600);
  servo1.attach(servoPin1);         // attaches the servo 1 on pin 6
  servo2.attach(servoPin2);         // attaches the servo 2 on pin 7
  pinMode(coinSlot, INPUT_PULLUP);  // coin slot as input
  pinMode(button1, INPUT_PULLUP);          // button 1 as input
  pinMode(button2, INPUT_PULLUP);          // button 2 as input
  pinMode(button3, INPUT_PULLUP);          // button 3 as input
  pinMode(button4, INPUT_PULLUP);          // button 4 as input
}

void loop() {
  if (digitalRead(coinSlot) < 1) {  // if a coin is inserted
    delay(30);
    coinCount++;                    // increment coinCount
    Serial.println(coinCount);
  }

  if ((digitalRead(button1) ==  HIGH) && (coinCount == 10)) {  // if 10 coins are inserted and button 1 is pressed
    delay(500);
    servo1.write(180);                                 // turn servo 1 to 90 degrees
    coinCount = 0;                                    // reset coinCount
  }

  if (coinCount == 20 && digitalRead(button2) < HIGH) {  // if 20 coins are inserted and button 2 is pressed
    servo2.write(180);                                 // turn servo 2 to 90 degrees
    coinCount = 0;                                    // reset coinCount
  }

  if (coinCount == 50 && digitalRead(button3) < HIGH) {  // if 50 coins are inserted and button 3 is pressed
    servo1.write(90);                                 // turn servo 1 to 90 degrees
    servo2.write(90);                                 // turn servo 2 to 90 degrees
    delay(500);                                       // wait for a second
    servo2.write(90);                                 // turn servo 2 to 90 degrees again
    coinCount = 0;                                    // reset coinCount
  }

  if (coinCount == 100 && digitalRead(button4) < HIGH) {  // if 100 coins are inserted and button 2 is pressed
    for (int i = 0; i < 5; i++) {                      // loop 5 times
      servo2.write(90);                                // turn servo 2 to 90 degrees
      delay(500);                                      // wait for a second
    }
    coinCount = 0;  // reset coinCount
  }
}

Welcome to the forum

Start by printing the values that you are testing. Are they what you expect ?

Using digitalRead(button4) < HIGH is unconventional but should work but why not use the more conventional digitalRead(button4) == LOW ?

How is the project, and in particular the coin counter, powered ?

have a read of how-to-get-the-best-out-of-this-forum

are you sure your buttons are working correctly? how did you test them?
put some Serial.println() statement in your code to print variable and button values and show the flow of the program execution?

my coinslot is powered by a 12v ac adaptor

Does it have a common GND connection with the Arduino as it should ?

image
this is only how i connect it

Sorry, but it is impossible to see how it is connected to the Arduino from that photograph, can you ?

Please draw a simple schematic and post it here. A picture of a pencil and paper drawing is good enough

the gnd of my coinslot is not connected to the arduino. the gnd of my coinslot is also connected to the ac adaptor

The coinslot and Arduino need to have a common GND in order that they have a common point of reference for signal levels

Are you sure that the coinslot operates with a 5V control input ?

that part is now solved. Thank you
can solved the other problem please!

It seems odd that the logic for button 1 is the opposite to that of buttons 2, 3, and 4.

Can you give us a link to the coinslot that you are using?

help me with my problem about the && operator

Help yourself by printing the values that you are testing. Are they what you expect ? Is the sketch ever reaching that part of the code ?

i've tried it and it's 0. is there anything wrong with it?

#include <Servo.h>

#define coinSlot 11  // coin slot pin
#define button1 3    // button 1 pin
#define button2 4    // button 2 pin
#define button3 5    // button 3 pin
#define button4 7    // button 6 pin
#define servoPin1 8  // servo 1 pin
#define servoPin2 9  // servo 2 pin

Servo servo1;       // create servo 1 object
Servo servo2;       // create servo 2 object
int coinCount;  // variable to store coin count

void setup() {
  Serial.begin(9600);
  servo1.attach(servoPin1);         // attaches the servo 1 on pin 6
  servo2.attach(servoPin2);         // attaches the servo 2 on pin 7
  pinMode(coinSlot, INPUT_PULLUP);  // coin slot as input
  pinMode(button1, INPUT_PULLUP);          // button 1 as input
  pinMode(button2, INPUT_PULLUP);          // button 2 as input
  pinMode(button3, INPUT_PULLUP);          // button 3 as input
  pinMode(button4, INPUT_PULLUP);          // button 4 as input
}

void loop() {
  if (digitalRead(coinSlot) < 1) {  // if a coin is inserted
    delay(30);
    coinCount++;                    // increment coinCount
    Serial.println(coinCount);
    Serial.println(digitalRead(button1));
  }

  if (digitalRead(button1) == 1 && coinCount == 10) {  // if 10 coins are inserted and button 1 is pressed
    delay(500);
    servo1.write(180);                                 // turn servo 1 to 90 degrees
    coinCount = 0;                                    // reset coinCount
  }

  if (coinCount == 20 && digitalRead(button2) == 1) {  // if 20 coins are inserted and button 2 is pressed
    servo2.write(180);                                 // turn servo 2 to 90 degrees
    coinCount = 0;                                    // reset coinCount
  }

  if (coinCount == 50 && digitalRead(button3) == 1) {  // if 50 coins are inserted and button 3 is pressed
    servo1.write(90);                                 // turn servo 1 to 90 degrees
    servo2.write(90);                                 // turn servo 2 to 90 degrees
    delay(500);                                       // wait for a second
    servo2.write(90);                                 // turn servo 2 to 90 degrees again
    coinCount = 0;                                    // reset coinCount
  }

  if (coinCount == 100 && digitalRead(button4) == 1) {  // if 100 coins are inserted and button 2 is pressed
    for (int i = 0; i < 5; i++) {                      // loop 5 times
      servo2.write(90);                                // turn servo 2 to 90 degrees
      delay(500);                                      // wait for a second
    }
    coinCount = 0;  // reset coinCount
  }
}

i've change the code to this

What exactly is zero ?

Do you mean coinCount ?

the button. sorry i'm new to this.

You have used INPUT_PULLUP in pinMode() which is a good idea but how are the button pins wired ?

To make your code more standard please change all of the tests for the result of digitalRead() to HIGH or LOW.

Print the value of all variables and digitalRead()s that are used in your tests immediately before you do the tests. Are the values what you expect ? For instance, does the value of coinCount increase when you insert coins ?

my greatest problem is the servo moving when it reaches the 1st statement or the coincount == 10

my greatest problem is the servo moving when it reaches the 1st statement or the coincount == 10

Do you mean that this test is never true and so the code in the dependant code block is not executed ?

    if (digitalRead(button1) == 1 && coinCount == 10)
    {  // if 10 coins are inserted and button 1 is pressed
        delay(500);
        servo1.write(180);  // turn servo 1 to 90 degrees
        coinCount = 0;      // reset coinCount
    }