Introduction: IOT Beverage Machine
Each time we buy a bottle of water or cold-drink, we are paying for the contents as well as packaging of the contents. So the idea is to create self vending water or cold-drink machines that are connected with mobile apps using IOT so we can fill our own bottles and save on costs. As well as we are also saving environment by reuse of the bottles and also saving the costs of recycling of plastic bottles.
So you have to launch app which can connect to machine and get the beverage as required. A payment gateway is not added yet, but you can add that feature also.
Step 1: Collect All Components
Collect all required components:
- Raspberry Pi 3
- SD card ( Class 10 )
- Power Adapter
- Submersible Motor
- Water Flow Sensor Ysf-201
- Relay Board with optocouplers
You will need a USB power adapter (Your android phone charger) and a memory card with minimum size from 8gb. Memory card should be class 10 so it will have high read and write speed. To see the output of Pi we have to connect a HDMI monitor. If you do not have a HDMI monitor then a HDMI to VGA converter is also required.
Step 2: Connecting Raspberry Pi to Relay and Motor
Connect main power to motor with relay in between so that motor can be controlled using relay board. Raspberry pi will provide 5V power to relay board and one GPIO pin is connected to signal pin IN2 of relay board. Here we have used 2 channel relay board although you can use a 1-channel board
Step 3: Connecting Raspberry Pi to Sensor
Water flow sensor operation on 5v and signal pulse from sensor also gives 5v output. So we can't connect sensor directly with raspberry pi and we have to use a voltage divider circuit to reduce voltage to 3.3v. R1 and R2 is 10k and 22k respectively. For additional safety it is recommended to connect a 330E resistor for safety of Pi board.
Step 4: Setup Your Pi Board
You will need to install Raspbian on Raspberry Pi running which is customised version of linux. We need to perform fresh installation on SD card. Download NOOBS software from www.raspberrypi.org and go to the DOWNLOADS section where we have download noobs software.
To install Raspbian, you're going to need a computer. Depending on the operating system you are using, the installation process will be slightly different. You will need to Install SD card Formatter in your PC then insert memory card in Computer and format it using Formatter tool.
Extract the NOOBS folder and copy all the files from this folder to the memory card.
Once the files have been copied in SD card, then insert the micro SD Card into your Raspberry Pi and power on the Pi Board. Follow the simple click-install steps. Pi will reboot after installation.
Step 5: Update Raspbian OS
- After installation the system will boot raspbian.
- Then connect raspberry pi to internet by using Network Icon in top bar
- Enter your password and raspberry pi will be connected to internet.
Now we have to update Raspbian OS. Open Terminal and run following commands.
sudo apt-get update
sudo apt-get upgrade
Step 6: Install Required Libraries
Our program needs Python which is preinstalled. In python we will use RPi.GPIO library to get data in and out from pins. To communicate with internet we have to use Pyrebase. but we have to install Pyrebase using following commands:
pip install pyrebase
Pyrebase library is used to communicate with google Firebase database. You can read more about pyrebase documentation here
Step 7: Signup for Google Firebase
To connect raspberry pi with cloud based database, we need to sign up for https://firebase.google.com with your google account. Create new project and generate web key and android or IOS app key in firebase console.
These keys will be used in mobile app and raspberry pi for accessing cloud based database.
Step 8: Run Python Code to Test App
Run following code on raspberry pi using python command in shell. Before executing this program we have to replace the config section in this program. You can get the configuration from the previous step in google console
Now you can test the program with connectivity to android app. Before that we also
want this program to run automatically and android app also need to be installed.
Step 9: Auto Run Python Program
We have to execute the change the auto run file present in directory
sudo nano ~/.config/lxsession/LXDE-pi/autostart
In this file write “sudo python program1.py”
save and exit this file using Ctrl+X
Step 10: Run Android App to Control Hardware
Use following git repository to clone the android app. Replace google-service.json file in the app folder from firebase console.
Compile and run app using android studio. Then you are ready to fetch water or any other beverage from machine and have fun.
Link for the app source code is here
Participated in the
IoT Builders Contest