Project tutorial
Smartap Future of Faucets

Smartap Future of Faucets

An advanced faucet that can close if left open, can monitor the water usage, can control the water flow to manage water consumption at home.

  • 1,622 views
  • 1 comment
  • 9 respects

Components and supplies

Apps and online services

Ide web
Arduino IDE
Wiznet Configuration tool

About this project

Objective

Smartap is a lightweight project that aims at automating the faucet. Main objective was to control minimise the water consumption. Wiznet WIZ750SR is the platform that has been used in the project along with Arduino Uno. Main steps to be followed are

  • Configuring Wiznet WIZ750SR Serial to Ethernet module
  • Setting up Arduino UNO
  • Interfacing components
  • Finalising

Introduction

Usual taps I had at my house was old school. I wanted to add something extra to the existing components. Wiz750SR is a pretty good solution since it had easy RJ45 connector.

Features

  • Click controlled tap
  • Flow control with relative to duration tap was pressed
  • Control tap over network
  • Determine waterflow rate and water consumed
  • Set a threshold for the tap
  • Leak Detection

How to:

Configure Wiznet WIZ750SR

The WIZ750SR is an ethernet to Serial convertor IC based on the Wiz7500mcu (ARM Cortex M0). It has a 10Mhz internal oscillator and 128kb flash memory. Most importantly the WIZ750SR works on the 3.3V logic. You have to first read the documentation to get a clear picture of the Wiznet IC.

To configure the Serial to Ethernet convertor, we can use the provided Wiznet configuration tool. First insert the WIZ750SR in the evaluation kit or connect the IC directly over the UART pins to PC.

Download the Wiznet configuration tool from the link: https://github.com/Wiznet/WIZnet-S2E-Tool-GUI

Then run the main_gui.py on your system (You should have python installed).

  • On Windows machine, go to https://www.python.org/downloads/ and download latest version of python, then locate in cmd to the required directory and enter 'python main_GUI.py' and press enter.
  • On Linux machine, go to terminal, locate to the required directory and enter 'python main_GUI.py' and press enter. Python will be probably installed on the machine.

This page should appear.

Connect the Wiznet evaluation board and press search. Select the device that shows up.

You can easily set the requirements of the device in here. For my project I setup in the following format:

  • Operation mode: TCP server
  • Local IP:192.168.4.1
  • Local port: 80
  • Baud rate: 115200
  • Data bit: 8
  • Parity: None
  • Stop bit: 1
  • Flow control: none

After setting all the preferences, click the settings tab. It will update the changes made and notifies with a confirmation dialogue box.

SettingupArduino

For this project, I used an arduino as it was easily available and easily interfaced with other devices. Any other micro-controller can be used as long as it supports UART communication.

Arduino can be set up pretty fast. Connect Arduino to the PC with the provided USB-A to USB-B connector. Check if the device is detected.

Startup the Arduino IDE which can be downloaded from https://www.arduino.cc/en/Main/Software.

Download the code that I have attached with this page below. Paste the code in arduino ide code editor and press the compile button on the top left corner.

Open tools menu>Boards>Arduino/Genuino UNO.

Open tools menu>port>"Select the port where arduino is attached".

Once this is done, press the upload button next to compile button. The uploading should complete without any error. You will have the Arduino successfully setup.

Interfacing Components

WaterflowSensor

This sensor contains 3 wires- VCC, GND and Pulse. It has a small wheel with fins inside the casing. As one fin crosses the internal detector, a pulse is generated in the pulse pin. This is detected by the Arduino by assigning it as an hardware Interrupt pin. Refer the maincode.

  • Connect VCC to 5v supply
  • Connect GND to common ground
  • Since pulse is interrupt controlled, connect it to pin 2

Tapswitch

For the tap control, we set up a small circuit as below.

Take the pin from data out and connect it to pin 3 of Arduino. Pin 3 is the second hardware interrupt of arduino uno.

Servo

You have to connect the servo to the tap to control it. Since I had a servo with less torque, I manipulated the tap a bit to easily control it with less torque. All that is required is to align the centre of the servo to centre of the tap rotation.

You have to choose the tap and control device appropriately. You have a choice of geared motor and Servo here. Since I used a 90 degree tap, I could use a servo. Otherwise you can use a geared motor. But you will have to include the L293D motor driver IC and manipulate the code a bit (tapfunc()).

WIZ750SR

This is the most trickiest part of the project. The Wiznet IC is a 3.3v logic device whereas arduino is a 5v device. If you choose a 3.3v arduino nano, then you can skip to direct connection stage.

First you have to generate 3.3v from existing 5v. For that lot of regulator ICs are available. But I have used an AMS1117-3.3 voltage regulator. This comes mostly in a SOT package.

Wiring of the IC is given in the complete circuit. We will get a regulated 3.3v DC voltage from pin 2 of this IC.

