You are on page 1of 4

Energy Monitoring System

Edsel Ian Fuentes, RME


Department of Electrical and Electronics Engineering
University of San Carlos – Technological Center
Cebu City, Philippines
BSEE-5

Abstract— The project aims to create a system that can In the Figure 1 below is the hardware used to measure for the
monitor energy,Use Contiki-NG, python, and Arduino electrical parameters
Genuino for the coding of the system. Arduino UNO Rev3,
telosB, Raspberry Pi, Zoul, and PZEM-004t was the
hardware used to create this system. PZEM-004t was the
module to measure the electrical parameters and Arduino
UNO Rev3 was used to obtain the electrical parameters
from PZEM-004t. Zoul sends the data to TelosB from
Arduino UNO Rev3 and the data are stored to Raspberry Pi
which serves as a data base for the electrical parameters
measured.. Arduino Genuino was used to program the
Arduino UNO Rev3, Contiki-was used to program telosB,
and python for the Raspberry Pi.
I. INTRODUCTION
The Internet of things (IoT) is the extension
of Internet connectivity into physical devices and everyday
objects. Embedded with electronics, Internet connectivity, and
other forms of hardware (such as sensors), these devices can
communicate and interact with others over the Internet, and
they can be remotely monitored and controlled.[1]
The definition of the Internet of things has evolved due to
Figure.1 PZEM-004t Module
convergence of multiple technologies, real- PZEM-004t is a multifunctional power monitoring
time analytics, machine learning, commodity sensors, module which can measure different electrical parameters. This
and embedded systems.[5] Traditional fields of embedded was used in the project to measure the different parameters to
systems, wireless sensor networks, control be obtain and displayed by Arduino UNO Rev3. Arduino UNO
systems, automation (including home and building Rev3, the 5V and GND is connected to the PZEM-004t and
automation), and others all contribute to enabling the Internet TelosB.Pin 1 and 0 are connected to TelosB in allowing it to
of things. In the consumer market, IoT technology is most obtain the electrical parameters coming from the PZEM-004t.
synonymous with products pertaining to the concept of the
"smart home", covering devices and appliances (such as
lighting fixtures, thermostats, home security systems and Figure 2 TelosB MTM-CM5000-MSP
cameras, and other home appliances) that support one or more
common ecosystems, and can be controlled via devices
associated with that ecosystem, such as smartphones and smart
speakers.
The IoT concept has faced prominent criticism,
especially in regards to privacy and security concerns related to
these devices and their intention of pervasive presence.[1]
II.METHODOLOGY
In creating the System, The following devices/hardware was
prepared;
 Arduino UNO Rev3 Serial.print(v);Serial.print("V; ");
 PZEM-004t Module
 TelosB float i = pzem.current(ip);
 Zoul if(i >= 0.0){ Serial.print(i);Serial.print("A; "); }
 Raspberry Pi.
float p = pzem.power(ip);
if(p >= 0.0){ Serial.print(p);Serial.print("W; "); }
The measuring of the electrical parameters was obtain
using PZEM-004t where voltage, current, active power and float e = pzem.energy(ip);
energy were measured. The data which is read by Arduino if(e >= 0.0){ Serial.print(e);Serial.print("Wh; "); }
UNO Rev3. Zoul was then used as a sending unit from the
obtained data from Arduino UNO Rev3 to TelosB. TelosB Serial.println();
Was used as an receiving unit to receive the data from Zoul }
and Raspberry pi was used as a database to store all
paramters. Refer to Figure 3 below for the system block
diagram. Next to follow would be the client code below in Code B

Code B
Figure 3 SYSTEM BLOCK DIAGRAM Client Code:

