Blynk and power electric consumption

Blynk and power electric consumption .
the electric meter emits 1 led pulse for every watt that measure
ATtiny85 detects the Led pulse using a sensor LDR , send to interrupt input of Arduino
sketch calculates the elapsed time between two pulses and calculates the power consumption
in the video we see a more elaborate version (rcwitch,lm35, and power consumption), look at the red widget (enel), that updates itself after a few seconds .

attiny85
LDR sensor
arduino uno
shield w5100

    #define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
    #include <SPI.h>
    #include <Ethernet.h>
    #include <BlynkSimpleEthernet.h>
    #include <SimpleTimer.h>
    
    // You should get Auth Token in the Blynk App.
    // Go to the Project Settings (nut icon).
    char auth[] = "xxxxxxxxxxxxxxxx";
    
    SimpleTimer timer;
    
    long pulseCount = 0;   
    //Used to measure power.
    unsigned long pulseTime,lastTime;
    
    //power and energy
    double power, elapsedkWh;
    
    //Number of pulses per wh - found or set on the meter.
    int ppwh = 1; //1000 pulses/kwh = 1 pulse per wh
    
    void setup()
    {
      Serial.begin(9600);
    
    // KWH interrupt attached to IRQ 1  = pin3
      attachInterrupt(1, onPulse, FALLING);
      
      Blynk.begin(auth);
     
      // Setup a function to be called every second
      timer.setInterval(1000L, sendUptime);
      
    }
    void sendUptime()
    {
      // You can send any value at any time.
      // Please don't send more that 10 values per second.
     
      Blynk.virtualWrite(1, power);
    }
    
    void loop()
    {
     Blynk.run(); // Initiates Blynk
      timer.run(); // Initiates SimpleTimer
     
    }
    
    // The interrupt routine
    void onPulse()
    {
    
    //used to measure time between pulses.
      lastTime = pulseTime;
      pulseTime = micros();
    
    //pulseCounter
      pulseCount++;
    
    //Calculate power
      power = (3600000000.0 / (pulseTime - lastTime))/ppwh;
      
      //Find kwh elapsed
      elapsedkWh = (1.0*pulseCount/(ppwh*1000)); //multiply by 1000 to pulses per wh to kwh convert wh to kwh
    
    //Print the values.
      Serial.print(power,4);
      Serial.print(" ");
      Serial.println(elapsedkWh,3);
    }
4 Likes

Wow, this looks like a real application!
Thanks for sharing. Seeing such projects inspires us to make Blynk better!

What are all the buttons used for? Do you control lights or electrical appliances?

I Pavel ,
I adapted small sketch to app Blynk , to check their operation . I then I joined them.
buttons control : lights , heating , dehumidifier , and ventilation
I have a photovoltaic, I control how much energy as it consumes and produces.
I am at home wireless automation system, the sketch that I use is adapted to my needs , I decided to publish more simple sketches that composed.
Thanks.

1 Like

Thank you for posting this kWh project.
i have almost the same, but not with Blynk but just an LCD and a Mega.(ethernet shield)
This is a nice start for me, and i just have to change some things because i use 2 sensors on an old ferraris meter ( turning wheel with black spot on it) The reason why i use 2 is because of my solar panels. When i produce more energy the i use the wheel turns the opposite way.
I will use this example to start and will post the result when it works :slight_smile:
Thanks!

Just noticed that your app is like 1 year old…