Urban Edge Smart Campus

Smart Campus solution to Monitor Crowd Movement and Energy

IntermediateFull instructions providedOver 2 days260
Urban Edge Smart Campus

Things used in this project

Story

Read more

Schematics

Powermonitoring schematic

Power monitoring

MMwave schematic

Fall and human presence MMwave schematic

Code

PowerCode

C/C++
#include<WiFi.h>; 
#include<DHT.h>; 
#include<AWS_IOT.h>; 
#include "EmonLib.h"

#define WIFI_SSID "ReneraiPhone" // SSID of your WIFI 
#define WIFI_PASSWD "renera97" //your wifi password 
#define CLIENT_ID "ESP32_Client"// thing unique ID, this id should be unique among all things associated with your AWS account. 
#define MQTT_TOPIC "$aws/things/ESP32/shadow/name/ESP32" //topic for the MQTT data 
#define AWS_HOST "akx1mya7kuo6k-ats.iot.ap-southeast-1.amazonaws.com" // your host for uploading data to AWS

unsigned long lastTime = 0;
unsigned long timerDelay = 3000;
unsigned long lastmillis = millis();

EnergyMonitor emon;
#define vCalibration 115.9
#define currCalibration 11.3
float kWh = 0;

AWS_IOT aws;
void setup(){
  Serial.begin(9600);
  emon.voltage(35, vCalibration, 1.7); // Voltage: input pin, calibration, phase_shift
  emon.current(34, currCalibration); // Current: input pin, calibration.
  Serial.print("\nInitializing thing ESP32\n");
  Serial.print("\n  Initializing WIFI: Connecting to ");
  Serial.println(WIFI_SSID);
  WiFi.begin(WIFI_SSID, WIFI_PASSWD);
  Serial.print("  ");
  while(WiFi.status() != WL_CONNECTED){
    Serial.print(".");
    delay(500);
  }
  Serial.println("\n  Connected.\n  Done");
  Serial.print("\n  Initializing Power Monitoring...");
  Serial.println("  Done.");
  Serial.println("\n  Initializing connetction to AWS....");
  if(aws.connect(AWS_HOST, CLIENT_ID) == 0){ // connects to host and returns 0 upon success
    Serial.println("  Connected to AWS\n  Done.");
  }
  else {
    Serial.println("  Connection failed!\n make sure your subscription to MQTT in the test page");
  }
  Serial.println("  Done.\n\nDone.\n");
}
void loop(){
//power calculations
    emon.calcVI(20, 2000); // Calculate all. No.of half wavelengths (crossings), time-out. This is FIXED 
    float voltage = emon.Vrms;
    float current = emon.Irms;
    float power = emon.apparentPower;
    kWh = kWh + emon.apparentPower*(millis()-lastmillis)/3600000000.0; //(1 hour = 3.6x10^9 microseconds)

  
  if(voltage == NAN || current == NAN){ // NAN means no available data
    Serial.println("Reading failed.");
  }
  else{
    //create string payload for publishing
    String voltage_current = "Vrms: ";
    voltage_current += String(voltage);
    voltage_current += "V Irms: ";
    voltage_current += String(current);
    voltage_current += "A Power: ";
    voltage_current += String(power);
    voltage_current += " W";   
   
    char payload[40];
    voltage_current.toCharArray(payload, 40);
    Serial.println("Publishing:- ");
    Serial.println(payload);
     if(aws.publish(MQTT_TOPIC, payload) == 0){// publishes payload and returns 0 upon success
      Serial.println("Success\n");
    }
    else{
      Serial.println("Failed!\n");
    }
  }
delay(1000);
}

Credits

NARENDRAN

NARENDRAN

20 projects • 22 followers
Sharen Perera

Sharen Perera

0 projects • 1 follower
Yazan Mansour Aldali

Yazan Mansour Aldali

0 projects • 0 followers
Rohit Thomas

Rohit Thomas

1 project • 0 followers
Kannan Uthaya Kumar

Kannan Uthaya Kumar

0 projects • 0 followers
Ravivarma Sivathasan

Ravivarma Sivathasan

0 projects • 1 follower
Sarim Ahmed Khalil

Sarim Ahmed Khalil

0 projects • 1 follower

Comments