This is my first Arduino project. The project objective is to remotely monitor the water flow in the irrigation system at my home. I intend to develop the project in 2 phases.
The first phase will be to display the results to a hard wired LED for the purpose of verifying the operation of the monitoring system.
The second phase consists of replacing the LED display with a WiFi module and uploading the output in a continuous stream to a TBD website.
I am now requesting a critique of the hardware setup and the sketch for Phase 1. I have already run the sketch through the Arduino ‘sanity’ verification.
The hardware consists of the following:
Arduino Uno
External power cable for Uno
Geniten Hall-effect water flow sensor
Diymall 4-pin .96 two-color oled display
Connections are as follows:
Jumpers from Uno to a 5V bus and to a 3.3V bus
Sensor power connecttion to 5V bus
Sensor data connect to Uno pin D2
Display power connect to 3.3V bus
Display SDA connect to Uno pin A4
Display SCL connect to Uno pin A5
H2O_Flo_LED
Measures the flow rate of water flowing through a 3/4-inch PVC pipe using a DIGITEN Hall effect sensor and displaying results on a 0.96-inch Diymall 4-pin Oled display.
The sensor output is in the form of the duration in milliseconds of a square wave pulse and the relationship to the water flowrate is:
F = 4.8 * Q ( in liters per minute)
*/
int pin = 2;
double dursec;
double pulsefreq;
double flolitr;
double flogal;
double flocuft;
unsigned long duration;
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);
void setup()
{
pinMode(pin, INPUT);
Serial.begin(9600);
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
//initialize with the I2C addr 0x3C (128x64)
display.clearDisplay();
// clear the display before start
}
void loop()
{
duration = pulseIn(pin, HIGH);
//Pulse duration in microseconds
dursec = duration / 1000000;
//Pulse duration in seconds
pulsefreq = 1 / dursec;
//Pulse frequency in Hz
flolitr = (pulsefreq * 60 / 4.8);
//Flow rate in Liters/hour
flogal = flolitr * .26417;
//Flow rate in Gallons/hour
flocuft = flolitr * .035315;
//Flow rate in cu ft/hour
display.setCursor(22,20);
//x,y coordinates
display.setTextSize(3);
//size of the text
display.println(flogal);
display.setCursor(85,20);
display.setTextSize(3);
display.println("Gal/hr");
//print "Gal/hr" in oled
delay(1000);
// Wait one second
display.clearDisplay();
}