Coin Sorter & Counter (Arduino Uno)
by neiltryan in Circuits > Arduino
10569 Views, 4 Favorites, 0 Comments
Coin Sorter & Counter (Arduino Uno)
Authors:
Dylan Hepburn
Aidan Lyons
Neil Ryan
Acknowledgements:
California State University Maritime Academy
Prof. Chang-Siu (ET 370 Electronics)
Erin Cole
Dane Sutton
Chris Mulhauser
Supplies
Please see Step 2.
The Idea
Description of Idea:
Mechanical coin sorters are by no means a new idea. Most sorters separate coins based on diameter. Coins roll along or slide down a ramp that has differently sized slots cut into it. Going from the top of the ramp to the bottom, the slots get progressively larger. A coin will pass by any slot that does not accommodate its diameter, and will fall into the first slot that does. Each slot leads to a tray or other receptacle that holds only one size of coin. While sorting coins by size can easily be done mechanically, counting them is a task where electronics are better suited. This project uses infrared (IR) sensors to count coins as they fall from the slots to the trays. The sensors communicate with an Arduino Uno microcontroller that sums the total value of all the coins in all trays. The Arduino controls an LCD display which displays the sum of all coins currently in the counter. The LCD also says which type of coin has been detected, when a coin tray is full, and when a coin tray has been emptied. The Arduino also controls five LED's and communicates with five tactile buttons. When any coin tray is full, a master LED (colored red) will illuminate. This notifies the user that one of the trays is full. At the same time, a secondary LED (colored green, yellow, clear, or blue) will also light up. The color of whatever secondary LED is illuminated indicates which of the four coin trays is full. Once a coin tray is full, the coin counter will not process any more coins of any type until the full tray is emptied and its respective reset button is pressed. Pressing a coin tray's reset button will subtract the value of however many coins were in the tray.
YouTube Video:
Link to video: https://www.youtube.com/watch?v=64j1PS3xZ_g
Bill of Materials (see the Two Attached Photos)
Additional Supplies Needed:
- 3/8" plywood sheets--for base and for the "table" that supports the IR sensor holders.
- Four, 3-inch tall PVC pipe fittings--to elevate the sensor-holding table (wooden blocks that are 3 inches tall can also be used).
- Material to form triangular frame that rests on IR sensor holders and holds up coin sorting slide. This material can be thin plywood, acrylic sheets, or anything else that is rigid and can be glued together.
- Material to make coin trays and the partitions that separate each coin tray. Can be thin plywood, acrylic sheets, or even cardboard.
- Lead based solder (lead free works, but we found that the lead solder worked far better).
- Hot glue or super glue.
Tools Used:
- Safety glasses--for soldering, cutting wires, and cutting wood
- Wire cutters
- Wire strippers
- Wood saw
- Soldering iron
- Cleaning wire for soldering iron tip
- Tip tinner
- Support stand to hold up breadboard when soldering (e.g. "QuadHands" or "Helping Hands" tools)
- Desoldering pump (for any mistakes made)
- Hot glue gun
CAD Files for 3D Printing
These 3 files are the Gcode for the 3D printed parts. This was created using Autodesk inventor and was sliced by Ultimaker Cura 4.8.1.
We use 1 of the coin slides, 4 of the coin catch basins are used, and 4 of the IR sensor holders.
We found that the best infill based on time required to print and the strength required was between 15% and 20%. for the final project, we opted for a 15% infill on the coin slide and 18% infill on the IR sensor holders and the catch basin. For the base support, we used brim as it allowed us to adjust our height if there was any issues without compromising our tolerances.
INO Files for Arduino
(The INO files contains the code in an Arduino format. The file titled "tinkercad30april.ino" is the basic code needed to run the coin counter. The file titled "counter_with_lcd_text.ino" is the same exact code as the first file, only the LCD now also displays text from the serial monitor rather than just the counter's overall sum.)
Coin Detect
Code:
if (quarterState == LOW && quarterStatePrev == HIGH){
quarters++;
Serial.print(" number of quarters ");
Serial.println(quarters);
Serial.println(" Quarter Detected! :) ");
Explanation:
The coin detection code is based on the input from one of our IR sensors, in this case the quarter sensor. The sensor outputs a constant high signal when it does not detect anything. The high signal is cut off when an object passes by the sensor. This code looks for the transition from the low “detection” signal, to the high “no detection” signal. When this transition occurs, the serial monitor displays the number of quarters, announces a quarter was detected, and adds 1 to the number of quarters counted within the sorter.
State Changes
Code:
if (quarters == 10){
state = 2;
Serial.print(" number of quarters ");
Serial.println(quarters);
Serial.println(" Quarters Full ");
digitalWrite (quarterLedPin, HIGH);
digitalWrite (masterLedPin, HIGH); }
Explanation:
When the number of any coin reaches a predetermined value, shown here as 10 quarters, the machine will transition to a specific state for a full coin sorter. Additionally, this state change is reported to the serial monitor, along with the number of that coin within the device, and the Master and coin specific LED are illuminated.
Coin Resets
Code:
if (quarterResetState == HIGH && quarterResetStatePrev == LOW){
quarters = 0; Serial.print(" number of quarters ");
Serial.println(quarters);
Serial.println(" Quarters Reset ");
digitalWrite (quarterLedPin, LOW);
digitalWrite (masterLedPin, LOW);
state = 1;
Explanation:
Once any coin reaches the previously mentioned full state, this is the state the device will transition into. It will wait for the transition of the reset button from a low output signal, to the high (pressed) output signal. Using this transition check instead of the pure output helps prevent the single button press from being seen as multiple button presses by the Arduino. When this button press is detected, the number of that specific coin is reset to zero, the LED's are turned off, and the updated number of that coin is reported to the serial monitor.
Master Reset
Code:
if (masterResetState == HIGH && masterResetStatePrev == LOW){
quarters = 0;
nickels = 0;
pennies = 0;
dimes = 0;
Serial.print(" number of quarters ");
Serial.println(quarters);
Serial.print(" number of nickels ");
Serial.println(nickels);
Serial.print(" number of pennies ");
Serial.println(pennies);
Serial.print(" number of dimes ");
Serial.println(dimes);
Serial.println(" Full Coin Sorter Reset");
digitalWrite (quarterLedPin, LOW);
digitalWrite (nickelLedPin, LOW);
digitalWrite (pennyLedPin, LOW);
digitalWrite (dimeLedPin, LOW);
digitalWrite (masterLedPin, LOW);
Explanation:
The master reset works similarly to the individual coin reset, but resets all four coin types at once instead of just a single coin at a time. All changes are reported to the serial monitor, and all LED's are shut off.
Sum Function
Code:
sum = (quarters*0.25)+(nickels*0.05)+(pennies*0.01)+(dimes*0.1);
lcd.setCursor(0, 0);
lcd.print(sum);
Explanation:
The sum function takes the current number of each coin, stored as a variable within the Arduino, and multiplies it by the value of the coin. It then sums all the stored coins and prints them continuously to the LCD. Because this is placed in the loop, and as such repeats frequently, any change in the number of any coin is displayed immediately.
Project Functionality
Project Functionality Description:
Operation of the coin sorter is simple. Begin by placing any U.S. coin (i.e. a quarter, nickel, penny, or dime) along the top of the slanted track (#1 in the figure). As the coin falls through its corresponding slot (#2), it will fall past the appropriate IR sensor (#3) and trigger it. The individual coin's value will be added to the sorter's overall sum displayed on the LCD (#4). Coins will be collected in the bins located on the back of the machine. When the number of any coin stored reaches a preset value (ten coins in the case of this project), the LED for that coin and a master LED will light, and the device will no longer count coins of any type. At this time, one should remove the full tray's coins from the device and press the appropriate reset, subtracting the value of the removed coins and resuming counting. The master reset will reset the sorter's overall sum to zero if you’ve decided to remove all coins from the device.
Circuit Diagram
(For a much higher resolution image of the attached circuit diagram, download it).
It should be noted that each IR sensor uses a 100 ohm resistor, each LED uses a 1K ohm resistor, and each button uses a 10K ohm resistor. The 16x2 LCD is of the I2C type, requiring only four wires. The coin counter uses four, FC 51 infrared sensors. Power is supplied to the circuit via the Arduino's USB cable. This cable can be plugged into a computer or into a USB "brick" type power adapter that can be plugged directly into a wall outlet.
Ensuring Maximum Power, Voltage, and Current Are Not Exceeded
Description:
The Arduino Uno operates at 5 V. This is the voltage that is supplied to all components in the system. Each digital pin can supply or take in 40 mA of current. Two analog pins, A2 and A3, are being used as digital output pins and each can supply a maximum of 40 mA.
A single, 3-milimeter LED typically has a max current rating of 20 mA. Each LED has a 1000-ohm resistor. Using Ohm's Law, voltage divided by resistance equals current, or 5 V / 1000 ohm = 5 mA. This value is well within the limits of the digital pins and LED’s.
Each IR sensor has an internal resistance of 9.9K ohm between the VCC and OUT pins, and an internal resistance of 10K ohm between the VCC and GND (ground) pins. On each sensor, there is an additional 100 ohm resistor attached to the ground pin, bringing the total resistance between VCC and GND to 10.1K ohm. Without even looking at the IR sensor's own circuit, it can be deduced that the lowest resistance the sensor could have is if the 9.9K and 10.1K resistances were somehow connected in parallel. Summing the reciprocals of 9900 ohms and 10100 ohms and then taking the reciprocal of that sum yields an equivalent resistance of approximately 5K ohm. Using Ohm's Law, 5 V / 5000 ohm = 1 mA. Again, this value is well within parameters of the digital pins, though the IR sensors get their power from a common rail coming from the Arduino's 5 V power pin.
The buttons themselves have very little resistance when they are pressed, but there are 10K ohm pull down resistors connected to the button's ground or outlet. There is another connection that branches off from each button's ground. It is a wire that goes to one of the digital pins from 3 through 7. These five pins are configured as digital inputs, though, and as such have a very high resistance--around 100 Megaohms. Therefore, only the 10K ohm resistor is really at play here. Dividing 5 V by 10000 ohms yields half a milliampere. The buttons get their power from the common rail connected to the 5 V power pin. Because the buttons all have a common ground and voltage source, and because the effect of the wires going to pins 3 through 7 is negligible, the buttons can be treated as a parallel circuit. The 0.5 mA current going through each of the 5 buttons can be added up to get the total current that would occur if all five buttons were depressed at once, this current being 2.5 mA. Again, this current is quite small--and only one button will be pressed at a time during normal operation.
The last component to take into account is the 16x2 LCD display. When supplied with 5 volts of power, a 16x2, I2C LCD consumes around 30 mA with the backlight on and display working (according to this source: https://protosupplies.com/product/lcd1602-16x2-i2... ). Therefore, a digital pin configured to output would be enough to power the VCC pin on the LCD. However, like the buttons, the LCD gets its power from the 5V power pin.
It is simple to find the total current that the Arduino would ever have to supply--assuming two LED's are lit, all sensors are on, the LCD is displaying with the backlight on, and all buttons are depressed (for whatever reason). Each LED gets its power from a digital output pin, and each LED consumes 5 mA. Two LED's = 10 mA. Each IR sensor consumes 1 mA, therefore four IR sensors consume 4 mA. Five buttons pressed all at once consumes 2.5 mA, and the LCD consumes 30 mA. Therefore, 10 mA + 4 mA + 2.5 mA + 30 mA = 46.5 mA = total current through Arduino. An Arduino Uno has a max current draw rating of 200 mA, so 46.5 is well within parameters.
State Machine Diagram
State 1 is the default state, the sum of the coins within the counter is continuously displayed and the device is ready to count any inserted coins. When a preset number of any coin is reached, in this case 10, the master LED lights up, signaling to the user that they should stop inserting coins. Additionally, the LED corresponding to the specific type of coin which has hit its limit is illuminated.
At this time, the coin sorter is now in State 2, and will no longer count any coins, continuing to display the sum until either the master reset button or the appropriate, individual reset button is pressed. The master reset should be used when all coins are removed at once, and the sum will return to zero and shuts off all LED's. Pressing the button for the specific type of coin which has become full, removes only the value of those coins from the sum and returns the sorter back to state 1, ready to count coins with no LED's lit.
Manufacturing and Assembly
Description:
The first four images show the progression of the circuit's physical implementation. This circuit was designed using Tinkercad. That program was very helpful, but certain features like FC-51 sensors and I2C LCD displays could not be simulated with it. The only way of knowing for sure if the circuit would work as designed was to build it. Before any soldering took place, the circuit was first built on a non-solderable breadboard. This allowed easy removal and adjustment of any components that weren't functioning properly. Building the circuit on a breadboard also provided insight for how the solderable breadboard, or perf board, should be laid out. Work on the perf board was done in stages. As components were removed from the breadboard and soldered to the perf board, the two boards were hooked up every now and then just to see if all the components still functioned together when connected to power. This method prevented a lot of troubleshooting headaches that might have been encountered if the circuit was built on the perf board in one go without any intermediate testing.
The fifth image shows printing a set of IR sensor holders.
The sixth image shows the coin counter's mechanical parts and electronic parts being put together for the first time.
The last image shows the perf board being re-wired. The connections that were replaced functioned properly but trying to wire the LED's and buttons to remote locations proved to be very messy. Soldering the buttons and LED's directly to the perf board gave a much cleaner design.
Conclusion and Takeaways
Improvements:
- Make a more sound physical structure
- Clean up the wiring
- Color code the wires
- Have a cleaner display face
Takeaways:
- Start earlier and rush the first couple of weeks
- Design and test before making something permanent
- Ask for advice earlier rather than later
- Don't build entire circuit and then attempt to add it to structure--build and wire circuit as structure comes together
Advice:
- Build a simple figure before attempting to 3D print
- Front load the work on designing and testing the circuit
- Communicate and be cordial with your partners