Thats not it. The RX, TX pins of the WIZ750SR also works under the 3.3v logic. You can easily get a logic convertor IC from online. One such IC is the Sparkfun logic convertor.

Alternatively, you can use potential dividers for the purpose also. But be careful when using the voltage dividers as logic convertor - deisgn the resistors ratio according to the equation

Vout = (R1/(R1+R2))xVin

As mentioned above, connect the RXD of S2E chip to TX of Arduino and TXD of S2E chip to RX of Arduino.

After this you will have successfully completed the interfacing and you must look messed up with wires.

The work is almost done.

Finalising

After all the connections are complete, turn the power On. You should see the Servo resetting to 0 position and all the power leds light up.

Open a browser on the connected network. Type in the ip address you had assigned to the WIZNET module. In this case - '192.168.4.1' and press enter.

You should be welcomed by a website looking like this:

You can remotely control the tap from this network - Turn it on or OFF.

If this part is complete, You have successfully completed the project. You can change the consumption threshold from the network webpage. Enter the data inside the text field and press the submit button.

Scope for development

Data from weather API can be downloaded. This data can be used to control the duration for which tap is turned on. The data can be uploaded to IOT services like Thingspeak or Ubidots and frequency of use of tap can be determined. Android app can be developed to use the Smartap.

Happy engineering!

Code

Complete Arduino codeArduino
Upload the code directly to arduino
#include<Servo.h>
#include <avr/pgmspace.h>

#define onswitch 3
#define flowinterrupt 0
#define flowsensor 2

Servo tapservo;

int tapcontrol,duration;
volatile byte tapbutton=LOW;

float calibration=4.5;
volatile byte flowpulse;  //Pulse from flowmeter
float flowRate;
unsigned int flowMilliLitres;
unsigned long totalMilliLitres,threshold;

unsigned long oldTime;

const char PROGMEM webpage1[]="<html>"
"<head>"
" <h2>SMARTAP DATA</h2>"
"  <style>"
"  table, td "
"  {    border: 1px solid black;}"
"  table"
"  {width:100%;}"
"  button"
"  {width: 100%;}"
"  </style>"
"</head>"
"<body>"
"<form action=\"changedata\" method=\"get\" enctype=\"multipart/form-data\" name=\"threshold\" id=\"threshold\" target=\"_self\">"
"<table>"
"  <tr>"
"    <th>Tap state</th>"
"    <td>";
const char PROGMEM webpage2[]="<select>"
"    <option value=\"ON\">ON</option>"
"    <option value=\"OFF\">OFF</option>"
"    </select> "
"  </td>   "
"  </tr>"
"  <tr>"
"    <th>Consumption rate</th>"
"    <td>";
const char PROGMEM webpage3[]="</td>"
"    </tr>"
"    <tr>"
"    <th>Total consumption</th>"
"    <td>";
const char PROGMEM webpage4[]="</td>"
" </tr>"
"    <tr>"
"    <th>Consumption threshold</th>"
"    <td><input type=\"text\" name=\"consthresh\" value='";
const char PROGMEM webpage5[]="' size=\"4\" maxlength=\"3\" />&nbsp;</td></td>"
"    </tr>"
"    <tr>"
"    <th></th>"
"      <td><button type=\"submit\" form=\"threshold\" value=\"Save\">Submit</button></td>"
"    </tr>"
"</table>"
"</form>"
"</body>"
"</html>";

void setup()
{
  Serial.begin(115200);
  duration=5000;
  tapcontrol=250;
  tapbutton=false;
  pinMode(onswitch, INPUT_PULLUP);
  tapservo.attach(9);
  threshold=500;    //500ml threshold

  //waterflow init
  pinMode(flowsensor, INPUT);   //Initialise flow sensor
  digitalWrite(flowsensor, HIGH);
  flowpulse        = 0;
  flowRate          = 0.0;
  flowMilliLitres   = 0;
  totalMilliLitres  = 0;
  oldTime           = 0;
  attachInterrupt(flowinterrupt, pulseCounter, FALLING);
  attachInterrupt(onswitch, tapclick, FALLING);

}
void loop()
{
 serialpeek();    //check if any data is at serial port
}

void serialpeek()  
{
  int i=0;
  char c;
  char serialdata[100];
  String datastring="";
  if (Serial.available())
  {
      while (i<100 && Serial.available())
      {
          c=Serial.read();
          serialdata[i]=c;
          i++;
      }
      serialdata[i]=0;
      datastring=String(serialdata);
     Serial.flush();

    if (datastring.indexOf("/ ")>0) { mainPage();}
    if (datastring.indexOf("threshold")>0) {updateval(serialdata);}

      Serial.flush();
  }
}

