i want to build a simple machine something like a vending machine to dispense a ticket.
i have a basic in electronic. but i am totally noob in arduino.
can someone help me to do the coding to complete my project? i dont know if you can understand or not what i want to do with the controller. please see the photo attached to understand what i mean.
im really appreciate if someone can help me out.
oh forgot to tell. im using the arduino uno r3 for the controller + sparkfun 6type multicoin acceptor.\
No one will write the code for you unless you’re willing to pay someone… But from your diagram, it shouldn’t be that hard to do it yourself… That way YOU earn the grade…
my friend give me this code to use. but i dont understand it.
im totally noob.
#include <Wire.h> // Comes with Arduino IDE
#include <LiquidCrystal_I2C.h> // Run Library.
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3,POSITIVE); // Set the LCD I2C address given way to send data from the microcontroller entered the LCD.
int buttonPin =3; // Set leg to get information from a vending machine.
int buttonState =0; // Set the status of buttonPin
int A = 0; // Define The display
void setup()
{
pinMode(buttonPin,INPUT); // Set of legs to stand butttonPin input.
/*
lcd.begin(16, 2); // Define the columns and rows of the LCD.
lcd.setCursor(4,0); // Set the initial position of the cursor position (4,0).
lcd.print("WELCOME"); // Display screen LCD.
lcd.setCursor(0,1); // Set the initial position of the cursor position (0,1).
lcd.print("PLZ INSERT COIN"); // Display screen LCD.
*/
Serial.begin(9600); // Used to type in characters
lcd.begin(16,2); // initialize the lcd for 16 chars 2 lines, turn on backlight
//-------- Write characters on the display ------------------
// NOTE: Cursor Position: (CHAR, LINE) start at 0
lcd.setCursor(0,0); //Start at character 4 on line 0
lcd.print("Welcome!");
delay(1000);
lcd.setCursor(0,1);
lcd.print("PLZ Insert Coin");
delay(8000);
// Wait and then tell user they can start the Serial Monitor and type in characters to
// Display. (Set Serial Monitor option to "No Line Ending")
lcd.clear();
lcd.setCursor(0,0); //Start at character 0 on line 0
}
void loop()
{
buttonState = digitalRead(buttonPin); // Store the buttonPin In buttonState
lcd.setCursor(0,0); // Set the initial position of the cursor at (0,0).
if(buttonState==LOW) // conditions.
{
A+=10; // Calculate the value added By increments of 5
delay(500); // Define a delay 500ms.
lcd.clear(); // Clear the entire LCD screen.
lcd.print("CREDIT"); // Display screen LCD.
lcd.setCursor(8,0); // Set the initial position of the cursor position (8,0).
lcd.print(A); // Show the value of the variable A to the screen LCD.
lcd.setCursor(12,0); // Set the initial position of the cursor position (8,0).
lcd.print("BATH"); // Display screen LCD.
}
}
how much should i pay to you if you help me sir? thank you…
This should work. Here’s a modified version of the code that does everything:
#include <Wire.h> // Comes with Arduino IDE
#include <LiquidCrystal_I2C.h> // Run Library.
#include <Servo.h> // For servos
//Above: tells Arduino that it should use the LCD & servo motor.
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // Set the LCD I2C address given way to send data from the microcontroller entered the LCD.
//Above: Tells Arduino the pins of the LCD
int coinCounter = 3; // the pin of the coin counter
int buttonPin = 7; // the first pin of the button
int buttonPin2 = 6; // the second pin of the button
int greenLED = 4; // green LED
int redLED = 5; // red LED
int A = 0; // Define The display
volatile int coinCount = 0; // count how many coins are inserted
int servoPin = 9; // servo pin
Servo servo; // servo
void setup()
{
pinMode(coinCounter, INPUT); //initialize the pin
pinMode(buttonPin, INPUT_PULLUP); //read from the button
pinMode(buttonPin2, OUTPUT); //act as ground
pinMode(greenLED, OUTPUT); //green LED
pinMode(redLED, OUTPUT); //red LED
lcd.begin(16, 2); // initialize the lcd for 16 chars 2 lines, turn on backlight
attachInterrupt(1, onCoin, RISING); // allow the coin counter to interrupt the program (first paramater: 0=pin 2, 1=pin 3)
servo.attach(servoPin); //servos
servo.write(0);
}
void loop()
{
lcd.clear();
lcd.setCursor(0, 0); //Start at character 4 on line 0
lcd.print("Welcome! Please");
lcd.setCursor(0, 1);
lcd.print("Insert Coins.");
while (coinCount < 1); //wait for at least one coin
lcd.clear();
lcd.setCursor(0, 0); //Start at character 0 on line 0
lcd.print("Insert more");
lcd.setCursor(0, 1);
lcd.print("coins, please.");
digitalWrite(redLED, HIGH); // turn on red LED
while (coinCount < 10); //wait for 10 pulses
digitalWrite(greenLED, HIGH); // turn on green LED
digitalWrite(redLED, LOW); // turn off red LED
lcd.clear();
lcd.setCursor(0, 0); //Start at character 0 on line 0
lcd.print("Please push");
lcd.setCursor(0, 1);
lcd.print("the button.");
while (digitalRead(buttonPin) == LOW); //wait for button
digitalWrite(redLED, LOW);
digitalWrite(greenLED, LOW);
lcd.clear();
lcd.setCursor(0, 0); //Start at character 0 on line 0
lcd.print("Thank you!");
coinCount -= 10;
servo.write(180);
delay(15);
servo.write(0);
delay(2000);
digitalWrite(greenLED, HIGH); // turn off green LED
digitalWrite(redLED, LOW); // turn off red LED
}
void onCoin(){
coinCount++; //keep track of coins
}
Oh, and by the way: did his code work? I mainly based my code off of his. And, by the way, I work for free. Because this is a university project, I recommend looking at the code, seeing what it does, and rewriting it yourself. See if you can make it more efficient, better, or cleaner.