1. Dave Stowe

    Have a look at mine, it might help :-

    Name :- Meter Pulse Counter and Clock Reader

    Purpose :- Counts the pulses in one day from midnight, and sends the data on request, normally every 5 seconds to my XRF net.
    Uses the LLAP protocol to send and recive data on my Ciseco XRF network see http://www.ciseco.co.uk for more info.
    My network communicates serially at 115200 baud so we dont miss a meter pulse.
    Answers to “aMRALIVE—-” to see if the unit is alive.
    Answers to “aMRSENDDATA-” to send the watts used, average, minimum and maximum values.
    Answers to “aMRRESETT—” to re-align the clock module, done by the master unit at 23:00 if master read the
    NTP time okay over the WWW before this, so we can accurately reset the unit at midnight. If no sync, runs on DS1307.
    Replies to the commands, mimicing aMRALIVE—- and RESETT—. On reqesting data sends the data blocks and then

    Protocol :- See full expination at above web site. It uses data in 12 byte blocks, a sync letter, ‘a’, 2 byte ident, ‘MR’ in
    my unit and then 9 bytes for data. You can set the frequencies, baud rates and security through their software. FREE!
    Datastream sent to master unit is :-
    LLAP Strings aMRWA0000025aMRAV0001800aMRCU0001800aMRMI0001798aMRMA0001802aMRSENDDATA- ‘6 Packets of 12 byte data’
    Description —-Watts——Average——Current—-Minimum—-Maximum——Reply—-

    Pysical :- Fitted in a large matchbox size box, and flashes a RGB LED red with a mimic pulse, blue with data on the network and
    green on the rest for power. An Xino RF Arduino from Ciseco is the main unit, with a DS1307 attached by double sided tape.
    You can use what ever type of Arduino you want. An LDR reads the meter pulse, LDR connects 1 pin to 5v, the other to pin D2.
    You also need a 10k resistor from pin D2 to 0volts. I attached my LDR to the meter with Blue Tack. Make sure no external
    light gets to the sensor. The darker it is aound the LDR the better, but not touching, glare. I use the falling edge for
    the interrupt, got a better accuracy as the LDR increases its resistance quicker, than rising edge. I attached the box to the
    side of the meter with double sided tape. Runs off a cheap everday mini USB plug 5v wall 240vAC PSU. Consumption is about 50ma!

    Testing :- Good accurate reads upto 30kwh, i.e great on domestic UK 240vac 80amp supply. Tested with lots of electric storage heaters,
    electric cooker, shower, ect all on! Got upto 18Kwh. Reading exactly the same as meter. Accuracy measured over 1 week was 0.2%.
    It could do with the LDR changing to a photo-transistor to get the timing perfect. On a pulse tester, I was getting +- 3.
    Never had a problem with any of the excellent Ciseco XRF modules, but beware the older ones being sold on Ebay, by ex-users,
    they are NOT all 5v tolerant! The easiest module is XBEE shaped and pinouts are similar. RTFM please! I have damaged
    units in my earlier days by not reading up on them. Various firmwares are available. All free.

    Further :- A master unit in my lounge works out and dislays and stores the data, the costs and other stuff using a Gameduino screen, with
    info speech for errors and warnings on an Emic sound unit. It also, on another secure other frequency XRF net work,
    controls the central heating, alarm system, reading temperatures int and ext, light level, motion detection devices, door
    and window sensors and RFID tag access to master. Later on, house access. All done through the excellent LLAP protocol
    and XRF variants. I might publish the master soon.

    Program :- Programmed using IDE 1.0.5-r2, size of program only 10,860 bytes, so can be done in smaller memory devices.

    Wriitten by:- Dave Stowe April 2014
    Copyright :- Dave Stowe, a disabled ex-industrial multiskilled engineer/programmer enjoying programming in C (well close enough) on Arduino’s.
    License :- This software is released under the DWYWWIIINRC License (Do Whatever You Want With It, It Is Not Rocket Science).
    Thanks to :- Jesper Eklunds, modified his program a lot! and to my super partner Leanda, who looks after and puts up with me.

    // Variables used for stats, see program for information
    int count = 0;
    int errors = 0;
    float wCurrent;
    float wAvg;
    float wTotal;
    unsigned long timeNow;
    unsigned long timeOld = 0.0;
    unsigned long timeStart = 0.0;
    float wMin = 10000.0;
    float wMax = 0.0;
    float sec = 0.0;
    float timeInterval = 0.0;
    boolean doFirst = true;
    boolean flash = true;
    boolean alive = true;
    boolean answerMaster = false;

    // Pin Assignments
    // Inputs
    const int LDRPin = 2; // Our LDR input triggers Int0

    // Outputs
    const int pulseledPin = 11; // Red LED
    const int powerledPin = 9; // Green LED
    const int CommsledPin = 10; // Blue LED
    const int SRFPower = 8; // Pin used to power up SRF
    const int error = 13; // Error LED

    // DS1307: SDA pin -> Arduino Digital 4, SCL pin -> Arduino Digital 5
    DS1307 rtc(4,5); // Initialise the DS1307 rtc board
    Time t; // t is name a struction to hold Time

    // Storage variables for the incoming data
    String XRF_id = “”; // the XRF id we recieved store
    String XRF_data = “”; // the XRF data we recieved store

    void setup() {
    rtc.halt(false); // Turn on the clock
    attachInterrupt(0, Calculate, FALLING); // LDR on Pin 2(int0), used to get pulses, fires interrupt, goes to function Calculate

    pinMode(pulseledPin, OUTPUT); //Set Red LED pin as an output
    pinMode(powerledPin, OUTPUT); // Set Green LED pin as output
    pinMode(CommsledPin, OUTPUT); // Set Blue LED pin as output
    pinMode(error , OUTPUT); // Set pin 13 as OUTPUT
    pinMode(SRFPower , OUTPUT); // Set Pin 8(SRF Power) as output
    digitalWrite(SRFPower, HIGH); // Turn on the SRF Power

    Serial.begin(115200); // Start the serial port for the SRF Communications, only active when pin 8 high

    digitalWrite(pulseledPin, LOW); // Turn off the red led
    digitalWrite(powerledPin,HIGH); // Turn on the green led
    digitalWrite(CommsledPin, LOW); // Turn off the blue led
    digitalWrite(error , LOW); // Turn off the error led
    // Send a start message with my time
    t = rtc.getTime(); // Get the time data into t
    String s = “aMRS”;
    if(t.hour < 10) s=s+"0";
    s = s + t.hour;
    if(t.min < 10) s=s+"0";
    if(t.sec = 12) { // Have we got twelve bytes?
    if (Serial.read() == ‘a’) { // is the first one an ‘a’?
    // Yes so read in the ID string 2 bytes
    digitalWrite(pulseledPin, LOW); // Turn off the red led
    digitalWrite(powerledPin, LOW); // Turn off the green led
    digitalWrite(CommsledPin,HIGH); // Turn on the blue led
    for (byte i = 0; i < 2; i++) XRF_id += char( Serial.read()); // Read in to get the XRF_id
    // Read in the data string 9 bytes
    for (byte i = 0; i = 0 && val 9 && val 99 && val 999 && val 9999 && val 99999 && val 0.1 ) { // If its greater than 0.1secs since last pulse, its a pulse
    timeOld = timeNow; // and store the time now for the next pulse check
    count++; // add the pulse to our count
    sec = ( timeNow – timeStart ) / 1000.0; // convert to seconds
    wTotal = count; // our total used is the pulse count. 1000 pulses = 1 Kw
    wAvg = 3600.0 * count / sec; // work out the average watts
    wCurrent = 3600.00 / timeInterval; // work out the current watts
    if ( wCurrent > wMax ) { wMax = wCurrent; }// store the maximum watts used if greater than before
    if ( wCurrent < wMin ) { wMin = wCurrent; }// store the mimimum watts used if lower than before
    flash = true;
    else { // the pulse is to short, so its an error
    digitalWrite(error, HIGH); // debug led on
    errors++; // increase the error count

    This has worked well for some time

Leave a Reply