Original version of flow sensor
authorJustin Mitchell <justin@discordia.org.uk>
Tue, 28 Feb 2017 16:01:17 +0000 (16:01 +0000)
committerJustin Mitchell <justin@discordia.org.uk>
Tue, 28 Feb 2017 16:01:17 +0000 (16:01 +0000)
flow_sensor.fzz [new file with mode: 0644]
flow_sensor.ino [new file with mode: 0644]
images/IMG_20150520_192335.jpg [new file with mode: 0644]
images/IMG_20150520_192545.jpg [new file with mode: 0644]
images/IMG_20150520_201717.jpg [new file with mode: 0644]
images/IMG_20150520_202233.jpg [new file with mode: 0644]
images/flow_sensor_pcb.png [new file with mode: 0644]
images/flow_sensor_schem.png [new file with mode: 0644]
reference/M3236.pdf [new file with mode: 0644]
reference/SIL05-1A72-71D.pdf [new file with mode: 0644]

diff --git a/flow_sensor.fzz b/flow_sensor.fzz
new file mode 100644 (file)
index 0000000..490657c
Binary files /dev/null and b/flow_sensor.fzz differ
diff --git a/flow_sensor.ino b/flow_sensor.ino
new file mode 100644 (file)
index 0000000..969dee1
--- /dev/null
@@ -0,0 +1,103 @@
+/* Flow sensor
+ * activates the relay when the rate of flow exceeds
+ * the selected value
+ */
+
+/* pin definitions */ 
+#define LED_RED   1
+#define LED_GREEN 0
+#define RELAY     4
+#define TRIM_ADC  2 /* ADC2 */
+#define TRIM_PIN  4 /* ADC2 is on PC4 */
+#define FLOW_INT  0
+#define FLOW_PIN  2
+
+/* our frequency counter */
+volatile int pulsecount = 0;
+
+/* increase the counter on interrupt */
+void counterISR()
+{
+  pulsecount++;
+}
+
+unsigned long last_time = 0; 
+int threshold = 0;
+
+/* read the trim pot, 
+ * div 3 to give a 1 - 342 range 
+ */ 
+void update_threshold(void)
+{
+  threshold = analogRead(TRIM_ADC);
+  threshold /= 3;
+  threshold += 1;
+}
+
+
+void setup() {
+  // pin 2 is the pulse from the flow sensor
+  pinMode(FLOW_PIN, INPUT);
+  
+  // pin 4 (ADC2) is an analog input
+  pinMode(TRIM_PIN, INPUT);
+  
+  // pin 0 & 1 are the LEDs
+  pinMode(LED_RED, OUTPUT);
+  pinMode(LED_GREEN, OUTPUT);
+  pinMode(RELAY, OUTPUT);
+  
+  // starting state: RED, relay open
+  digitalWrite(LED_RED, HIGH);
+  digitalWrite(LED_GREEN, LOW);
+  digitalWrite(RELAY, LOW);
+  
+  update_threshold();
+  last_time = millis();
+  
+  // now start the interupt routine
+  attachInterrupt(FLOW_INT, counterISR, FALLING);
+}
+
+void loop() {
+  unsigned long now = millis();
+
+  // clock has looped, restart
+  if (now < last_time) {
+    last_time = now;
+    pulsecount = 0;
+    return;
+  }
+
+  // it has been a second
+  if (now >= (last_time + 1000)) {
+    int count = pulsecount;
+
+    if (count == 0) {
+      // no movement: red
+      digitalWrite(LED_RED, HIGH);
+      digitalWrite(LED_GREEN, LOW);
+      digitalWrite(RELAY, LOW);
+    }else
+    if (count > threshold) {
+      // good flow: green, close relay
+      digitalWrite(LED_RED, LOW);
+      digitalWrite(LED_GREEN, HIGH);
+      digitalWrite(RELAY, HIGH);
+    } else {
+      // bad flow: yellow
+      digitalWrite(LED_RED, HIGH);
+      digitalWrite(LED_GREEN, HIGH);
+      digitalWrite(RELAY, LOW);
+    }
+
+    // check if the threshold moved
+    update_threshold();
+    
+    // restart the clock
+    last_time = now;
+    pulsecount = 0;
+  }
+
+  // otherwise do nothing, just wait
+}
diff --git a/images/IMG_20150520_192335.jpg b/images/IMG_20150520_192335.jpg
new file mode 100644 (file)
index 0000000..417c4b8
Binary files /dev/null and b/images/IMG_20150520_192335.jpg differ
diff --git a/images/IMG_20150520_192545.jpg b/images/IMG_20150520_192545.jpg
new file mode 100644 (file)
index 0000000..39a8ac5
Binary files /dev/null and b/images/IMG_20150520_192545.jpg differ
diff --git a/images/IMG_20150520_201717.jpg b/images/IMG_20150520_201717.jpg
new file mode 100644 (file)
index 0000000..074ed4a
Binary files /dev/null and b/images/IMG_20150520_201717.jpg differ
diff --git a/images/IMG_20150520_202233.jpg b/images/IMG_20150520_202233.jpg
new file mode 100644 (file)
index 0000000..15b5b72
Binary files /dev/null and b/images/IMG_20150520_202233.jpg differ
diff --git a/images/flow_sensor_pcb.png b/images/flow_sensor_pcb.png
new file mode 100644 (file)
index 0000000..28b381a
Binary files /dev/null and b/images/flow_sensor_pcb.png differ
diff --git a/images/flow_sensor_schem.png b/images/flow_sensor_schem.png
new file mode 100644 (file)
index 0000000..0bb23c2
Binary files /dev/null and b/images/flow_sensor_schem.png differ
diff --git a/reference/M3236.pdf b/reference/M3236.pdf
new file mode 100644 (file)
index 0000000..bd79651
Binary files /dev/null and b/reference/M3236.pdf differ
diff --git a/reference/SIL05-1A72-71D.pdf b/reference/SIL05-1A72-71D.pdf
new file mode 100644 (file)
index 0000000..d727df3
Binary files /dev/null and b/reference/SIL05-1A72-71D.pdf differ