Saturday, May 24, 2014

Saving battery life...

A Fuel Flow Managing System is all about measuring Fuel economy. That's easy to understand. So it would only make sense if the Fuel Manager would need the least possible energy for doing its job. Thats what I did.

JeeLib is a Arduino (not only) Library that can put a Arduino (ATMEGA) into sleep, consuming the least amount of energy. You can install it buy downloading from GitHub here and putting the folder (rename it as JeeLib) into the Arduino "libraries" folder.

I modified the sketch to take a measurement for one second and then go to sleep until the sensor picks up a pulse again. It would really make sense of course, when using a Barebone Arduino, that hasn't got the USB intercafe etc. that also consumes energy. 

Here is the updated code with the JeeLib part.

//******************************************************
//     BT Fuel Manager Arduino sketch by MaleBuffy
//            for Single 2 Stroke Outboard
//         and BT Fuel Manager / BT Fuel Gauge
//                24/5/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
//     Pin D6 for GND for the Sensor
//     Pin D2 for Sensor cable



#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
float literspersecond;  // Holds the Serial output to the BT Device. Its the liters per second
int hall = 2;    // Sensor Pin should be connected to Pin 2 of the Arduino
int pulses = 2000 ; // Define Sensor 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
  PulseSensor++;  // 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(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



// Loop measuring pulses from Sensor

void loop ()    
{

  PulseSensor = 0;   // Resetting PulseSensor 
  sei();      // Enabling interrupts
  delay (1000);   // Delay 1 second (1000 milliseconds)
  cli();      // Disabling interrupts

  literspersecond = (PulseSensor/pulses); // Flowsensor used, makes X Pulses ever Liter. 
  BTFuel.println(literspersecond,4); // Sends liters per second to Bluetooth 

  if (PulseSensor == 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