Wednesday, November 7, 2012

Project November: Lego Automatic Coin Counter

Overview

This is a contraption that I built to automatically sort and count coins. I was inspired by the coin-counting machines that the banks have placed together with the ATMs, and thought of it as a marble-machine with a practical purpose, and hence decided to build one. Here it is, marvelously huge and freakin' time-consuming to build:




Coins are dumped into the hopper located at the left of the contraption and the machine will sort and count them without any human intervention, and at the end of the process the coins would fall into output bins at the bottom, which could be emptied by pushing down on a lever, allowing quick access to the collected coins.

Processing of data is done by the NXT mounted in the center of the machine. Input is provided by four light sensors, each corresponding to a specific type of coin. The NXT counts the number of each type of coin, displays the data gathered on its screen, and at the request of the user, calculates the total value of the coins fed into the machine.

From here on I would proceed to describe the working principles of this machine.

Mechanics 

The machine is made up of 4 main modules:

1) Hopper
2) Y-Stack Elimination
3) Conveyor
4) Sorting Module

Coins to be counted are dumped into the hopper at the top of the machine. The hopper is slanted towards the right, hence the coins would slide down the hopper due to gravity and approach the exit. Due to the funnel shape of the hopper the randomly-arranged coins would converge into a single row before exiting the hopper. Hence, piling up of coins in the z-axis is solved by utilizing gravity and the shape of the hopper.





Now we have to solve the piling of coins in the y-axis. This could be done easily if we create a barrier higher than the height of the tallest coin, which in this case is the 50 cents coin, but shorter than twice the height of the shortest coin, which in this case is the 10 cents coin, and mouting the barrier at the end of the funnel-shaped hopper such that piled-up coins would be blocked while the coins on the first layer below would be allowed through, effectively forcing the mess of coins into one single layer. However, the difference in the above mentioned heights is extremely small, on the order of fractions of millimeters, and as such, I am rather worried about the reliability of such a design. Lego is basically colored plastic molded into user-friendly shapes, hence their structural integrity and strength could represent a great problem. Vibrations due to collisions between the coins and the height barrier could potentially loosen connections and destroy the intricately-designed height barrier as the barrier deviates from the required height. Through experimentation I have proved my hypothesis correct and I concluded that the reliability of such a system is unacceptable.

I overcame this problem by making a lucky and important observation - the height of my ruler is a tiny bit smaller than the height of a 10 cents coin. Which means, if the ruler is placed in the path of the incoming stacked-up coins, then only the bottom layer would be blocked, while the coins on top would continue sliding down, unaffected at all. We're basically reversing the concept here; instead of blocking the coins on top, we're blocking the coins below. But then the treasure we're looking for is the guaranteed one-layer coins below, so instead of blocking them altogether, we slant the ruler, such that they're deflected, not blocked.

This is the mechanism you see in the pictures above. The slanted ruler ensures that the coins in the bottom layer gets deflected and proceeds onto the path leading to the sorting module, while the coins stack up on top goes straight and eventually fall into a chute leading to a conveyor belt, which would transport the coins back up into the hopper.




The conveyor is built with Lego tank tracks, with pins plugged into the track units at regular intervals to catch the coins prevent them from simply sliding down against the moving belt. To prevent the coins from bouncing and falling past these pins, and ending up on the floor, a barrier is built at the bottom end of the belt. This barrier can move up and down, hence when the pins pass underneath it it would move up and allow the coins to be caught by the pins, else, it would stay down and maintain contact with the moving belt, preventing the coins from sliding down past the bottom end of the belt.

At the top end of the belt, a slide is mounted such that coins would be directed into the hopper where the process begins again. The belt is driven by a PF XL-Motor, toggled on/off by an NXT motor.

In the meantime, coins that take the path leading to the sorting module falls into a chute where they are rotated along the y-axis and end up lying slanted rather than horizontally. Now the coins roll down rather than slide down.





