IoT Automatic Water Dispenser With RFID

by final5912 in Circuits > Sensors

7907 Views, 5 Favorites, 0 Comments

IoT Automatic Water Dispenser With RFID

262566.jpg

Creator of this Article:

Gilbert - BINUS Student majoring in Computer Engineering

Vincent Cunardy - BINUS Student majoring in Computer Engineering

As we know water is one of the essential elements that a living being need to keep healthy. Human indeed needs to consume a minimum of 4L water a day to stay dehydrated and healthy. In this pandemic, we are asked to do social distancing that means we need to make an effort to minimize direct physical interaction. therefore in order to able to consume water even doing social-distancing. The water Dispenser project is being made.

This is a project which was designed to apply an Internet of thing (IoT) system with Arduino and ESP(as Wifi) as the base, although there are many projects based on Arduino and ESP. In order to apply the IoT system this project should be a more useful project that will be able to help and maximize the productivity of the user.

Supplies

Main Components

  • One ESP8266 (WiFi Module)
  • One relay 5V
  • Two ultrasonic HC-SR04
  • One Water Pump 12V
  • Some RFID MRFC522 and Mifare Card
  • One LCD with I2C 1602 16x2
  • One Arduino Uno
  • Two Adapter 12 V
  • One PSU Breadboard
  • One jack DC
  • One Breadboard
  • Few Jumper wires
  • a water pipe
  • a water tank

Optional Components (Casing)

  • Some glue and adhesive tape
  • a cardbox / acrylic case
  • a scissors
  • handrill

Preparation

In this project, we prepare the supplies listed above for the Hardware preparation In order to build an IoT water dispenser system. For the software system as we using Arduino IDE which is a cross-platform application that is written in C and C++ programming language. The software provides the feature to write and upload the code to the microcontroller and easier to provide the library that we will be using.

You also need to prepare a Blynk Account to help you to follow the next step of this project. The project using Blynk to understand the application of IoT Hardware. This software is easy to access and it is an open-source application that will be helpful in building the software application for the hardware.

Here is the link to Install Blynk
Android

IOS

How to Use Blynk

FBN8IGDKJH5CXR3.jpg
FJR26Q9KJH5CXR4.jpg
F57T8KPKJH5CXR5.jpg
F90MCUSKJH5CXR6.jpg
FOOETO3KJH5CXR7.jpg
265267.jpg
265268.jpg

After installing the app, create your account and log in to start using the app.

Create a new project, and name your project, choose the device as in our case we choose(NodeMCU/ESp8266) with the connection type is WiFi, then there will be an email send by Blynk it contains the authorization token.

Using the widget box choose the widget feature that will be used. Position the widget item in the place exactly as the UI Frame above.

The widget uses is Gauge, Vertical V, notification, email, and 5 buttons.

Block Diagram and Flow Chart

blockdiagramTR (8).png
blockdiagramTR (9).png
FlowChartTR (5).png
FlowChartTR (6).png
FlowChartTR (8).png

In this step consist figure of the Block diagram and Flow chart of the system in this project.
In the Block diagram, the PSU breadboard that connects to ESP8266 and Arduino Uno is the same voltage supplier. The PSU Breadboard is an Input voltage to the controller.

In the ESP8266 Block diagram both of the Ultrasonic sensor is defined as an Input. Then the input data is processed in the controller(ESP8266). The output will be the 5V relay that is connected to Water Pump.

In the Arduino Uno Block diagram, MRFC522 RFID is the system input. The input then is processed by the controller(Arduino Uno). Then the controller will send the output to LCD to display either the input is successful or failed.

How to Install Library for Arduino IDE

FBFCDC8KJIKP330.jpg
messageImage_1609917332541.jpg
messageImage_1609917740065.jpg

In the Arduino IDE

