Watt-a-save

by AndreiAnghel in Circuits > Wireless

697 Views, 21 Favorites, 0 Comments

Watt-a-save

WattASave pre evaluation
schema-initiala.jpg

The main purpose of this project is to monitor the energy consumption in a household so it can act as an intelligent switch and give feedback to the user on a website. The feedback is important as it will encourage responsible use of electrical power, reducing the cost of bills as proven here:

http://www.eci.ox.ac.uk/research/energy/downloads/...

This system can be set up to work for different applications related to home automation, such as smart lighting, presence detection, heating control, that is why we want to make the best out of all its features.

We will use a chipKIT WF32 to control the whole system and to send data to the cloud.

Pmod PMON1 will be used to acquire data about power consumption but we are still looking for a way to connect it to the WF32 board. (More details to be added).

Another useful module that will not be used on this first phase is the Pmod OLED that will display data directly to the user. The reason why we cannot connect it to the WF32 is that some required pins are not available. We will work for a demo on the MX3 board though.

In the initial phase of the project we will use three modules: Pmod TMP3, Pmod ALS and Pmod MAXSONAR and send the data acquired by those to the ubidots application.

You can have a quick preview at this link, on youtube: Watt a save pre evaluation video

Acquire Digilent Modules

DSC_0237.JPG
DSC_0235.JPG
DSC_0236.JPG

First of all we will need the following three modules: Pmod TMP3, Pmod ALS and Pmod MAXSONAR that will be connected to the chipkit WF32 development board. Pmod TMP3 will use the Wire library, the ALS will communicate using the SPI interface and the MAXSONAR will use the analog mode.

Connect the Modules to the WF32

DSC_0224.JPG

As we already know, Pmod TMP3 sensor is using the I2C interface so it will be connected to the SCL and SDA pins of the WF32; The MAXSONAR is using the ANALOG mode, therefore we will connect the AN pin to A0 and define it in the headers and the RX will be connected pin 39 of the board. Using the SPI interface, the ALS module will be connected to pins 10(SS), 11(NC),12(MOSI) and 13(SCK) of the WF32.

The Code for TMP3

DSC_0235.JPG

In order to establish a communication between the TMP3 module and the WF32 board, be sure to include the Wire library in the header of your main code, as such :

#include

To initialize it, add this line in the setup() function:

Wire.begin();

After this has been initialized, we should write the code for the reading of the values:

Wire.beginTransmission(0x48); // 0x48 is the address selected by the jumpers on the module. There are 8 different addresses that can be changed.
Wire.send(0x00); Wire.endTransmission();

Wire.requestFrom(0x48, 1); // request 6 bytes from slave device #2

while(Wire.available()) // slave may send less than requested

{

int c = Wire.receive(); // receive a byte as character

Serial.println("Temp value: "); Serial.println(c);

}

The Code for ALS

DSC_0236.JPG

The Ambient Light Sensor (ALS) is using the SPI interface. therefore we must make some definitions in the headers for the connected pins.

#include

DSPI0 dspi;
int lightLevel; int lightData[16];

In the setup() function, add these following lines:

pinMode(SS, OUTPUT);
pinMode(MISO, INPUT);

pinMode(SCK, OUTPUT);

digitalWrite(SS, HIGH);

dspi.setPinSelect(SS);

dspi.begin(SS);

dspi.setTransferSize(DSPI_16BIT);

dspi.setSpeed(2000000);//2 MHz

In the loop() function we should add the following lines.

dspi.setSelect(LOW);

lightLevel = dspi.transfer(0);

lightLevel = lightLevel>>4;

dspi.setSelect(HIGH);

Serial.println("LIght level: ");
Serial.println(lightLevel);

lightLevel =0;

The Code for MAXSONAR

DSC_0237.JPG

In this case, the MAXSONAR will use the analog mode to communicate with the board therefore we must make the following definitions.

-----------------------------------headers----------------------------------------------------------

#include

#define ANpin A0
#define RXpin 39 #define TXpin 40 #define PWpin 3

uint16_t data;
MAXSonar sensor;

const UNIT units = CM;
const MODE mode = ANALOG;

---------------------------------------------------------------------------------------------------------

--------------setup()----------------------------------------------------------------------------------

pinMode(RXpin, OUTPUT); //Make sensor's RX pin an output from the uC
digitalWrite(RXpin, LOW); //write sensor's RX pin low to stop sensor activity

pinMode(PWpin, INPUT);

delay(250); //allow for powerup before sending RX command

digitalWrite(RXpin, HIGH);

delay(49); //delay for calibration after RX pin is left open or held high

delay(49); //delay for initial range reading;

Serial.println("Getting Range Data:");

------------------------------------------------------------------------------------------------------------

-----------------loop()-----------------------------------------------------------------------------------

sensor.begin(ANALOG, RXpin);

data = sensor.getDistance(ANALOG, ANpin, units);

sensor.end(RXpin);

Serial.println("Distance level: ");

Serial.println(data);

-------------------------------------------------------------------------------------------------------------

The Code for the Wifi Data

screenshot.png

After we connected all the sensors and we acquired the data we needed, we should ultimately send it to the cloud. For this, we used the IoT solution provided by ubidots.com. We can find there all the resources we need for developing and I will show a quick demo to use it in this step.

First of all, you should create an account on ubidots.com that will provide you with 30000 free "dots" per month. Each "dot" represents a data packet that you sent from the selected device. After the creation of the account, they show a quick tutorial to create projects and variables where you will store the data. More details to come.

After the creation of these variables, we will generate a token to use in the following code and also include the unique identifiers of the variables(IDs). To establish a connection to the ubidots.com host, we can use the code provided by Digilent on http://digilentinc.com/Products/Detail.cfm?NavPath...

After including the correct ssID and password, we can establish a connection and then include the two functions that will keep the connection alive and store data by sending POST requests to the ubidots app. These functions can be found in the attached document, functions.c.

In the headers, we should initialize the variables to store the IDs of the variables on the ubidots app and the token generated on the ubidots account.

Example for the variables I used:

String token="whXIEUtXJUysPxCxnidR8TUXZyW2jobjGQH8cEqvVDplf7tLmlAaBqjpQQWL";
String idTemp="552fb77076254275b35206d0";

String idLight="55300b317625426c4337e819";

String idPresence="55300c457625426ab95475e0";

After acquiring data from each sensor, to send it we will call the save_value() function with their specific arguments.

For instance, for the MAXSONAR, we will display on the serial monitor the data after it was sent to the ubidots app.

if(save_value(String(data),idPresence))

{

Serial.println("Distance level: ");

Serial.println(data);

}

Downloads

The End

This is it for the moment. There will be more details to come in the future as we find more improvements for the code to make it more efficient.