Hello world, a few weeks ago I decided to upgrade my homebrewing setup from bottling to kegging. In this process, I decided I wanted to make the dispenser automated. Also with a payment system. The intention of the payment system was not to earn money, but just as a challenge to myself. In the end, it turned out working very nicely.
At first I wanted to make the whole system mechanical, because I study mechanical engineering, and have no experience with programming. I spent some days trying to figure out how to make the system all mechanical, but I didn’t quite figure out how. Then one day I decided to take a more electrical approach.
As I currently have no subjects in programing and basically know nothing about any programming, I went to the library at my school and borrowed a book about programming Arduino, and a book about programing in C++. As I look back I think the book about C++ might have been an overkill. The same day I went to the online Arduino store and bought a starter kit. I also went to eBay and bought a lot of stuff that I might need. A list of what I used in this instructable will follow below.
So, if you have no experience with programing, and want to learn in the prosses, I highly encourage you to make something similar, and learn in the prosses. I spent about 2 months from start to finish making this. And I have learned a lot!. At first I found the programing very frustrating, and hard. But now I feel like I understand at least something. But still I find it hard. And the coding provided in this instructable is not top notch. But the code works, and that is the most important if you ask me.
This is how the machine works in a few steps.
There are two buttons on the machine to select different menus on the LCD.
When a menu that provide beer is selected the servo blocking the coin inlet is opned. This allows you to insert a coin. When the right coin is inserted and registered the servo will close preventing further adding of coins. At the same time this happens a signal is sent to the relay module, to open the solenoidvale. The valve will then stays open until a given amount of volume has passes through the flow sensor. The valve will also close if the valve stays open for more than 100sek. After this has happened the servo will open and all is ready for a new loop.
The values form the flow sensor is also stored in a different menu where you can see the total consumption. The same menu also provides information about the temperature of the fridge and how long the system has been running.
In the video, you will see the machine not pouring
beer, why is that? Sadly, I am all out of beer. I will upload a new video of the machine pouring beer when my next batch is ready. That will be in about 1 week.
I am entering this instructable in the circuits
challenge pleas vote if you liked it.:)
Step 1: Part List
Parts and tools
Not many tools are needed for this project. The only power tools I used was a drill, soldering iron and hot glue gun. You also need a knife and some drills.
An Arduino starter kit ( with some resistors, breadboard, LEDs, buttons, photoresistors, servo, LCD, speaker,etc.) https://store.arduino.cc/product/GKX00007
A larger LCD display: (I recommend buying a blue one, it looks cooler)
Flow sensor: ( I bought 3 different types, I found this one to be the best)
12-v dc powersupply:
Prototype shield: (not really needed)
Parts for beersystem:
Co2 tank with regulator.
++ tubing parts see pictures.
Wooden plate to mount faucet.
Wood to build the “bar”
Some screws, and mounting brackets.
Step 2: Building the Frame and Wall Mounting
I made the frame from a single piece of wood, with the dimensions given in the pdf. The dimensions will fit the components I used nicely. You might need to edit the coininlet to fit your coins. When mounting the frame to the wall I used L shaped brackets.
Notice my design does not have a drip tray, this is because I want to make an awesome driptray with my CNC machine. But my CNC machine is at home and I do not have access to it as of now. A drip tray is very useful; it drips quite a lot form the faucet. I will add the additional steps of making the driptray within a month.
Step 3: Electronics and Wiring of the System
Electronics and wiring of the system
In the pictures, you will see the wiringdiagram I used in my system. I recommend you using it rather than just looking at the pictures. I made the diagram using autodesk circuits which is a free web based program. the sketch i made helped a lot to keep track of all the wiring. Here is the link to my sketch.
Sadly, not all the components I used in my project where available in the Autodesk circuits library. That’s is why you will see some wires which leads to nothing. This applies to the Relay module, Solenoidvalve, Flowsensor,9v Powersupply, i2c LCD driver and temperature sensor
The flow sensor will be connecting to pin 2, as you can see by the three wires which leads to nothing. The relay connects to pin Nr 7. The relay also has a VCC input, and an external 5v powersupply. The LCD runs a i2c driver here you will need to connect PIN A4 to SDA and pin A5 to SCL, VCC to 5V+ and GND to GND. The 9 v battery is also replaced by a 12 v dc power supply.
The temperaturesenor I used where a DS18B20 not an TMP36 as shown in the scetch. The DS18B20 goes in the same spot as the TMP36 sensor. I don’t think connecting a TMP36 the way shown in the sketch will work.
To get power through the wall I used an Ethernet cables which I stripped down to reveal 7 different wires. I used this cable because I had it available. There is a 12 volt power supply powering the Arduino trough the GND and VIN pins. The relay is also powered by an external power supply here I used a 5v USB charger.
There are two additional steps about the flow
sensor and coin detection.
Step 4: Testing the Use of Photoresistor and Optointerrupter for Detecting Coins.
Testing the use of photoresistor and optointerrupter for detecting coins.
I made this simple setup to see if the photo resistor provided with the Arduino start-up kit could detect coins. Notice the LED is constantly emitting light.
According to the Arduino webpage the Arduino analog input can read as much as 10 000 values a second. Witch is accurate enough for the detection of a falling coin. I also tested this by blocking the light from the LED for a very short amount of time, to detect changes in analogRead value. See images.
In conclusion, the photo resistor provided with the Arduino starter kit can be used to detect coins. But keep in mind the photoresistor will be affected by light contamination. Therefore it can give a slightly contaminated signal. But it is not a problem if you isolate the system, or I think you could just use a very bright LED?.
I also did the same setup with a optointerrupter, basically the same thing. And it turned out to working even better. The signal form the optointerrupter was a lot cleaner. I think this is because it used IR light.
But in the I ended up using a photoresistor instead of a optointerrupter. Not because it was better, but because I accidentaly manage to burn out the IR LED.
Step 5: Coin Detection.
I wanted to make the coin detection device as simple and reliable as possible. to simplify I targeted only making the device detect one type of coin, but the detection device I ended up making could quite easily be modified to detect all kinds of coins.
My initial thought was to first sort the coins then, make the coins fall onto some sort off pushbutton, to make a digital signal to the Arduino. Sorting the coins turned out to be quite simple just by making the coins roll down an incline, with a slight tilt to make the coins always lean to one side. This side had rectangular hole(s) slightly smaller than the diameter of the coin itself. This way only the coins with a smaller diameter than the hole will fall through, by this principle you could quite easily sort many types of coins given that they have different diameters.
After sorting the coins needs to be registered as an input to the Arduino. I tried several methods to detect the coins, firstly using a limit switch. I placed the limit switch after the coins had been sorted to make the coin fall on top of the switch. This did not work quit as well as anticipated, mostly because the switched was too hard to press, thereby the falling coins did not generate enough pressure to operate the switch, managed to make this work 10 out of 11 times, with was not quite good enough.
I then tried using the fact that coins conduct electricity to my advantage. I mounted two wires where the sorted coin wold fall, thereby making the coin complete the circuit. It worked ok, but the signal I ended up getting to the arduino became quite distorted and not reliable enough. Therefore I discarded this method as well.
After taking an elevator with an optical sensor in front of the doors to detect hindrances, I though this wold work nicely. And it did!. I mounted a led constantly directing a light beam onto a photo resistor. This way an interruption of the light beam cold easily be detected by the Arduino. I did this and it worked. Using the serial monitor of the Arduino I could see the change in value when there being coin was obstructing the light beam. It worked so well that I ended up looking deeper into the use of light interruption as a button. I found that optointerupters was the way to go.
This way I came up with a completely different solution to the problem of detecting the right type of coins. I made a device, see drawing. As the coins enter they are forced down a slope which ends up in a curve. The slope functions to make the coins roll and avoid bouncing, as the coins enter the curve at the end of the slope, they are forced down due to the increase I normal force generated by the cure. Therefore, the optointerupter is placed just at the end of the curve. In my case I only coins with large enough diameter will be detected. With more than one optointerupters it wold be possible to detect different coins based on their diameter, just by placing more of them in the curvy part. But the coding in Arduino wold bee a bit more complicated.
Optointerupters are used in many types of printers and are quite accurate. I experienced with them and noticed that I could detect coin with an accuracy off less than one millimetre.
Step 6: The Code.
Here is the code I wrote. I think the code is a bit weird, but it works. The code I am posting below is a bit simplified. It does not provide the random Quote function nor the “lottery” function as seen in the video. The code I wrote for this ended up being 600 lines long witch I thought was a bit of an overkill.
The implantation of the LCD and buttons works in the way, that each time you push a button you increase or decrease a value of an integer. I then used IFsentences to display different text on the LCD, according to the value of the integer.
Her is basically how the code works, when you select the “coin for beer function” .
1. (what you see when you look at the display) LCD displays useful information. Example ” welcome to this awsome beermachine" “one coin= 0,5l”) ”add coin”.
2. (you add a coin) the coin passes through the system and interrupts the light beam form the optointerupter. The interruption of the light beam is registered by a decreasing value form the photointerupter sensor. The value goes from being 400 to becoming less than 360.
3. (servo close) the servo is activated blocking the coin inlet preventing further adding of coins.
4. (solenoid valve is opened) Also when the value is less than 360 a ON signal is sent to the relay module. This opens the solenoid valve, until an OFF signal is sent to the relay module.
5. (flow sensor measures volume) The flow sensor starts monitoring how much liquid passes through it. When the value monitored by the flow sensor has reached a given amount an OFF signal is sent to the Relay module.
6. (timeout function) If a given amount of time is not reached within a certain amount of time an OFF signal is sent to the relay module
7. (servo open) after an OFF signal has been sent to the Relay, the servo is activated opening the coin inlet.
8. (repeat) this is the basic code.
The final code includes a menu system which can displays several different functions.
· Type of beer in the keg, price, VOL etc.++
· Temperature in the refrigerator
· Total amount of liquid passed through the system++
· A lottery function where you can get twice as much beer or NO beer at all! Funny sounds and light are also added to make it more interesting¨
· Some useless funny stuff that has nothing to do with the dispenser at all ( I made a function that displays a random quotes)
Step 7: Fluid Supply
The beer is stored and carbonated in a 19L keg. The system is pressurised by a co2 tank, and has an operating pressure of about 1 bar. The beer runs from the beer keg to a solenoid then through a flow sensor. At the end of the beeline a faucet is located. This way beer is only allowed to run through the system when bout the solenoidvalve and the facet. I did it this way to prevent water damage and to easily bypass the solenoidvalve to make the system run without payment system.
The keg can be filled up with almost anything that flows.
Later I plan on adding more than one faucet so I can have more than one beer types. I am also thinking about adding more solenoidvalves so I can run more than one type of beer trough the same faucet.
Step 8: Solenoid Valve and Flowsensor. + Calibrating
Solenoidvalve and flowsensor
The 12v solenoidvalve is connected to the beer line right after the beer comes out of the keg. The flowsensor is connected about 5 cm after the solenoid. I did it this way because the solenoid valve has a small filter right in front of the inlet.
I purchased two different flowsensors from eBay. One with a 3mm inlet/outlet, and one with a ½ inch inlet/outlet. My thoughts where that the larger flowsensor wold be better suited, mainly because it wold not be clogged up as easily. But the initial problem was not the clogging up; it was the accuracy of the sensor. In my case it turned out that the smaller sensor had much better accuracy.
One other problem with the large flowsensor accrued when dealing with low flowrates. It turned out that the impeller in the sensor wold not turn at all. When the flow rates where too low. This was not as big of a problem with the smaller one.
Calibrating the flowsensor: I used the serial monitor function in the Arduino sketch to calibrate the flowsensor. I poured 10dl of liquid out of the facet and then wrote down the number. I then divided the value by 10 to get amount of “values” per DL. After doing this about three times I ended up with a constant of 400 sensor values per DL. You will find this value used in my code.
Step 9: That Is All.
That is all for now. Hope you liked It.
I will be adding a more revised code, to make it more understandable in a few weeks. I have exams coming up in just a few days so I have no time to rewrite it now.
Again, hope you liked it and pleas vote.! :) stay tuned for more!