Thursday, May 29, 2014

Theoretically speaking...(Update: Tested and working)

A friend asked me to make him a BT Fuel Manager for his twin Yamaha Setup. He has 2 tanks that feed each outboard, so he needed 2 sensors and a bit of coding to make this work with the Android apps. Since he isn't into learning Processing from scratch, he asked me to help him with the software part and show him how to do the hardware part.

Like the title says, this hasn't been tested, but should work. What it does is, it uses a second interrupt on Pin 3, where the second sensor is connected, and triggers exactly the same function to count pulses. Now this could have been done in two ways.

1. We could just attach an interrupt to pin 3 and call the same increment function called "incrementpulse".
2. We could use 2 seperate increment values and functions and add that at the end when sending data to the Apps

I have chosen the second way for a simple reason: You can use 2 diffrenet sensors, that have a diffrenet count per liter value. For instance 2000 pulses per liter on the first one and a 2500 pulses per liter on the second one.

Here is the code in theory:

UPDATE 1/6/2014: I have connected two flow sensors and tested the application. It is working and gets data from both sensors. We still haven't tested it on the boat but everything looks promising. The best part is that even if you plan to use one flow sensor, you can use this Sketch as it works also with one sensor connected!


//******************************************************
//     BT Fuel Manager Arduino sketch by MaleBuffy
//            for Double 2 Stroke Outboard
//         and BT Fuel Manager / BT Fuel Gauge
//                21/4/2014
//******************************************************
//
//     Pin 9 of Arduino to RX on the HC-05
//     Pin 11 of Arduino to TX on the HC-05
//     Pin 3v3 for +3.3V for the HC-05
//     Pin Gnd for Ground for the HC-05
//     Pin D4 for +5V for the Sensor 1
//     Pin D6 for GND for the Sensor 1
//     Pin D2 for Sensor 1 cable
//     Pin D3 for Sensor 2 cable   
//     Pin D4 for +5V for the Sensor 2
//     Pin D6 for GND for the Sensor 2
#include <JeeLib.h> // The Library used to put Arduino to sleep ISR(WDT_vect) { Sleepy::watchdogEvent(); } // Enable Watchdog for Sleeping purposes #include <SoftwareSerial.h>// import the Arduino serial library SoftwareSerial BTFuel(11, 9); // Define the Pins of the HC-05 Bluetooth device. RX, TX volatile float PulseSensor; // Measuring the pulse from the sensor 1 volatile float PulseSensor2;// Measuring the pulse from the sensor 2 float literspersecond; // Its the liters per second of sensor 1 float literspersecond2; // Its the liters per second of sensor 1 int hall = 2; // Sensor 1 Pin should be connected to Pin 2 of the Arduino int hall2 = 3; // Sensor 2 Pin should be connected to Pin 3 of the Arduino int pulses = 1818 ; // Define Sensor 1 Pulse per Liter for 2500 FCH-M-POM-LC 6 MM / 950 for FCH-midi-POM / 1818 for FS-3400AH int pulses2 = 1818 ; // Define Sensor 2 Pulse per Liter for 2500 FCH-M-POM-LC 6 MM / 950 for FCH-midi-POM / 2000 for FS-3400AH / void incementpulse () //This is the function that incements the pulse counter. PulseSensor 1 { PulseSensor++; // Equals PulseSensor = PulseSensor + 1 } void incementpulse2 () //This is the function that incements the pulse counter. PulseSensor 2 { PulseSensor2++; // Equals PulseSensor = PulseSensor + 1 } // Begin of Code. Setting pins up. void setup() { pinMode(hall, INPUT); // Init Pin 2 to receive data from the Sensor digitalWrite(hall, HIGH); // Using Internal Pull up resistor to pin 2 pinMode(hall2, INPUT); // Init Pin 3 to receive data from the Sensor digitalWrite(hall2, HIGH); // Using Internal Pull up resistor to pin 3 pinMode(4, OUTPUT); // Initializes digital pin 4 as an OUTPUT digitalWrite(4, HIGH); // 5V to pin 4 (Flow Sensor) pinMode(6, OUTPUT); // Initializes digital pin 6 as an OUTPUT digitalWrite(6, LOW); // GND to pin 6 (Flow Sensor) BTFuel.begin(9600); // Initiate serial connection to Bluetooth device attachInterrupt(0, incementpulse, RISING); // attaching the interupt attachInterrupt(1, incementpulse2, RISING); // attaching the interupt } // Loop measuring pulses from Sensor void loop () { PulseSensor = 0; // Resetting PulseSensor PulseSensor2 = 0; // Resetting PulseSensor 2 sei(); // Enabling interrupts delay (1000); // Delay 1 second (1000 milliseconds) cli(); // Disabling interrupts literspersecond = (PulseSensor/pulses); // Flowsensor used, makes X Pulses ever Liter. literspersecond2 = (PulseSensor2/pulses2); // Flowsensor used, makes X Pulses ever Liter. BTFuel.println(literspersecond+literspersecond2,4); // Sends liters per second to Bluetooth if (PulseSensor == 0 && PulseSensor2 == 0) { // If no input comes from the Sensor, put the Arduino to Sleep enterSleep(); } } // Function to put Arduino to sleep void enterSleep() { Sleepy::powerDown(); }

No comments:

Post a Comment