Length of time between pulses ?

Hello, I'm tring to work out how to time the length of time between pulses of an LED i.e rate (on my electric meter , 1 pulse = 1 watt of electricity). The timing can be anything from 1 pulse every ~10 minutes to ~3 a second being 6WATTS - 10.8 Kilowatts then I could display this on a servo to form a Kilowatt power meter display :slight_smile:

It sounds to me like the first thing you need is a detector that can sense the LED. Then you can write code to time the length between readings.

Sorry I should have said, I was planning to have a 741 opamp and a photo diode or a LDR to send the pulses back to an Arduino

Here is a very simple sketch that will monitor pulse transitions and calculate the time in milliseconds betwen the leading and trailing edge. You can define the edge transitions as appropriate for your blink detect logic.

#define  DELAY_START   HIGH         // or low depending on your blink detection logic
#define  DELAY_END   !DELAY_START   // this is the inverse of the above 

int ledPin = 13;                // choose the pin for the LED
int inputPin = 2;               // choose the input pin (for blink detection circuit)
long start, duration;

void setup() {
  pinMode(ledPin, OUTPUT);      // declare LED as output
  pinMode(inputPin, INPUT);     // declare pushbutton as input
}

void loop(){
  while( digitalRead(inputPin) != DELAY_START   )
       ;
  start = millis();
  while( digitalRead(inputPin) != DELAY_END   )
       ;
  duration = start - millis();
  // do stuff here to process the delay time calculated above
}

I hope this helps with some ideas about how to impliment your application

Many thanks for that I didn't think it was that easy :wink: - would that example time between the pulses ? i.e. the LED flashes on for about 0.25 second fixed and the time between each flash varies. I was originally looking at PulseIN but would measure the length of flash and also it hangs while timing. I don't have an Arduino YET just looking at C code (I'm fairly good at electronics!)

Dave.

Dave, as long as your #define DELAY_START to reflect the pin state when the blink stops, the code should measure the duration to the next blink start.

The code above also hangs while timing but you should have enough time after the end of a pulse and the beginning of the next to update your servo. The problem with PulseIn for your app is that it only times up to three minutes.

You could use an interrupt to capture the transition but I am not sure its necessary. see here for more on interrupts with the arduino http://www.arduino.cc/en/Reference/AttachInterrupt

Ah thanks, it was just my reading to code the wrong way around if see what I mean

In the very dim and distant past I used mess about with assembler for 6502 and Z80 processors a BBC 'B' and ZX81 remember them ? in the 80's but C seems a hell of a lot easier, I should have learnt it sooner I had printed out a C tutorial from the 80's on a dot matrix printer but never really got into it - no Arduino then I guess !. It's almost as easy as BBC basic !

10 for a= 1 to 10
20 print a
30 next a

Thanks again !

Dave

Dave, I remember every one of them all very well indeed :). I still have my ZX81 packed away in a box somewhere.

You will be pleased to know that the Arduino environment hides a lot of the complexity of C, and it's a heck of a lot easier then z80 assembler so you shouldn't have too much trouble. And there are lots of examples for the kind of thing you are doing. And many people here that are knowledgeable and glad to help.

Mem, I still have my beeb BBC 'B' and my ZX81 ;D oh yes the ZX81 only has 1K of memory !! I also had a 16K ram pack !! wow how things have changed. I've been reading a lot lately a 'C' book and it doesn't seem to bad ever raw C. Yes this seems a nice friendly forum

Are you in the UK Mem or maybe Holland ? - I think the beeb and ZX81 were popular in Holland too.

Dave.

My favourite book on C is “The C programming language” by Kernighan and Ritchie. I had recommended it to someone else on this forum but he found it wasn't ideal as a beginners book so I am a little reluctant to push it again. But, it has a clarity of writing that I found refreshing when I was learning the language many years ago. See if you can find a copy in your local library.

And yes, I am in the UK, I live in north west London.

BTW, there is an article here you may find interesting: http://www.btinternet.com/~jon00/electmon.shtml

Well, strange I've looked at your page many times before! (from bwired.nl 's page) The book I have is 'C Programming In Easy Steps'. I've 'played' with 1-wire - ibuttons etc, and Homeseer. The electric company just changed our meter to one like yours with the flashing LED!

Small world

Dave.

Just to be clear, not my page or meter, but one that I guessed would be similar to yours.

Ah ok, my mistake :-[

Dave.

W00t, Beeb-heads of the world unite!

Representing the Southern Hemisphere crew...

--Phil. :smiley:

P.S. BBC Basic with inline 6502 assembler ftw!