The flip-like device, featured in the photo on the right, ensures that the originally horizontally-oriented coins gets pressed onto the platform behind so that the coins end up oriented correctly, slanted and parallel to the sorting mechanism.

The sorting mechanism consists of two main rails, the difference in height between the two rails increasing gradually from left to right (direction is reversed in the two photos above due to perspective). Both rails are slanted along the y-axis. The L-shaped bottom rail supports the majority of the coins' weight, while at the same time the protruding portion acts as a wall, and together with the top rail, prevents the coins from falling. Contact must be maintained with both rails for a coin to continue rolling down the rails.

Due to the difference in height between the rails, the smallest coin (10 cents) would lose contact with the top rail earlier as they roll down, hence falling from the rails. The largest coin (50 cents) would maintain contact with the top rail for the longest, and would fall near the end of the mechanism. Hence coins are sorted according to diameter as they roll along the rails.

Friction is a problem here, because the coins rub against both rails on their journey down. Hence I used some baby powder for lubrication, which worked out quite well. I suppose the tiny granules of powder acted as small ball bearings. Oil cannot be used as the coins would get oily and it would be incredibly disgusting to use the machine. However, the powder is prone is getting blown or pushed around, hence frequent replacement is necessary.





The coins, now sorted by size, fall down chutes leading to light sensors, each of which detects the increased amount of reflected light as the coins pass above them. The flips you see hanging down on top of the sensors are there to ensure that the coins fall directly above the sensors such that accuracy is maintained.  The coins then fall into chutes that guide them into the collection bins below. With a press of a lever the bins could be tilted and the contents emptied.

Programming

At first glance the programming seems straight forward enough. Basically we have to accomplish 3 things:

1) Start-up sequence: Calibrate all sensors and define all variables.
2) Main sequence: Activate conveyor belt and keep track of the number of coins.
3) End sequence: Calculate total value, deactivate conveyor, clear all variables.

NXT-G automatically defines all variables and resets all variables at the start and end of each program, hence making live easier. On the other hand, NXT-G has some limitations, which would cause some problems as you'll see later.

At the start of the program, the conveyor belt is toggled on by an NXT motor. That's the first block in the program.





Then comes the calibration of sensors. This is done sensor-by-sensor in series. The ambient light value is first read, then 10 is added to the value and stored as a variable. This is the set point to which the NXT would compare light values with during the main sequence. This process is repeated for each sensor.


Next is the formatting for the screen. A bunch of display blocks, each corresponding to a line on the NXT screen.




Originally the idea was to continuously loop the main sequence such that each sensor repeatedly compares the light value to the set point and adds one to the number of the coins, which is defined as a variable, if the light value is above the set point. This would require a sensor-toggled switch; if light value ≥ set point then add one to variable, else do nothing. However switches in NXT-G does not accept value inputs, hence I am unable to link the set point variable into the switch. The solution to this is simple. Since switches only accept in the form of logic, I first compare the light value sensed to the set point. If it is greater, then I define it as true, else it is false. Now I could link the logic into the switch. If the logic is true, then the NXT would access the variable for the number of coins of each type, add one to the variable, store the new value for the variable in its memory, convert the value to text, and display the text on its screen in the appropriate line. Then I loop everything. This occurs for each sensor, for a total of 4 loops in parallel. The ending condition for all the loops is the center orange button being pressed.

Once the orange button is pressed the NXT would exit the loop and proceed. The belt would be toggled off and the NXT would then calculate the total value of the coins. It's just basic math, except that the NXT-G software can't do floating point operations, only integer calculations, hence the final value is displayed in cents.

Result

In HD, but my camera wasn't entirely in focus so kindly bear with the slight blur.


Limitations and Possible Improvements

One limitation is that I only have space to display 4 digits for the final value, so if the value exceeds $99.99 the user would have to carry out the operation in batches. But I doubt my machine is reliable enough to count that many coins without errors.