void mainPage()
{
  int i;
  byte serbuffer;
  for(i=0;i<strlen_P(webpage1);i++)
  {
    serbuffer=pgm_read_byte_near(webpage1+i);
    Serial.print(serbuffer);
  }
  Serial.print(tapbutton);
  for(i=0;i<strlen_P(webpage2);i++)
  {
    serbuffer=pgm_read_byte_near(webpage2+i);
    Serial.print(serbuffer);
  }
  Serial.print(flowRate);
  for(i=0;i<strlen_P(webpage3);i++)
  {
    serbuffer=pgm_read_byte_near(webpage3+i);
    Serial.print(serbuffer);
  }
  Serial.print(totalMilliLitres);
  for(i=0;i<strlen_P(webpage4);i++)
  {
    serbuffer=pgm_read_byte_near(webpage4+i);
    Serial.print(serbuffer);
  }  
  Serial.print(threshold);
  for(i=0;i<strlen_P(webpage5);i++)
  {
    serbuffer=pgm_read_byte_near(webpage5+i);
    Serial.print(serbuffer);
  }  
}

void updateval(String serialdata)
{
  int a,b,x,y,temp=0;
  String buffertext,parameter[2];
  x=serialdata.indexOf("?");
  y=serialdata.length();
  String pagetext = serialdata.substring(x+1,y);
  for(int i=0;i<2;i++)
  {
    x=temp;
    y=pagetext.indexOf("&",temp);
    buffertext=pagetext.substring(x,y);
    temp=x+1;
    a=buffertext.indexOf("=");
    b=buffertext.length();
    parameter[i]=buffertext.substring(a+1,b);
  }
  if(parameter[0]=="ON")tapclick();
  threshold=parameter[1].toInt();
}

void tapclick()
{
 if( totalMilliLitres<= threshold) 
 {
  tapfunc();
 }
}

void pulseCounter()
{
  flowpulse++;
  if((millis() - oldTime) > 1000)
  {
    detachInterrupt(flowinterrupt);
    flowRate = ((1000.0 / (millis() - oldTime)) * flowpulse) / calibration;
    oldTime = millis();
    flowMilliLitres = (flowRate / 60) * 1000;
    totalMilliLitres += flowMilliLitres;
    flowpulse = 0;
    attachInterrupt(flowinterrupt, pulseCounter, FALLING);
  }
}

void tapfunc()
{
  tapcontrol=0;
  while(digitalRead(onswitch)==HIGH&&tapcontrol<90) //90 degree tap
  {
    tapcontrol+=10;
    tapservo.write(tapcontrol);
    delay(50);
  } 
  delay(duration);
  for(int i=tapcontrol;i>0;i--)   //loop to close the tap with fading effect
  {
    tapservo.write(i);
    delay(30);
  }
}
Webpage mainpageHTML
This code is broken down in the main code
<html>
<head>
	<h2>SMARTAP DATA</h2>
	<style>
	table, td 
	{    border: 1px solid black;}
	table
	{width:100%;}
	button
	{width: 100%;}
	</style>
</head>
<body>
<form action=\"changedata\" method=\"get\" enctype=\"multipart/form-data\" name=\"threshold\" id=\"threshold\" target=\"_self\">
<table>
	<tr>
    <th>Tap state</th>
    <td>
    	<select>
 		<option value="ON">ON</option>
		<option value="OFF">OFF</option>
		</select> 
	</td>   
 	</tr>
	<tr>
    <th>Consumption rate</th>
    <td>#</td>
   	</tr>
   	<tr>
    <th>Total consumption</th>
    <td>#</td>
	</tr>
   	<tr>
    <th>Consumption threshold</th>
    <td><input type=\"text\" name=\"consthresh\" value='0' size=\"4\" maxlength=\"3\" />&nbsp;</td></td>
  	</tr>
  	<tr>
		<th></th>
  		<td><button type="submit" form="threshold" value="Save">Submit</button></td>
    </tr>
</table>
</form>
</body>
</html>

Schematics

CIrcuit complete
Wiring at the tap end.
Schematic wiznet smartap sheet 1 20180624212208 c1hcv6qxpd
Potential Divider interfacing
Alternate connection for interfacing Wiz750SR with Arduino
Schematic wiznet smartap sheet 1 20180624213637 cvr0arvovy

Comments

Similar projects you might like

Personal Home Assistant

Project tutorial by 3 developers

  • 4,003 views
  • 0 comments
  • 26 respects

Hacking Qualcomm (Quick Charge) QC 2.0/3.0 With ATtiny85

Project tutorial by Shahariar

  • 5,898 views
  • 11 comments
  • 40 respects

Lightly

Project tutorial by Abdullah Sadiq

  • 4,561 views
  • 3 comments
  • 20 respects

Secure Package Delivery Trunk for Your Front Porch

Project tutorial by Team Castle Locker

  • 2,515 views
  • 1 comment
  • 15 respects

WIZnet S2E Light Control

Project tutorial by Team S2ELighting

  • 1,448 views
  • 0 comments
  • 7 respects

The Train of the Future

Project showcase by Team STT

  • 14,081 views
  • 5 comments
  • 19 respects
Add projectSign up / Login