ARDUINO CODE FOR COMBINE LCD,COIN ACCEPTOR, CONTINUOUS ROTATION SERVO& KEYPAD

i need help about arduino code for combine LCD,COIN ACCEPTOR, CONTINUOUS ROTATION SERVO & KEYPAD to build a vending machine~~

my vending machine function is:

1.choose the product with keypad(can choose multi-product in one times)
2."*"use as cancel the order and "#" use as confirm order
3.LCD will display the total cost of product
4.insert coin to coin acceptor untill reach the total cost
5.after reach the total cost,servo will start function 1 by 1

ty for helping~~~

k1zzi:
i need help about arduino code for combine LCD,COIN ACCEPTOR, CONTINUOUS ROTATION SERVO & KEYPAD to build a vending machine~~

my vending machine function is:

1.choose the product with keypad(can choose multi-product in one times)
2."*"use as cancel the order and "#" use as confirm order
3.LCD will display the total cost of product
4.insert coin to coin acceptor untill reach the total cost
5.after reach the total cost,servo will start function 1 by 1

ty for helping~~~

Which part are you having a problem with? More info would help.
Or do you want someone to write it for you?

I need someone write it for me because i am newbie for arduinosry for disturb~

Good luck. :slight_smile:

(It might be quicker to learn how to do it yourself.)

Since this is obviously a commercial venture, how much are you paying?

sorry about that, i cant pay money to u. My pocket almost empty...

my component list
1.LCD 1602C
2.SERVO AS3103
3.KEYPAD 3X4
4.COIN ACCEPTOR

k1zzi:
sorry about that, i cant pay money to u. My pocket almost empty...

my component list
1.LCD 1602C
2.SERVO AS3103
3.KEYPAD 3X4
4.COIN ACCEPTOR

I don't want to do it anyway. I'm busy on my own project. I just thought that if you mentioned how much you were prepared to pay, it might encourage someone to do it for you.

So, you're making a product that will make money for you, but you want someone to write the whole program for free? That's not very fair. :frowning:

#include <Keypad.h>
#include<Servo.h>

Servo myservo;
int pos = 0;
const byte ROWS = 4;
const byte COLS = 3;

char keys [ROWS] [COLS] = {
 {'1', '2', '3',},
 {'4', '5', '6',},
 {'7', '8', '9',},
 {'*', '0', '#',}
};

byte rowPins[] = { 9, 8, 7, 6 };
byte colPins[] = { 12, 11, 10 };
Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

#define ledpin 13

void setup()

{
 myservo.attach(2);
 myservo.write(pos);
 Serial.begin(9600);
}

void loop()
{
 char key = kpd.getKey();
 if (key) // Check for a valid key.
 {
   switch (key)
   {
     case '1':
       Serial.println(key);
       pos = 0;
       myservo.write(pos);
       break;

     case '2':
       Serial.println(key);
       pos = 5;
       myservo.write(pos);
       delay(1375);
       pos = 0;
       myservo.write(pos);
       break;

     case '3':
       Serial.println(key);
       break;

     case '4':
       Serial.println(key);
       break;

     case '5':

       Serial.println(key);

       break;

     case '6':

       Serial.println(key);

       break;

     case '7':
       Serial.println(key);
       break;

     case '8':

       Serial.println(key);

       break;

     case '9':
       Serial.println(key);
       break;

     case '0':
       Serial.println(key);
       break;

     case '*':
       Serial.println(key);
       break;

     case '#':
       Serial.println(key);
       break;

   }

 }
}

i only know use the case "1" start the servo and case"2" stop the servo
i dont know where to start to write the 1st function, pls give me some suggestion

Please modify your Reply #6 and use the code button </> so your code looks like this and is easy to copy to a text editor

Also please remove unnecessary white space.

...R

Robin2:
Please modify your Reply #6 and use the code button </> so your code looks like this and is easy to copy to a text editor

Also please remove unnecessary white space.

...R

ty

Have a look at Planning and Implementing a Program

What do you want to use the keypad for? Does each key represent a different product?

...R

Robin2:
Have a look at Planning and Implementing a Program

What do you want to use the keypad for? Does each key represent a different product?

...R

i use the keypad(1-6) to select 6 different product and the"*"as cancel order "#"as confirm order.After confirm, LCD will display total cost of product and "pls insert coin" .Insert coin to coin acceptor as same value as LCD show, servo will start function 1 by 1.
Before i post this topic, i have discuss with my friend to solve it.
He say need to use float A=(product value) to avoid servo move before coin insert to coin acceptor and float B=(A) for after coin insert same with the product value and trigger the servo function.

May i know some code about analog signal continuous rotation servor how to control angle.

TY.

k1zzi:
he say need to use float A=(product value) to avoid servo move before coin insert to coin acceptor and float B=(A) for after coin insert untill with the same value.show me some examples,ty.

Don't use float values for money. Just use pennies (or cents) because floats aren't precise enough. For displaying to the user you can put a decimal point in the display to show pennies as £.pp

Then you can easily have an IF like this

if (inputPennies >= pricePennies) {
    // move servo to dispense item
}