Firstly the powder I'm using tend to get pushed down the tract by coins, hence resulting in the lack of lubrication in certain areas and sometimes causing a jam. Perhaps an alternative lubricant would solve the issue, but so far I do not have any ideas.

Secondly the chute leading to the conveyor occasionally get clogged up by coins. This is due to one of the pieces that I used to build the chute having a corner sticking out slightly, presenting itself as an obstacle for the coins. I could have rebuilt the chute using other parts, but the fundamental problem here is that Lego, being plastic, could be deformed easily and hence is not ideal for projects that require precision. Unfortunately I do not have any other robotics set available for use.

Thirdly some of the coins tend to get stuck in the sorting mechanism if they travel too fast. This is due to an excess of lubricant on the rails. Again, problem with the powder.

Much remain to be improved.

Building Process

I spent quite a lot of time on this project, and have taken some pictures along the time.












Friday, January 13, 2012

Project Mike: Marble Launcher

Project Date: Jan 2012

This is my all-new Lego gun that shoots marbles. It is built machine-gun style, with a quad-pod and vertical handles.

It accelerates the marbles using two wheels that are spun by 6 PF M-motors. A geartrain increases the rotation speed of the wheels to around 3000 rpm. Two battery packs mounted at the back to counterbalance the weight of the motors powers them. Because of the increase in rotation speed, torque is severely reduced. This means that the wheels need some time to recover and speed up after every shot. The original concept of "feed in the marbles and let the gun do the work" is made complicated by this. I devised a mechanism to feed in the marbles one-by-one at a controlled rate. This way, the marbles do not go in one immediately after another and potentially jam the gun. It's possible to solve this problem by either using more powerful motors (which I don't have) or by sacrificing projectile power by decreasing the rotation speed (which I don't want to).



The mechanism I used consists of three simple parts: a simple, tilted, funnel-like magazine, a vertical S-bend and a flipping switch to control marble feed rate. You can see the large magazine in the pictures at the top. Marbles are poured into this magazine and are funneled into a single row by the two angles beams. They roll down  the track in the picture at the left, drop down into a hole, and continue rolling. The purpose of this vertical S-bend will be explained later. The first marble will roll into a switch, made up of two peg connectors, which can be seen in the top left picture, and get stuck. This stops the marbles from rolling further. Once the trigger is pressed, a motor periodically flips this switch (mechanism explained later) and allows one marble to go through at a time. This marble then rolls down a ramp and into the wheels.

The flipping action of the switch is violent and will force the marbles behind to roll backwards, up the ramp. The purpose of the vertical S-bend is to limit the distance the marbles can roll backwards and to reflect them back towards the switch. If there were no S-bend, the fire rate of this gun would be severely reduced since the marbles would roll back, stop, and return to the switch every time the switch is flipped. The switch can be more clearly seen in the left picture below.



The mechanism I used to flip the switch can be seen in the picture at the right. It requires a seventh motor. I used a PF XL-Motor for this purpose. It spins an axle connected perpendicular to the rotation axis, which at the 10 o'clock position, will strike a Lego piece, tilting it anticlockwise. This Lego piece is connected to the switch. Since the motor spins at about 200 rpm, the switch flips about 200 times a minute, which translates to a firing speed of around 200 rpm.

The trigger is extremely primitive in this gun. To fire, the handle at the right is tilted forwards, triggering an electronic switch and activating the motor that flips the switch, enabling marbles to proceed to the launching wheels.

Having said so much about the gun, it's time for some description for the quadpod.


The front legs are tilted sideways, but to save time, I constructed the back legs straight. To increase the strength, I used dental floss to chain the legs together (visible in the left picture). Otherwise the legs would spread out under stress and break.

This gun is supposed to fire at 200rpm, but the actual value is at 250 to 300 rpm. Likely reason for this is that some marbles managed to escape from my switch.

And lastly a picture of me and my gun:



And the video from my YouTube channel (didn't want to upload on blogger since the quality is so bad here):