Friday 6 September 2013

Measure Torch burn time and compare outputs with an Arduino Uno and bh1750fvi-e.pdf ( lux meter)

I was curious as to how long my batteries were lasting in my torches. I tried turning them on and watching to see when they dimmed/turned off, mostly I missed the inevitable end.... Also trying to gauge power output was proving problematic, they all look very similar. So, something a little more scientific was required.

I thought the answer was a bh1750fvi-e sensor which is a calibrated light sensor readily available and easily interfaced to. In fact all the code/circuit was already on the internet, just needed a small tweak to add a timestamp and capture to file.

The principle is :

1) An Arduino Uno has a bh1750fvi-e sensor connected to it via the I2C bus.
2) The Uno reads the sensor every 1 second and outputs to a connected PC a timestamped value.
3) The Pc captures the Uno's output in MS HyperTerminal, to a file.
4) Load the file in MS Excel and graph it.

An example is shown below, from a Ultrafire G2-t60 torch with a fully charged 18650 3.7V 2500ma Trustfire battery loaded. Its draws about 2.2A at the tailcap. Distance from Torch to Sensor, approx 20cm..

Looks like only a 50 minute burn time.




The graph shows Lux, Foot-Candles and Wattsm2.

I had hoped to measure Lumens but that is a completely different measurement, google it, its not trivial... So the magnitude of the graph is sort of irrelevant in the graph unless you want to compare power outputs between multiple torches.

Lux is the only value returned from the sensor, the other two were included in the code I found on the internet and derived from the Lux value, might loose them.

The torch was about 20cm from the sensor, the further away you move it the values go down. I suspect this was too close and the initial values of the torch at full power are maxing out the sensor. To compare torches, i'll experiment with greater distances, if this is a 800-900 lumen torch then to provide some future proofing in comparisons with more powerful torches i'll try increasing the distance to 1m.

Parts:

Arduino Uno because I had one..
PC for connecting to the Uno for programming and recording the values ( USB).
BH1750FVI Digital Light intensity Sensor Module for Arduino, like this from ebay..














Datasheet for sensor...

www.rohm.com/products/databook/sensor/pdf/bh1750fvi-e.pdf

I used a breadboard to prototype it up...

And test like this:



Circuit is only 4 wires to support the sensor's power requirements and the I2C interface. Its listed in the programme below.

/*
 #######################################################
 Arduino Light Meter

 #######################################################

 BH1750 sensor module connections:
 -------------------------------------
 BH1750                        Arduino
 VCC      --------------->     5V
 SCL      --------------->     Analog pin 5 (A5)
 SDA      --------------->     Analog pin 4 (A4)
 ADD      --------------->     Leave it open
 GND      --------------->     GND
 #######################################################

 */


#include "Wire.h" 
#include "math.h"

// macros from DateTime.h 
/* Useful Constants */
#define SECS_PER_MIN  (60UL)
#define SECS_PER_HOUR (3600UL)
#define SECS_PER_DAY  (SECS_PER_HOUR * 24L)

/* Useful Macros for getting elapsed time */
#define numberOfSeconds(_time_) (_time_ % SECS_PER_MIN)  
#define numberOfMinutes(_time_) ((_time_ / SECS_PER_MIN) % SECS_PER_MIN) 
#define numberOfHours(_time_) (( _time_% SECS_PER_DAY) / SECS_PER_HOUR)
#define elapsedDays(_time_) ( _time_ / SECS_PER_DAY)  


int BH1750_Device = 0x23; // I2C address for light sensor
int iCheck = 0;  // iCheck = 0 for Lux, iCheck = 1 for Foot-Candles
unsigned int Lux, Scaled_FtCd;
float FtCd, Wattsm2;

void setup()
{
  Wire.begin();
  Serial.begin(9600);
  Configure_BH1750();
  delay(300);

  Serial.println("Time,  [lx],  [FC] , [Watts/m^2]");
}

void loop()
{

  Lux = BH1750_Read();
  FtCd = Lux/10.764;  /*Foot Candle*/
  Wattsm2 = Lux/683.0;

  time(millis() / 1000);
  
  Serial.print (",");  
  
  Serial.print(Lux,DEC);     

  Serial.print (",");

  Serial.print(FtCd,2);     

  Serial.print (",");

  Serial.println(Wattsm2,4);     

  delay(1000);
}