...R

Robin2:
Don't use float values for money. Just use pennies (or cents) because floats aren't precise enough. For displaying to the user you can put a decimal point in the display to show pennies as £.pp

Then you can easily have an IF like this

if (inputPennies >= pricePennies) {

// move servo to dispense item
}




...R

i can change the pennies to cents or RM??

#include <Keypad.h>
#include<Servo.h>

Servo myservo;

const int coinInt = 0;

int pos = 0;
int priceSen1 = 100;
int priceSen2 = 150;
int priceSen3 = 200;
int priceSen4 = 250;
int priceSen5 = 300;
int prcieSen6 = 350;
int inputSen = 0;

volatile float coinsValue = 0.00;// I dont know how to change this

const byte ROWS = 4;
const byte COLS = 3;

char keys [ROWS] [COLS] = {
 {'1', '2', '3',},
 {'4', '5', '6',},
 {'7', '8', '9',},
 {'*', '0', '#',}
};

byte rowPins[] = { 9, 8, 7, 6 };
byte colPins[] = { 12, 11, 10 };
Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

#define ledpin 13

void setup()

{
 myservo.attach(2);
 myservo.write(pos);
 attachInterrupt(coinInt, coinInserted, RISING);
 Serial.begin(9600);
}
void coinInserted()
{
 coinsValue = coinsValue + 0.10;
 inputSen = 1;
}
void loop()
{
 char key = kpd.getKey();
 if (key) // Check for a valid key.
 {
   switch (key)
   {
     case '1':
       Serial.println(key);
       if (inputSen >= priceSen1) {
         pos = 5;
         myservo.write(pos);
         pos = 0;
       }
       break;

       if (inputSen == 1)
         //Check if a coin has been Inserted
       {
         inputSen = 0;
         //unflag that a coin has been inserted

         Serial.print("Credit: RM");
         Serial.println(coinsValue);
         //Print the Value of coins inserted
       }
   }
 }
}

i dont know how to change the "volatile float coinValue=0.00"

k1zzi:
i can change the pennies to cents or RM??

Is it necessary to ask ?

i dont know how to change the "volatile float coinValue=0.00"

volatile int coinValue = 0;

I think you would benefit from working carefully through several of the example programs that come with the Arduino IDE and a bit of self-study into the C/C++ programming language.

...R

Robin2:
Is it necessary to ask ?

volatile int coinValue = 0;

I think you would benefit from working carefully through several of the example programs that come with the Arduino IDE and a bit of self-study into the C/C++ programming language.

...R

TY.

k1zzi:
TY.

#include <Keypad.h>
#include<Servo.h>

Servo myservo;
int pos = 0;
int cond = 0;
const int coinInt = 0;
const float Value1 = 0.20;
const float Value2 = 0.50;
volatile float coinsValue = 0.00;
int coinsChange = 0;

const byte ROWS = 4;
const byte COLS = 3;

char keys [ROWS] [COLS] = {
  {'1', '2', '3',},
  {'4', '5', '6',},
  {'7', '8', '9',},
  {'*', '0', '#',}
};
byte rowPins[] = { 9, 8, 7, 6 };
byte colPins[] = { 12, 11, 10 };
Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup()
{
  Serial.begin(9600);
  attachInterrupt(coinInt, coinInserted, RISING);
  myservo.attach(4);
  myservo.write(pos);
}
void coinInserted()
{
  if (cond != 0) {
    coinsValue = coinsValue + 0.10;
    coinsChange = 1;
  }
  if (cond == 0) {
    Serial.println("You must select the product first");
  }
}
void loop()
{
  if (coinsChange == 1)
  {
    coinsChange = 0;
    Serial.print("Credit: RM");
    Serial.println(coinsValue);
  }
  char key = kpd.getKey();
  if (key) // Check for a valid key.
  {
    switch (key)
    {
      case '1':
        Serial.println(key);
        cond = 1;
        break;
      case '2':
        Serial.println(key);
        cond = 2;
        break;
      case'*':
        Serial.println(key);
        cond = 3;
        break;
    }
  } if (cond == 1) {
    if (coinsValue >= Value1) {
      Serial.print("ok");
      pos = 5;
      myservo.write(pos);
      delay(3000);
      pos = 0;
      myservo.write(pos);
      cond = 0;
      coinsValue = 0;
    }
  }
  if (cond == 2) {
    if (coinsValue >= Value2) {
      Serial.print("ok");
      pos = 5;
      myservo.write(pos);
      delay(3000);
      pos = 0;
      myservo.write(pos);
      cond = 0;
      coinsValue = 0;
    }
  }  if (cond == 3) {
    Serial.print("ok");
    cond = 0;
  }
}

can teach me about multi-select products by using keypad 3x4 and show the total value after finish select??

k1zzi:
can teach me about multi-select products by using keypad 3x4 and show the total value after finish select??

What does the code you have posted actually do when you run it?
What would you like it to do?

Your question is like an invitation to write the program for you, and I am not going to do that. If there are particular parts of your code that you can't get working I will try to help.

...R