UbiMakerMaka Hernandez
Published © CC BY-NC-SA

Build an Energy Monitor Device Using a Particle Electron

Monitor your machine's energy consumption with this low-cost, Industrial Energy Monitor tutorial in just a few minutes.

BeginnerFull instructions provided3 hours2,239
Build an Energy Monitor Device Using a Particle Electron

Things used in this project

Story

Read more

Code

Code snippet #1

Plain text
// This #include statement was automatically added by the Particle IDE.
#include <Ubidots.h>

// This #include statement was automatically added by the Particle IDE.
#include <Current_Monitor.h>

#ifndef TOKEN
#define TOKEN "put_your_ubidots_token_here" // Put here your Ubidots TOKEN
#endif

Ubidots ubidots(TOKEN);
CurrentMonitor current;
double current_reading = 0;

void setup() {
    Serial.begin(9600);
    if(!current.initialize(0,0,0,0)){
        Serial.println("Initialize failed");
    }
    Particle.variable("Current", current_reading);
    delay(5000);
}

void loop() {
    if(current.deviceStatusReady){
        double c = current.readChannelCurrent(1);
        if(c != current.failedCommand){
            current_reading = c;
            Serial.println(current_reading);
            ubidots.add("Current", current_reading);  // Change for your variable name
            if(ubidots.sendAll()){
                // Do something if values were sent properly
                Serial.println("Values sent by the device");
            }
        }
    }
    delay(1000);
}

Code snippet #2

Plain text
// This #include statement was automatically added by the Particle IDE.
#include <Ubidots.h>

// This #include statement was automatically added by the Particle IDE.
#include <Current_Monitor.h>

#ifndef TOKEN
#define TOKEN "put_your_ubidots_token_here" // Put here your Ubidots TOKEN
#endif

Ubidots ubidots(TOKEN);
CurrentMonitor current;
double current_reading = 0;

void setup() {
    Serial.begin(9600);
    if(!current.initialize(0,0,0,0)){
        Serial.println("Initialize failed");
    }
    Particle.variable("Current", current_reading);
    delay(5000);
}

void loop() {
    if(current.deviceStatusReady){
        double c = current.readChannelCurrent(1);
        if(c != current.failedCommand){
            current_reading = c;
            Serial.println(current_reading);
            ubidots.add("Current", current_reading);  // Change for your variable name
            if(ubidots.sendAll()){
                // Do something if values were sent properly
                Serial.println("Values sent by the device");
            }
        }
    }
    delay(1000);
}

Credits

UbiMaker
53 projects • 231 followers
Maker @ ubidots.com
Contact
Maka Hernandez
29 projects • 124 followers
Contact

Comments

Please log in or sign up to comment.