#include "contiki.h"
#include "net/routing/routing.h"
#include "random.h"
#include "net/netstack.h"
#include "net/ipv6/simple-udp.h"
#include "dev/serial-line.h"
Each of the devices was then program in order to perform #include <stdio.h>
its function. In the Code A Below is the program used for the #include "sys/log.h"
Arduino UNO Rev3 using Arduino Genuino #include "mysensor.h"
#define LOG_MODULE "App"
Code A #define LOG_LEVEL LOG_LEVEL_INFO
#define WITH_SERVER_REPLY 1
Program for Arduino UNO Rev3 : #define UDP_CLIENT_PORT 8765
#define UDP_SERVER_PORT 5678
#include <SoftwareSerial.h>
#include <PZEM004T.h> #define SEND_INTERVAL (5 *
CLOCK_SECOND)
PZEM004T pzem(10,11); // (RX,TX) connect to TX,RX of
PZEM static struct simple_udp_connection udp_conn;
IPAddress ip(192,168,1,1); int sendnot = 0;
static char str[32];
void setup() {
Serial.begin(9600); /*----------------------------------------------------------------------
pzem.setAddress(ip); -----*/
} PROCESS(udp_client_process, "UDP client");
PROCESS(test_serial, "Serial Part");
void loop() {
float v = pzem.voltage(ip); AUTOSTART_PROCESSES(&udp_client_process,&test_s
if (v < 0.0) v = 0.0; erial);
/*---------------------------------------------------------------------- // printf("Waiting ... ");
-----*/ // pzem_initialize();
static void
udp_rx_callback(struct simple_udp_connection *c, }
const uip_ipaddr_t *sender_addr,
uint16_t sender_port, /* Add some jitter */
const uip_ipaddr_t *receiver_addr, etimer_set(&periodic_timer, SEND_INTERVAL
uint16_t receiver_port, - CLOCK_SECOND + (random_rand() % (2 *
const uint8_t *data, CLOCK_SECOND)));
uint16_t datalen) }
{
PROCESS_END();
char buffer[32]; }
snprintf(buffer, sizeof(str), "%s\n", (char *)data); /*----------------------------------------------------------------------
// printf("%s",buffer); -----*/
// LOG_INFO_6ADDR(sender_addr); PROCESS_THREAD(test_serial, ev, data)
//#if LLSEC802154_CONF_ENABLED {
// LOG_INFO_(" LLSEC LV:%d", PROCESS_BEGIN();
uipbuf_get_attr(UIPBUF_ATTR_LLSEC_LEVEL));
//#endif for(;;) {
// LOG_INFO_("\n"); PROCESS_YIELD();
sendnot = 0; if(ev == serial_line_event_message) {
}
/*---------------------------------------------------------------------- sendnot = 1;
-----*/ snprintf(str, sizeof(str), "%s\n", (char *)data);
PROCESS_THREAD(udp_client_process, ev, data) //printf("received line, sending to air: %s\n", (char *)data);
{ }
static struct etimer periodic_timer; }
// static unsigned count; PROCESS_END();
uip_ipaddr_t dest_ipaddr; }

PROCESS_BEGIN();
Lastly the Server code is programmed so that
/* Initialize UDP connection */ TelosB will receive the data and uses the same port as Zoul
simple_udp_register(&udp_conn, UDP_CLIENT_PORT, which was the sending unit and its data was stored in
NULL, Raspberry Pi. Refer in Code C below.
UDP_SERVER_PORT, udp_rx_callback);
Code C
etimer_set(&periodic_timer, random_rand() %
SEND_INTERVAL); Server Code:
while(1) {.

PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&perio #include "contiki.h"


dic_timer)); #include "net/routing/routing.h"
#include "net/netstack.h"
if( sendnot #include "net/ipv6/simple-udp.h"
&&NETSTACK_ROUTING.node_is_reachable() && #include "sys/log.h"
NETSTACK_ROUTING.get_root_ipaddr(&dest_ipaddr)) { #define LOG_MODULE "App"
/* Send to DAG root */ #define LOG_LEVEL LOG_LEVEL_INFO
// LOG_INFO("Sending request %u to ", count);
// LOG_INFO_6ADDR(&dest_ipaddr); #define WITH_SERVER_REPLY 1
// LOG_INFO_("\n"); #define UDP_CLIENT_PORT 8765
// snprintf(str, sizeof(str), "hello %d", count); #define UDP_SERVER_PORT 5678
simple_udp_sendto(&udp_conn, str, strlen(str),
&dest_ipaddr); static struct simple_udp_connection udp_conn;
// count++;
} else { PROCESS(udp_server_process, "UDP server");
AUTOSTART_PROCESSES(&udp_server_process); III . CONCLUSIONS
/*----------------------------------------------------------------------
-----*/
static void The Internet of things (Iot) has a lot of applications
udp_rx_callback(struct simple_udp_connection *c, which be applied to different fields and disciplines. Energy
const uip_ipaddr_t *sender_addr, Monitoring is one great application for its capacity. In
uint16_t sender_port, creating a system for Iot, different hardware was used in order
const uip_ipaddr_t *receiver_addr, to obtain/measure, transmit/send, receive, and store. Each
uint16_t receiver_port, hardware uses different software in order to program. In this
const uint8_t *data, Project Raspberry Pi was used as a local server to store the
uint16_t datalen) data from the electrical parameters measured by the
{ multifunctional measuring device “PZEM-004t”. Other
// LOG_INFO("Received request '%.*s' from ", datalen, hardware was used as a sending unit like Zoul and TelosB as
(char *) data); a receiving unit.
printf("%.*s", datalen, (char *) data);
// LOG_INFO_6ADDR(sender_addr);
// LOG_INFO_("\n");
#if WITH_SERVER_REPLY
/* send back the same string to the client as an echo reply
*/
// LOG_INFO("Sending response.\n");
simple_udp_sendto(&udp_conn, data, datalen,
sender_addr);
#endif /* WITH_SERVER_REPLY */
}
/*----------------------------------------------------------------------
-----*/
PROCESS_THREAD(udp_server_process, ev, data)
{
PROCESS_BEGIN();

/* Initialize DAG root */


NETSTACK_ROUTING.root_start();

/* Initialize UDP connection */


simple_udp_register(&udp_conn, UDP_SERVER_PORT,
NULL,
UDP_CLIENT_PORT, udp_rx_callback);

PROCESS_END();
}
/*----------------------------------------------------------------------
-----*/

You might also like