Ctrl +Comma or Go to File => Preferences to Paste (http://arduino.esp8266.com/stable/package_esp8266com_index.json) in Additional Board Manager URLs

Go to Tools => Board => Board Manager => Search "ESP8266" => Install "esp8266" by ESP8266 Community.

Ctrl + Shift + I or Go to Sketch => Include Library => Manage Libraries

Search "Blynk" => Install "Blynk" by Volodymyr Shymanskyy

Search "Liquid Crystal I2C" => Install "LiquidCrystal I2C" by Frank de Brabander.

Search "MRFC522" => Install "MRFC522" by Github Community.

Wiring and Code ESP8266

messageImage_1609829174338.jpg

Firstly, wire the component as the schematic diagram as above. The ESP will work as the connection to the WiFi Module. In this system, the data will be sent to the application is the water level of the dispenser.

In the relay, we connected the motor to NO of the relay so that when the relay is activated the motor will start working and pumping the water. For the pipe use a better pipe that usable for drinking and connecting it to the pump so the system could pump out the water.

After connecting the pin of the component to the circuit. The next step will be including the library in the Arduino IDE. Include BLYNK and ESP8266WiFi library to Arduino IDE software. Then use the code below to test the ESP WIFI is working fine as needed.

In the code below is the setup configuration to use the hardware and Blynk software. In order to use Blynk, we use Blynk.begin() in the setup function and give the essential parameter such as Blynk authentication, SSID and pass to access the Blynk project.

#define trigger1 D1
#define echo1 D2
#define Relay D3
#define trigger2 D4 
#define echo2 D5 

#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

//Blynk Application Setup
char auth[] = "Your AUTH";
char ssid[] = "Your SSID";
char pass[] = "Your Pass";

float time1 = 0, distance1 =0, time2 = 0, distance2 = 0, tinggi2 = 0;

void setup()
{
 Serial.begin(9600);
 Blynk.begin(auth, ssid, pass);
 pinMode(trigger1,OUTPUT);
 pinMode(echo1,INPUT);
 pinMode(Relay,OUTPUT);
 pinMode(trigger2, OUTPUT);
 pinMode(echo2,INPUT);
}

In the code below is the code for the Ultrasonic sensor to measure the distance of the object detected to the sensor. The ultrasonic sensor will send a vibration to echo and catch back it through the trigger pin. Thereby applying the method of distance = (speed * time)/2 we will be able to get the actual distance of the object to sensor.

void measure_distance()
{
 digitalWrite(trigger1,HIGH);
 delayMicroseconds(10);
 digitalWrite(trigger1,LOW);
 delayMicroseconds(2);
 time1 = pulseIn(echo1,HIGH);
 distance1 = (time1 / 2) / 29.1;
}

void measure_distance2()
{
 digitalWrite(trigger2,HIGH);
 delayMicroseconds(10);
 digitalWrite(trigger2,LOW);
 delayMicroseconds(2);
 time2 = pulseIn(echo2,HIGH);
 distance2 = (time2 / 2) / 29.1;
 tinggi2 = 25 - distance2;
}

In this code below is the main program the water dispenser. the main program will update the system and keep track of the water level. the system will update to the Blynk software the water level by using the ultrasonic sensor. Blynk.virtualWrite will update the data to Blynk software of the water level. When the water level is low by using Blynk.notify() and Blynk.email() the software will send and notify email to the user to refill the water tank.

Blynk.run() is essential in the main function for it is used to connect the microcontroller to the Blynk application

void loop()
{
 measure_distance();
 measure_distance2();
 Serial.print("Hasil Sensor dispenser: ");
 Serial.print(distance1);
 Serial.println("cm");
 Serial.print("Hasil Sensor iot: ");
 Serial.print(distance2);
 Serial.println("cm");
 if(distance1 < 15)
 {
   digitalWrite(Relay,LOW);
 }
 else
 {
   digitalWrite(Relay,HIGH);
 }
 delay(500);
 
 if(distance2 > 0 && distance2 < 5)
 {
   Blynk.virtualWrite(V4, 255);
   Blynk.virtualWrite(V3, 255);
   Blynk.virtualWrite(V2, 255);
   Blynk.virtualWrite(V1, 255);
   Blynk.virtualWrite(V0, 255);
 }
 
 else if(distance2 > 5 && distance2 < 10)
 {
   Blynk.virtualWrite(V4, 0);
   Blynk.virtualWrite(V3, 255);
   Blynk.virtualWrite(V2, 255);
   Blynk.virtualWrite(V1, 255);
   Blynk.virtualWrite(V0, 255);
 }

 else if(distance2 > 10 && distance2 < 15)
 {
   Blynk.virtualWrite(V4, 0);
   Blynk.virtualWrite(V3, 0);
   Blynk.virtualWrite(V2, 255);
   Blynk.virtualWrite(V1, 255);
   Blynk.virtualWrite(V0, 255);
 }
 
 else if(distance2 > 15 && distance2 < 20)
 {
   Blynk.virtualWrite(V4, 0);
   Blynk.virtualWrite(V3, 0);
   Blynk.virtualWrite(V2, 0);
   Blynk.virtualWrite(V1, 255);
   Blynk.virtualWrite(V0, 255);
 }
 
 else
 {
   Blynk.virtualWrite(V4, 0);
   Blynk.virtualWrite(V3, 0);
   Blynk.virtualWrite(V2, 0);
   Blynk.virtualWrite(V1, 0);
   Blynk.virtualWrite(V0, 255); 
   Blynk.notify("Water tank need to be refill");
   Blynk.email("gilbert926@yahoo.co.id", "Water Tank Alert", "Water tank need to be refill");   
 }
 
 Blynk.virtualWrite(V5, tinggi2);
 Blynk.virtualWrite(V6, distance2);
 delay(200);
 Blynk.run();
}

Wiring and Code Arduino Uno

messageImage_1609829132407.jpg

Next, we set up another microcontroller that will be connected to RFID and LCD 16x2. By using the schematic above for the wiring configuration.

Pin 13 to 9 will be used for the RFID. FOR the LCD we will use I2C to connect to the microcontroller. LCD SDA and SCL pin is connected to the Analog pin in the Arduino SDA->A4 and SCL->A5. Because the voltage uses for RFID and LCD are different. we connected 3.3V to RFID and 5V to LCD.

In the code includes library SPI and Wire for the communication protocol used by RFID, MRFC522 library is also included because the component that we use as RFID reader is MRFC522, and then we include LiquidCrystal_I2C library because the LCD we use are solder with I2C module, by using I2C LCD module we will reduce the usage of the pin that is being used for the Arduino. In this project, we mainly use the I2C communication protocol to reduce the cost of wiring the components.

In order to use the SPI communication and LCD & RFID. In the setup function, it is needed to add
SPI.begin();

LCD.begin();

mfrc522.PCD_Init();

#include <SPI.h>
#include <MFRC522.h>
#include <LiquidCrystal_I2C.h>
#include <Wire.h>

#define SS_PIN 10 // SDA pin
#define RST_PIN 9

MFRC522 mfrc522(SS_PIN, RST_PIN);   // Create MFRC522 instance.
LiquidCrystal_I2C lcd(0x27, 16, 2);
 
void setup() 
{
  Serial.begin(9600);   // Initiate a serial communication
  SPI.begin();      // Initiate  SPI bus
  lcd.init();
  lcd.backlight();
  mfrc522.PCD_Init();   // Initiate MFRC522
  Serial.println("Put your card to the reader...");
}

in this code below is the main program for the Arduino microcontroller. The RFID will scan the tag/card that has been authorized and shown the user of the card by LCD.

PICC_IsNewCardPresent() this function is used to check either there is a tag/card that is currently in the range of the RFID sensor.

PICC_ReadCardSerial() this function is used to check either the card data could be read or not.

The card/ tag that is being read by the RFID sensor will use the data UID to check either it is Authorize or not. If the card or tag is not authorized it will return an error message through LCD.

void loop() 
{
  // Look for new cards
  if ( ! mfrc522.PICC_IsNewCardPresent()) 
  {
    return;
  }
  // Select one of the cards
  if ( ! mfrc522.PICC_ReadCardSerial()) 
  {
    return;
  }
  //Show UID on serial monitor
  Serial.print("UID tag :");
  String content= "";
  byte letter;
  for (byte i = 0; i < mfrc522.uid.size; i++) 
  {
     Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
     Serial.print(mfrc522.uid.uidByte[i], HEX);
     content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
     content.concat(String(mfrc522.uid.uidByte[i], HEX));
  }
  Serial.print("\n Message : ");
  content.toUpperCase();
  if (content.substring(1) == "59 F7 14 E8") //change here the UID of the card/cards that you want to give access
  {
     lcd.setCursor(0,0);
     lcd.print("Access Authorized");
     lcd.setCursor(0,1);
     lcd.print("Hello Vincent");
     delay(100);
  }
  else if (content.substring(1) == "D5 97 A7 23")
  {
     lcd.setCursor(0,0);
     lcd.print("Access Authorized");
     lcd.setCursor(0,1);
     lcd.print("Hello Gilbert");
     delay(100);
  }
  else   {
     lcd.clear();
     lcd.setCursor(0,0);
     lcd.print("Error");
     lcd.setCursor(0,1);
     lcd.print("Access Denied");
     delay(100);
  }
} 

Setup Hardware

To set up the whole system the voltage that will be using is an AC to DC voltage. The system of the microcontroller will be connected to 12V Adapter which is connected with a jack DC. Then connecting the V+ and V- from the adapter to the PSU breadboard, then from the PSU breadboard to Vin of ESP and Arduino Microcontroller to supply the system with a voltage to run the system. This PSU breadboard will convert the 12V voltage to either 3.3V or 5V according to the voltage needed by the component.

Next is placing the ultrasonic Sensor. One at the above the water tank and the other placed under the pipe so it could detect if there are any cup detected in the range.

Then place the RFID in the front so it could use to scan the card/tag that is currently authorized. Also, make sure to put the LCD so it is visible to know either the card that is used to scan is either register or not.

Demonstration

Problem Encounter and Data Gathering

messageImage_1610095749471.jpg
messageImage_1610095766103.jpg

The optimal Volume water of the tank for the dispenser to pump the water

The optimal distance of the card/tag and RFID reader to detect

Summary

In conclusion, this project could be build using microcontroller ESP8266 as the hardware and Blynk as software integration to build the application. As the additional Feature, we use an Arduino Uno microcontroller that is connected to the LCD and RFID.

For suggestion, even though using ESP8266 microcontroller could work functionally. It is better to have a microcontroller that has more available pins so that it is not needed to use two microcontrollers as in the project above. Another suggestion is to make a better casing such as using 3D print, as a card box is not a good option for casing a project that involved liquid.