Read Your Main Power Electricity Meter (ESP8266, WiFi, MQTT and Openhab)

20,212

57

11

Introduction: Read Your Main Power Electricity Meter (ESP8266, WiFi, MQTT and Openhab)

About: I like to combine electronics like Arduino's, ESP8266 etc with 3D designing and 3D printing.

In this Instructable you find out how I read my Main Electricity Power use of my house and publish it via an ESP8266, Wifi, MQTT in my Openhab Home Automation.

I have a 'smart meter' ISKRA Type MT372, however it has no easy possiblility to export the data. Therefore I used the LED pulses to read the current Power, the LED pulses 1000 times for 1 kW/h.

Step 1: Principle Scheme

The pulses are detected by an ESP8266. However, you need a good and clear '0' and '1'. The pulses are quite weak so I needed some suitable electronic components.

Phototransistor

A photoresistor is not fast enough to detect the short and weak pulses of red light. Based on this Youtube video I choose a phototransistor. By adding a 2M Ohm resistor I could reach about 2V.

Comparator

However, to ensure a clear '0' and '1' I choose to add a LM293 comparator. By connecting a 0.6 V to Vin and the phototransistor the Vref, I got a positive signal in the dark, and a negative signal at the pulse. The appropiate voltages were found by using potentiometers for the Vin and the Vref voltage. With the comparator, I used a 300K resistor.

By using a pull-up resistor on the output, I could get an output difference of almost 3.3V.

The output is shown at the oscillope screen.

ESP8266

The ESP8266 detects the low voltage when there is a pulse. It sends the output data to my MQTT broker. The data is received by:
- Openhab2
- Node-red via which the data is uploaded to Thingspeak

Step 2: Components

The main components I used:

- 3DU5C Phototransistor (see video for explanation)

- LM293 Comparator

- ESP-01

- several resistors

- prototype PCB

- Buck converter. I use my router power supply of 12V and found out that a LM1117 is not very efficient and gets quite hot.

- ABS box

Step 3: Programming

The program is published on my Github: https://github.com/Wim3d/Main_power_meter

See the scheme for the outline of the program and the method the power is calculated.

I program my ESP-01 via a modified USB-programmer. I soldered a button switch between RST and GND forn an easy reset and a slide switch between GPIO0 and GND to boot in in flash mode.

Step 4: Assembling

Al the parts are soldered to a prototype PCB.

See the pictures and the scheme for explanation.

Blue LED: the blue LED is attached to the output signal of the LM293 comparator an lights independent from the ESP8266.
If there is no pulse (dark), the voltage output from the phototransistor circuit is low, therefore Vref < Vin (steady voltage of 0,6V) and the output of the LM293 is high, no current flows to VCC and the blue LED is OFF.

If there is a pulse (light), the output from the phototransistor circuit is higher (ca. 1.5V) therefore Vref ? Vin (steady voltage of 0.6V) and the output of the LM293 is low, so current flows from VCC and the blue LED is ON.

Green LED: the green LED is attached to GPIO0 of the ESP8266 and pulses if the ESP8266 has detected a good pulse.

Step 5: Mounting to the Electricity Meter

I used some sticky putty for posters to mount the PCB in the box and the box to the meter, not to damage the meter. It is important to drill a hole at the exact position of the LED. Bend the phototransistor pointing down to the LED.

Step 6: Powering Up

I used some more sticky putty to prevent ambient light shining into the phototransistor as I opened the case in daylight. Drill a small hole in the lid to see the LEDs blink (not on the photos).

Read the values in Openhab to get these cool graphs!

Arduino Contest 2017

Participated in the
Arduino Contest 2017

Be the First to Share

    Recommendations

    • First Time Author Contest

      First Time Author Contest
    • DIY Summer Camp Contest

      DIY Summer Camp Contest
    • Maps Challenge

      Maps Challenge

    11 Comments

    0
    Mads B
    Mads B

    7 months ago

    Hi Wim3d, Very nice project and instructions, i have already build it and are currently testing against my electricity company readings, it seems that im always on the low side by between 2-7%.

    Maybe my meter is pulsing to fast, how fast can this count???, my energy meter (LANDIS+GYR E120) pulses 10000/kwh with current fuses gives 70 pulse/sec at full load

    Thanks Mads

    0
    Wim3d
    Wim3d

    Reply 7 months ago

    Dear Mads, thanks for your comment.
    I had some disturbation with exterior light and therefor do a check on the pulse length. In my meter, the pulse length was contant (38 ms as far as I could see). To fit 70 pulses in a second, your meter will have shorter pulses than 38 ms. Maybe the pulselength changes at different frequencies. I suggest to change the minimal pulse length (PULSE_MIN_LENGTH in line 18 of my code) to 5 ms. Otherwise you can eliminate the check on pulse length (in my code the IF statement in line 98 and ELSE in line 103) at all.
    If measuring speed is the issue, you can work with interrupts, which results in a much higer measuring speed. I can help you with a code for that. I use that in another project (not on Instructables yet)

    0
    Mads B
    Mads B

    Reply 7 months ago

    Hi Wim3d, thank you for replying :-)
    I my pulse length is 5ms, so i tweaked the setting to fit this.
    I found the limiting factor to be a 100ms delay

    digitalWrite(LEDPIN, HIGH); // blink led
    delay(100); <-----------------------THIS DELAY
    digitalWrite(LEDPIN, LOW);

    The calc 3600000ms / 105ms = 34285 pulse/hourhour = 3428.5 watt max reading
    Because of this every time our consumption was higher then this, the counter was reading wrong.

    I changed the delay value to 5ms
    Then calc 3600000ms / 10ms = 360000 pulse/hour = 36000watt max reading

    Now my measurements is the same as the electricity company readings :-)

    0
    Wim3d
    Wim3d

    Reply 7 months ago

    Thanks for your reply, I'm glad it worked out this way.

    0
    frank.carius
    frank.carius

    1 year ago

    Only a short hint: You have a "Smart Meter". Look at the upper right area and you find a round metal plate with two holes in the middle. These are IR-Diodes. One for receiving and one for sending. Use a smartphone and make a visio to see, if the right one is sending every second. I have a similar power meter and the right one is sending a full "SML-Datagram" with consumption, voltage, current, and may more. And you can use a magent to mount a IR-LED.
    Have a look at the tasmota firmware. (german: https://forum.creationx.de/forum/index.php?thread/1095-d0-z%C3%A4hler-sml-auslesen-mit-tasmota/) maybe you can simply use it with a transistor to read all data instead of counting flashes :-)

    Frank

    0
    Wim3d
    Wim3d

    Reply 1 year ago

    Thanks for the tip. I checked this, but found out that in my version of the power meter the IR communication is not implemented, apparently it is quite a basic version, only with holes, bu no IR-LEDs. In the mean time I got a newer power meter, so I can not review this point. My newer power meter has more advanced communication, but also this blinking red LED, which I use again.

    0
    tralfazy
    tralfazy

    3 years ago

    Nice one!

    Edit needed.. change your text where you called the phototransistor a photoresistor? (in 6 places). It's an important difference. I know. I tried to use a photoresistor to make a tachometer but it's too slow to handle that job.

    0
    Wim3d
    Wim3d

    Reply 3 years ago

    Thanks a lot for pointing at these errors. That is exactly why I used a phototransistor.

    0
    PhilTee
    PhilTee

    3 years ago

    Fantastic idea! I'd been thinking about trying to sniff the wireless data. This is much better. Well done.

    0
    Wim3d
    Wim3d

    Reply 3 years ago

    Thank you!