12/04/2021 To 18/04/2021
Full Signal processing code
#include <MovingAverageFilter.h>
#include <SoftwareSerial.h>
#define RX 6
#define TX 7
MovingAverageFilter movingAverageFilter(20);
MovingAverageFilter movingAverageFilter1(20);
MovingAverageFilter movingAverageFilter2(70);
SoftwareSerial Display(9, 10);
//---------------------------------------------------------
String AP = "Dialog 4G 193"; // AP NAME
String PASS = "64F7bDe3"; // AP PASSWORD
String API = "RAPBZ11S6DYB2NYL"; // Write API KEY
String HOST = "api.thingspeak.com";
String PORT = "80";
int countTrueCommand;
int countTimeCommand;
boolean found = false;
SoftwareSerial esp8266(RX,TX);
String Person = "S Randinu";
//-------------------------------------------------------
int count= 0;
float input;
float output;
float caltime;
float initialarray[2] = {0.0,0.0};
float currentarray[2];
float dy;
float dt;
float derivative_output;
float output1;
float initialarray1[2] = {0.0,0.0};
float currentarray1[2];
float dy1;
float dt1;
float derivative_output1;
float output2;
float output3;
float threshold=475.0;
int peakcount=0;
int k=0;
String PersonID_IN = "S.R.";
String PersonID_SR = "Hettiarachchi";
float peak = 0.0;
float time1=0.0 ;
float time2=0.0;
float time3= 0.0;
float voltage = 0.0;
float zero= 0.0;
float timegap=0.0;
float Volume =0.0;
float Flowrate = 0.0;
String Display_send="";
void setup()
{
Serial.begin(9600);
Display.begin(9600);
esp8266.begin(115200);
sendCommand("AT",5,"OK");
sendCommand("AT+CWMODE=1",5,"OK");
sendCommand("AT+CWJAP=\""+ AP +"\",\""+ PASS +"\"",20,"OK");
}
void loop()
{
input = analogRead(A0);
//float z = (5.0*input)/1023;
caltime = millis();
output = movingAverageFilter.process(input); // here we call the fir routine with the input. The value 'fir' spits out is stored in the output variable.
currentarray[0] = output;
currentarray[1] = caltime;
dy = currentarray[0]- initialarray[0];
dt = currentarray[1] - initialarray[1];
derivative_output = dy/dt;
initialarray[0] = currentarray[0];
initialarray[1] = currentarray[1];
output1 = movingAverageFilter1.process(derivative_output*150);
currentarray1[0] = output1;
currentarray1[1] = caltime;
dy1 = currentarray1[0]- initialarray1[0];
dt1 = currentarray1[1] - initialarray1[1];
derivative_output1 = dy1/dt1;
initialarray1[0] = currentarray1[0];
initialarray1[1] = currentarray1[1];
output2 = movingAverageFilter2.process(derivative_output1*150);
output3= output2*100;
voltage = (5.0*output3)/1023;
if (k!=1){
if(voltage > 11.0){
//peak = threshold;
k= 1;
time1=millis();
}
}
if(k==1){
if(voltage < 10.8){
//peak = 0.0;
peakcount = peakcount +1;
k=0;
timegap = (time1-time3)/1000;
time3 = time1;
Volume= Volume+0.02517;
Flowrate = (0.02517*3600.0)/timegap;
}
}
if (voltage>0.0){
Serial.println(voltage);
}
else{
Serial.println(zero);
}
if (count == 2550){
Display_send = "*" + PersonID_IN + "," + PersonID_SR + "," + String(peakcount) + "," + String(timegap) + "," + String(Volume)+ "," + String(Flowrate) + "," + "#";
Display.println(Display_send);
String getData = "GET /update?api_key="+ API +"&"+ "field1" +"="+Person+"&"+ "field2" +"="+String(timegap)+"&"+ "field3" +"="+String(timegap)+"&"+ "field4" +"="+String(Volume)+"&"+ "field5" +"="+String(Flowrate)+"&"+ "field6" +"="+String(Flowrate)+"&"+ "field7" +"="+String(peakcount);
sendCommand("AT+CIPMUX=1",5,"OK");
sendCommand("AT+CIPSTART=0,\"TCP\",\""+ HOST +"\","+ PORT,15,"OK");
sendCommand("AT+CIPSEND=0," +String(getData.length()+4),4,">");
esp8266.println(getData);delay(1500);countTrueCommand++;
sendCommand("AT+CIPCLOSE=0",5,"OK");
count =0;
}
else{
count =count +1;
}
}
void sendCommand(String command, int maxTime, char readReplay[]) {
while(countTimeCommand < (maxTime*1))
{
esp8266.println(command);//at+cipsend
if(esp8266.find(readReplay))//ok
{
found = true;
break;
}
countTimeCommand++;
}
if(found == true)
{
countTrueCommand++;
countTimeCommand = 0;
}
if(found == false)
{
countTrueCommand = 0;
countTimeCommand = 0;
}
found = false;
}
Final code file
All the processed data results of Atmega328p Microcontroller
Original drop signal & Smoothed drop signal
Blue line - Original drop signal
Red line - Smoothed drop signal
First derivative signal
First derivative signal & Smoothed first derivative signal
Blue line - First derivative signal
Red line - Smoothed First derivative signal
First derivative signal & Drop signal
Blue line - First derivative signal
Red line - Drop signal
Drop signal, smooth drop signal & First derivative signal
Blue line - First derivative signal
Red line - Drop signal
Green line - Smoothed drop signal
Second derivative signal
2nd Derivative signal & Smoothed 2nd derivative signal
Blue line - 2nd derivative signal
Red line - Smoothed 2nd derivative signal
2nd derivative signal & Drop signal
Blue line - 2nd derivative signal
Red line - Drop signal
Drop signal & 2nd derivative signal, smooth 2nd derivative signal
Blue line - 2nd derivative signal
Red line - Smoothed 2nd derivative signal
Green line - Drop signal
Drop signal & Drop detecting pulse signal
Blue line - Drop detecting pulse
Red line - Drop signal
Drop detecting pulse signal 7 Threshold line
Blue line - Drop detecting pulse
Red line - Threshold line
Flow rate & Drop counting Display
Casing Design
The layout of the casing was done by using solid works. Main device layout is shown below.
Project Files