ahmad AbdullahAhsan Naveed
Published

Electric Limiter

We are building a device through which we can monitor the usage of electricity of a device and also tell the device to remind us if that app

IntermediateFull instructions provided628
Electric Limiter

Things used in this project

Hardware components

Voltage Sensor
×1
current sensor
×1
Breadboard (generic)
Breadboard (generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×1
4-Channel 16-Bit ADC for Raspberry Pi (ADS1115)
Seeed Studio 4-Channel 16-Bit ADC for Raspberry Pi (ADS1115)
×1
Resistor 10k ohm
Resistor 10k ohm
×2
Capacitor 10 µF
Capacitor 10 µF
×1
Resistor 100 ohm
Resistor 100 ohm
×1
Esp8266 board
×1

Story

Read more

Schematics

Circuit Diagram

Code

Untitled file

C/C++
#include <Adafruit_Sensor.h>
#include <Wire.h>


#include <Adafruit_ADS1X15.h>

#include "grandeur.h"




/* Import WIFI library */
#include <ESP8266WiFi.h>

Adafruit_ADS1115 ads;
int16_t ad1=ads.readADC_SingleEnded(0);
int16_t ad2=ads.readADC_SingleEnded(1);
double c;
double v;
int timestamp;

              // Create an instance

/* SSID and Password */
#define ssid "Ahmed’s iPhone (2)"
#define password "12345431"



String apiKey = "grandeurl7o63r4a00dx0ljlc3le1j6a";
String deviceID = "devicel7o63s1000e00ljldw837ilc";
String token = "d4f35653f5a79cdb9dcec5464b1698f16b39a3c0777d65428738921614b3225f";


Grandeur::Project project; 
Grandeur::Project::Device device;

void statusChange(bool status) {
    switch(status) {
        case CONNECTED:
          /* Device connected to the cloud */
          Serial.println("Device is connected to the cloud.");
          return;

        case DISCONNECTED:
          /* Device disconnected from cloud */
          Serial.println("Device is disconnected from the cloud.");
          return;
    }
}

float readcurrent() {

   

    /* Reading temperature using DHT library */
      c=ads.computeVolts(ad2);  // Calculate Irms only
      c=((2^1480)*c)/3.3;

    /* Checking if temp value is not a number */
    if (isnan(c) ) {
        Serial.println("Failed to read the data!");   
    }

     Serial.print((c*230.0)+1);         // Apparent 

  Serial.print(" ");
  Serial.println("Irms");   
  c=(c*230.0)+1;
    return c;
    
}


float readvoltage() {

    

    /* Reading temperature using DHT library */
      v=ads.computeVolts(ad2);  // Calculate Irms only
      v=((2^1480)*v)/3.3;

    /* Checking if temp value is not a number */
    if (isnan(v) ) {
        Serial.println("Failed to read the data!");   
    }

     Serial.print((v*230.0)+1);         // Apparent 

  Serial.print(" ");
  Serial.println("Vrms");   
  v=((v*230.0)+1);
    return c;
    
}
void connectWifi() {
    /* Configure in WIFI client mode */
    WiFi.mode(WIFI_STA);

    /* Connect to a router */
    WiFi.begin(ssid, password);

    /* Wait for wifi to connect */
    while (WiFi.status() != WL_CONNECTED) {
        delay(500);
        Serial.print(".");
    }

    /* Print message */
    Serial.println("");
    Serial.println("WiFi connected");
}

void displayTemp(const char* code, int c,int v) {
    Serial.println(c);
    Serial.println(v);
}

/* Update Temperature */
void update_temp_handler1(const char* code, const char* c) {
    Serial.printf("Updated state is: %s\n", c);   

}
void update_temp_handler2(const char* code, const char* v) {
    Serial.printf("Updated state is: %s\n", v);   

}
void setup() {
    // Set the led pin as an output pin.
    Serial.println("fight");
    Wire.begin(D1,D2);
     Serial.begin(9600);
      ads.begin();

    pinMode(c, INPUT);
    pinMode(v, INPUT);
    
  
   /* Connect to wifi */
    connectWifi();

    /* Connect to Grandeur server */
    project = grandeur.init(apiKey, token);

    /* Detect connection status */
    project.onConnection(statusChange);

    /* Get reference to device */
    device = project.device(deviceID);

    device.data().on("current", update_temp_handler1);

    device.data().on("current", update_temp_handler2);

if (!ads.begin()) {
    Serial.println("Failed to initialize ADS.");
    while (1);
  }
     timestamp = millis();
     
  
}

// Loop function repeats the code in it indefinitely.
void loop() {
   if (millis() - timestamp > 3000) {  
    Serial.println("forget");
   device.data().set("c", readcurrent());  
   device.data().set("v", readvoltage());  
        timestamp = millis();
   
   }
   
    project.loop();
}

Credits

ahmad Abdullah

ahmad Abdullah

1 project • 1 follower
Ahsan Naveed

Ahsan Naveed

0 projects • 1 follower
A not very special guy just enthusiast about tech

Comments