Showing posts with label Liquid Filling Machine Using Arduino Flow Rate Sensor. Show all posts
Tuesday, September 25, 2018
Liquid Filling Machine Using Arduino Flow Rate Sensor
Liquid Filling Machine Using Arduino Flow Rate Sensor
CODING OF THIS PROJECT:-
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Keypad.h>
#define Password_Length 4
int signalPin = 12;
char Data[Password_Length];
char Master[Password_Length];
byte data_count = 0, master_count = 0;
bool Pass_is_good;
int customKey;
int sum=0;
const byte ROWS = 4;
const byte COLS = 4;
char hexaKeys[ROWS][COLS] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
byte rowPins[ROWS] = {9, 8, 7, 6};
byte colPins[COLS] = {5, 4, 3, 1};
Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
byte statusLed = 13;
byte sensorInterrupt = 0; // 0 = digital pin 2
byte sensorPin = 2;
// The hall-effect flow sensor outputs approximately 4.5 pulses per second per
// litre/minute of flow.
float calibrationFactor = 1;
volatile byte pulseCount;
float flowRate;
unsigned int flowMilliLitres;
unsigned long totalMilliLitres;
unsigned long oldTime;
LiquidCrystal_I2C lcd(0x3F, 16, 2);
void setup()
{
lcd.begin();
lcd.backlight();
pinMode(signalPin, OUTPUT);
// Initialize a serial connection for reporting values to the host
Serial.begin(9600);
// Set up the status LED line as an output
pinMode(statusLed, OUTPUT);
digitalWrite(statusLed, HIGH); // We have an active-low LED attached
pinMode(sensorPin, INPUT);
digitalWrite(sensorPin, HIGH);
pulseCount = 0;
flowRate = 0.0;
flowMilliLitres = 0;
totalMilliLitres = 0;
oldTime = 0;
// The Hall-effect sensor is connected to pin 2 which uses interrupt 0.
// Configured to trigger on a FALLING state change (transition from HIGH
// state to LOW state)
attachInterrupt(sensorInterrupt, pulseCounter, FALLING);
}
/**
* Main program loop
*/
void loop()
{
lcd.setCursor(0,0);
lcd.print("Entr Amont in ml");
customKey = customKeypad.getKey();
if (customKey){
Data[data_count]=customKey-48;
lcd.setCursor(data_count,1);
lcd.print(Data[data_count]);
sum=sum+Data[data_count];
data_count++;
}
if( data_count==3)
{
digitalWrite(signalPin, HIGH);
delay(990*sum);
sum =sum*100;
lcd.setCursor(0,1);
lcd.print(sum);
digitalWrite(signalPin, LOW);
clearData();
}
if((millis() - oldTime) > 1000) // Only process counters once per second
{
detachInterrupt(sensorInterrupt);
flowRate = ((1000.0 / (millis() - oldTime)) * pulseCount) / calibrationFactor;
oldTime = millis();
flowMilliLitres = (flowRate / 60) * 1000;
// Add the millilitres passed in this second to the cumulative total
totalMilliLitres += flowMilliLitres;
unsigned int frac;
// Print the flow rate for this second in litres / minute
Serial.print("Flow rate: ");
Serial.print(int(flowRate)); // Print the integer part of the variable
Serial.print("L/min");
Serial.print("\t"); // Print tab space
// Print the cumulative total of litres flowed since starting
Serial.print("Liquid Quantity: ");
Serial.print(totalMilliLitres);
Serial.println("mL");
Serial.print("\t"); // Print tab space
Serial.print(totalMilliLitres/1000);
Serial.print("L");
// Reset the pulse counter so we can start incrementing again
pulseCount = 0;
// Enable the interrupt again now that we've finished sending output
attachInterrupt(sensorInterrupt, pulseCounter, FALLING);
}
if(sum < totalMilliLitres ){
digitalWrite(signalPin, LOW);
lcd.clear();
lcd.setCursor(0,1);
lcd.print ("In=");
lcd.setCursor(3,1);
lcd.print(sum);
lcd.setCursor(0,0);
lcd.print ("Amount Delivered");
lcd.setCursor(6,1);
lcd.print (",Out=");
lcd.setCursor(11,1);
lcd.print(sum,DEC); // print the Flow Rate
lcd.setCursor(14,1);
lcd.print ("ml");
delay(60000);
lcd.clear();
clearData();
}
}
void pulseCounter()
{
// Increment the pulse counter
pulseCount++;
}
void clearData(){
while(data_count !=0){
Data[data_count--] = 0;
}
return;
}
Subscribe to:
Posts
(
Atom
)

