I am going to make a vending machine from spare parts I have accumulated from old printers, toys ect.. and i have got a coin sorter for the money!
i am going to have about 6-8 motors to vend the products this will take up 6-8 outputs
I will be using 2 inputs to the arduino from a keypad using different resistance for product selection
I will be using 4 inputs to detect 4 different coins from the sorter £1, 50p, 20p and 10p
i will be needing to use the serial output (serial.begin) to show the amount of credit in the machine.
If i dont use the serial out to show the amount of credit in the machine i will use 3 outputs to light up 3 leds when the credit is at a certain threshold, e.g : led1= 30p+ and led2= 60p+ and led3= £1+
What i need help with is the programming of the money taken with adding it up and storing it in some variable and when the threshold of a value for example "a can of drink" is at 50p, the customer can select the button that corresponds with that item. (items will be, crisps= 50p, drinks 60p and chocolate bars 70p.)
So, how do i make a program that will count the coins up from the different switches being activated by the coins to then be deducted by what ever selection is being made then allowing the machine to vend.
Im quite new to this and would appreciate anyone help!
I agree with @LarryD. You have described an elephant. They can only be eaten in small pieces.
You need to write separate short programs to figure out how to work with each part seprately. Don't think of creating the whole project until you can do that. Note, also, that it will be much easier to get advice here for problems with small single-purpose programs.
I encourage you on this project. It sounds like fun, but it will be frustrating due to some timing difficulties, especially associated with the coin slots.
I suppose that your coin detector is effectively a momentary pushbutton switch. The coin hits it, it closes, possibly with bounces, then opens. In your main program loop, your are cycling through to see if a coin switch has closed. But you may be in the wrong part of the loop, and not catch it, or you may catch it, and bounces as well, so it seems as though multiple coins have dropped.
So for reliability, you probably need to intercept these switches by interrupts, and you may need pin change interrupts if you are using one of the usual Arduino siblings. But a bounce can also effect interrupts, causing more than one in a row. I've had that problem, so I clear interrupts in my interrupt routine and then add a delay to get beyond bounces.
So what you're trying is doable, bitten off one step at a time, but don't be impatient. This will take time to get right,