unsigned int BH1750_Read() //
{
  unsigned int i=0;
  Wire.beginTransmission(BH1750_Device);
  Wire.requestFrom(BH1750_Device, 2);
  while(Wire.available()) //
  {
    i <<=8;            //Highbyte/Lowbyte read
    i|= Wire.read();  
  }
  Wire.endTransmission();  
  return i/1.2;  // Convert to Lux as per datasheet..
}

void Configure_BH1750() 
{
  Wire.beginTransmission(BH1750_Device);
  Wire.write(0x10);      // Set resolution to 1 Lux / continous H-Res mode
  Wire.endTransmission();
}

void time(long val){  
 int days = elapsedDays(val);
 int hours = numberOfHours(val);
 int minutes = numberOfMinutes(val);
 int seconds = numberOfSeconds(val);

 char time_c[13];

 sprintf(time_c,"%02d:%02d:%02d" , hours, minutes, seconds); 
    
 Serial.print(time_c);
}


When you run the programme from within Arduino IDE you can verify the output using the Serial monitor in the Tools menu. I thought there was a way of capturing it direct from there but couldn't find it, so i opted to use the old terminal emulator supplied with Windows ( Hyper Terminal under Programs/Communications).

First of all exit the Arduino IDE to free up the USB port and then run up Hyper Terminal.
Create a new connection which is:-
Connects using the COM port used by Arduino IDE ( mine was COM8 for the USB port).
Bit Speed = 9600

Enable capture to file using the Transfer menu option "Capture Text"

To capture text with the headings from the Uno's output, Call the device to reset the Uno and get it to start logging from 00:00:00 and output the headings. You can Call / Disconnect the Uno to reset its output anytime.

I left the torch on overnight, stopped the capture the next morning, loading into MS Excel as a CSV file and graphed it. The first row in the file contains the series names.

Not so plain sailing...

I tried again with the same torch ( Ultrafire G2-t60) and a premium Xtar 3.7v 2600 to see if that made any difference to the run time....

Started it off and after 30mins noticed a nice warm plastic smell, it was running so hot it was burning the plastic surface it was resting on ! I had to let it cool down and repeat the process, making the excel graphing a nightmare.. ( with the current timestamp). But it ended up like this:-

Let it cool down !

Final Run.


Total Runtime at max power ish... = 55mins, it was beginning to drop off but I can't imagine it would be noticeable. Looks like the Xtar battery was only slightly better that the Dealxtreme Trustfire battery.

Next steps:-

Reduce the frequency from every 1s reading to say 5s to reduce the number of rows.
Try 1m distance between sensor and torch to be able to compare torches of wider Lumen output.
Heat management, work on a heat dissipation method.
Review the timestamp format to make Excel work easier and stopping/starting.
Waterproof sensor, so I can measure dive torch run times.
Gather some more data with different torches/LEDs/Battery to work on the comparisons.

Update:

Created a waterproof version so I can measure dive torches burn time and not worry about overheating...

Placed the sensor in an acrylic tube and used a rubber bung to block if off. The tube was an offcut from my dive torch project Here



I shortened the bung so the sensor could sit as far down the tube as possible, as the torch is resting on the bottom of my bucket and the beam is quite low.


I used the waste from the bung to make a wedge to keep the sensor in place.

Then place the torch and the sensor in a bucket of tap water, pointing the torch at the sensor.



The wire is 4 core alarm cable but could be anything, length is about 1m back to the Arduino Uno board.

Now I can run the torch without worrying about heat, in one test, I ran the torch for 2hrs and it was barely warm.



In testing the triple XML light ( link here .light. ) I've noticed that the circuit/program doesn't detect the flickering you sometimes get when the battery is going too low to drive the LED... Pro






















1 comment:

  1. Hallo :-) and big thanks ...i was looking for the proper usage of this elapsedDays() ( time(long val)..)
    SO nice..greets from germany Stuttgart

    ReplyDelete