Tutorial Arduino: How to measure an apartment electrical consumption – Misurare il consumo energetico di un appartamento.

Scritto da Alessandra De Rosa on . Postato in Formazione, Prodotti, Progetto Leonardo da Vinci, Servizi, Tutorials Arduino

The apartment for testing is represented here:

arduino appartamento progetto

The components we will be using:

  • 1 arduino
  • 6 xbees
  • 6 breadboards
  • 11 relays
  • 6 ac current sensors
  • 1 display

The main sketch for this is :

arduino components project 1

arduino components 2

The project has 2 separated parts, the first is the main one, which has the arduino and the xbee to receive the data from all the other sensors in the apartment, the second is used in every division.

The first one is represented here :
 arduino_components_stanza2

This one is where we have the sensor measuring the energy usage at all the apartment, and the display.

This circuit controls all the apartment energy consumed.

The Second one is represented here :

 arduino_components_stanza3

In this one we have and xbee sending data and controlling the relays.

The relay control on the divisions is made by the arduino, he is the one who checks if everything is ok and if it needs to turn OFF anything or not.

The receiving and sending of the data is made in turns, arduino will receive the data from one room, analyze it , store it and then send the option (ON or OFF) to the correspondent xbee.

All these steps are used for every single xbee in the apartment.
After receiving and treating the data arduino will show for 25 seconds, the data for every room in the display and the generic one too.

The logic used consists of:

1- Receiving and processing the  data from:

                – Kitchen

                – living room

                – Bedroom

                – WC

                – Garage

2- If one of the divisions is not communicating -> breaks and tries again.

3- While( count != 25000 ) // Display divisions-> 25000 loops = 25 seconds

{

. Displays the data

}

The code we wrote:

<LiquidCrystal.h> // library for the LCD

LiquidCrystal lcd(7,6,5,4,3,2); // pins for the LCD


int an0= 0; // A0- Garage                 5 (house division number)
int an1= 1; // A1- Kitchen                1
int an2= 2; // A2- Living room         2
int an3= 3; // A3- Room                    3
int an4= 4; // A4- Toilet                    4
int an5= 5; // A5- sensor
int button= 0;
int received;

void setup()
 {
  Serial.begin(9600);
  lcd.begin(16, 2);
  pinMode(9, INPUT); // Button
  pinMode(13,OUTPUT); // Relay
}
void loop() 
{
int storage [5]; // saves each house division's information
int cnt=0; // makes the storage get the next division

for(cnt=0; cnt<5 ;cnt++)
{
received= Analog.read(cnt); // information about a house division
  if (received == 0)
    break;
storage[cnt]= received; // saves that information
}

// LCD:
lcd.setCursor(0,0);
lcd.print("Apartment energy");
lcd.setCursor(0,1);
lcd.print(analogRead(5));



if(digitalRead(9)==HIGH) // if the button gets clicked
button++;


if(button==1) // Kitchen
{
lcd.setCursor(0,0);
lcd.print("Room 1 is using");
lcd.setCursor(0,1);
lcd.print(storage[0]);
}

if(button==2) // Living room
{
lcd.setCursor(0,0);
lcd.print("Room 2 is using");
lcd.setCursor(0,1);
lcd.print(storage[1]);
}
if(button==3) // Room
{
lcd.setCursor(0,0);
lcd.print("Room 3 is using");
lcd.setCursor(0,1);
lcd.print(storage[2]);
}
if(button==4) // toilet
{
lcd.setCursor(0,0);
lcd.print("Room 4 is using");
lcd.setCursor(0,1);
lcd.print(storage[3]);
}
if(button==5) // Garage
{
lcd.setCursor(0,0);
lcd.print("Room 5 is using");
lcd.setCursor(0,1);
lcd.print(storage[4]);
}
}


17 July 2014

Alexandre Leitao

Gonçalo Neto

Tutorial Arduino: How to control system energy usage

Scritto da Alessandra De Rosa on . Postato in Formazione, Prodotti, Servizi, Tutorials Arduino

This project consists on controlling the usage of energy on the system.

It works like the electric entry in your home. It has an emergency kill switch in case of a short circuit.

After a couple of seconds it tries to reconnect the switch.

For the whole project we used:

-1 Arduino uno

-1 Breadboard

-2 Potentiometer

-1 16 pin display

-3 Resistances

-1 Buzzer

-1 Relay srd-05vdc-sl-c

-2 Leds

The first step is connecting and testing the display.

arduino display connection

arduino display connections

As you can see on the sketch and picture above it is quite simple to connect, it takes 3 + 5v cables to power the display, 3 grounds as well and 6 to display the data.

Another important thing is the potentiometer to be able to control the brightness and contrast of the display.

The code we wrote for this was:

lcd.print("Step One:");
lcd.SetCursor(0,1);
lcd.print("Complete!");






The second step after you test all the circuit with the LCD is to connect another potentiometer and a relay.

This time the potentiometer is sending the values towards arduino to let it control the relay ON or OFF.

We will use this potentiometer to simulate the current in the system.

 arduino potentiometer and relay

arrduino potentiometer and relay

The part of the code  that controls what happens in case of 99 % of the charge and 100% represents overcharge in our sketch.

The third part is implementing a LED to the system.

The relay controls the energy on the bottom energy line so the led will be connected to that line, to simulate a light in the room.

The sketch and picture for this are :

 arduino led

arduino led

The code:

  val_sim=analogRead(5);
  val_sim*=100;
  val_sim/=1024;
  val_fin=val_sim; // in percentage
  Serial.println(val_sim);
  lcd.setCursor(0,0);
  lcd.print("Voltage usage   ");
  lcd.setCursor(0,1);
  lcd.print("value : ");
  lcd.print(val_fin);
  lcd.print(" %   ");
  if(val_fin &gt; 90.0 &amp;&amp; val_fin &lt; 99.0)
  {
    tone(buzzer,ton_e,1000);
    //noTone(buzzer);
    tone(buzzer,ton_e,1000);
    lcd.setCursor(0,0);
    lcd.print("Warning!!!      ");// atenzione!!!
    lcd.setCursor(0,1);
    lcd.print("High voltage!!! "); 
    delay(2000);
    lcd.setCursor(0,0);
    lcd.print("Reduce Voltage  "); // system off :restart
    lcd.setCursor(0,1);
    lcd.print("Value &lt; 90 %    "); 
    delay(2000);
  }
  if(val_fin &gt; 99.0)
  {
    lcd.setCursor(0,0);
    lcd.print("                ");
    lcd.setCursor(0,1);
    lcd.print("                ");
    lcd.setCursor(0,0);
    lcd.print("Overcharge!     ");
    lcd.setCursor(0,1);
    lcd.print("System : Stop   ");
    digitalWrite(rele,LOW); 
    tone(buzzer,ton_e,2000);
    delay(2500);
    lcd.setCursor(0,0);
    lcd.print("Reduce Voltage  ");
    lcd.setCursor(0,1);
    lcd.print("Value &lt; 90 %    ");
    delay(5000);
    lcd.setCursor(0,0);
    lcd.print("Waiting: 5 sec  ");
    lcd.setCursor(0,1);
    lcd.print("System : Restart");
    lcd.setCursor(0,0);
    lcd.print("Waiting: 4 sec  ");
    lcd.setCursor(0,1);
    lcd.print("System : Restart");
    delay(1000);
    lcd.setCursor(0,0);
    lcd.print("Waiting: 3 sec  ");
    lcd.setCursor(0,1);
    lcd.print("System : Restart");
    delay(1000);
    lcd.setCursor(0,0);
    lcd.print("Waiting: 2 sec  ");
    lcd.setCursor(0,1);
    lcd.print("System : Restart");
    delay(1000);
    lcd.setCursor(0,0);
    lcd.print("Waiting: 1 sec  ");
    lcd.setCursor(0,1);
    lcd.print("System : Restart");
    delay(1000);
    lcd.setCursor(0,0);
    lcd.print("Waiting: 0 sec  ");
    lcd.setCursor(0,1);
    lcd.print("System : Restart");
    digitalWrite(rele,HIGH);
  



The last piece of the whole puzzle is adding 2 more components, a buzzer and another led.

The led is controlled by the voltage simulated with the second potentiometer, and the buzzer emits sounds as soon as it has an overcharge.

This is how our final project looks like:

arduino buzzer and led

arduino buzzer and led

The whole code for this is:

#include &lt;LiquidCrystal.h&gt;
&nbsp;
int buzzer = 12;
int rele = 11;
int ton_e = 1047;
&nbsp;
LiquidCrystal lcd(7,6,5,4,3,2);
&nbsp;
void setup()
{
 lcd.begin(16,2);
&nbsp;
 pinMode(buzzer,OUTPUT);
 pinMode(rele,OUTPUT);
 pinMode(5,INPUT);
&nbsp;
&nbsp;
&nbsp;
 Serial.begin(9600);
}
&nbsp;
void loop()
{
  float val_sim=0.0;
  float val_fin=0;
  digitalWrite(rele,HIGH);
&nbsp;
   lcd.setCursor(0,0);
  lcd.print("HydraSolutions  ");
  lcd.setCursor(0,1);
  lcd.print("System: Starting");
  delay(2500);
&nbsp;
  for(;1;)
  {
  val_sim=analogRead(5);
&nbsp;
  val_sim*=100;
  val_sim/=1024;
&nbsp;
  val_fin=val_sim; // in percentage
&nbsp;
  Serial.println(val_sim);
  lcd.setCursor(0,0);
  lcd.print("Voltage usage   ");
  lcd.setCursor(0,1);
  lcd.print("value : ");
  lcd.print(val_fin);
  lcd.print(" %   ");
&nbsp;
  if(val_fin &gt; 90.0 &amp;&amp; val_fin &lt; 99.0)
  {
    tone(buzzer,ton_e,1000);
    //noTone(buzzer);
    tone(buzzer,ton_e,1000);
    lcd.setCursor(0,0);
    lcd.print("Warning!!!      ");// atenzione!!!
    lcd.setCursor(0,1);
    lcd.print("High voltage!!! "); 
    delay(2000);
    lcd.setCursor(0,0);
    lcd.print("Reduce Voltage  "); // system off :restart
    lcd.setCursor(0,1);
    lcd.print("Value &lt; 90 %    "); 
    delay(2000);
  }
  if(val_fin &gt; 99.0)
  {
    lcd.setCursor(0,0);
    lcd.print("                ");
    lcd.setCursor(0,1);
    lcd.print("                ");
&nbsp;
    lcd.setCursor(0,0);
    lcd.print("Overcharge!     ");
    lcd.setCursor(0,1);
    lcd.print("System : Stop   "); 
    digitalWrite(rele,LOW); 
   
    tone(buzzer,ton_e,2000);
    delay(2500);
&nbsp;
&nbsp;
    lcd.setCursor(0,0);
    lcd.print("Reduce Voltage  ");
    lcd.setCursor(0,1);
    lcd.print("Value &lt; 90 %    "); 
    delay(5000);
    lcd.setCursor(0,0);
    lcd.print("Waiting: 5 sec  ");
    lcd.setCursor(0,1);
    lcd.print("System : Restart");   
    delay(1000);
    lcd.setCursor(0,0);
    lcd.print("Waiting: 4 sec  ");
    lcd.setCursor(0,1);
    lcd.print("System : Restart");   
    delay(1000);
    lcd.setCursor(0,0);
    lcd.print("Waiting: 3 sec  ");
    lcd.setCursor(0,1);
    lcd.print("System : Restart");   
    delay(1000);
    lcd.setCursor(0,0);
    lcd.print("Waiting: 2 sec  ");
    lcd.setCursor(0,1);
    lcd.print("System : Restart");   
    delay(1000);
    lcd.setCursor(0,0);
    lcd.print("Waiting: 1 sec  ");
    lcd.setCursor(0,1);
    lcd.print("System : Restart");   
    delay(1000);
    lcd.setCursor(0,0);
    lcd.print("Waiting: 0 sec  ");
    lcd.setCursor(0,1);
    lcd.print("System : Restart");   
&nbsp;
    digitalWrite(rele,HIGH);
  }
  }
}




July 14th 2014

Alexandre Leitao

Gonçalo Neto

Arduino tutorial: a voltage spike simulation.

Scritto da Alessandra De Rosa on . Postato in Formazione, Prodotti, Servizi, Tutorials Arduino

For this tutorial we are going to simulate a voltage spike using the potitiometer.

The logic is the 0 value returned by the potenciometer is “equal” to 0v and the [1000-1023] is “equal” to 5V and we are going to consider this set of values a voltage spike.

So for this we used:

  • Arduino uno
  • Breadboard
  • 1 Led
  • 1 resistance
  • 2 potentiometer
  • 1 relay SRC-05VDC-SL-C

 

The Relay uses a digital port and we use a analog port to receive and understand if the returned value is equal to a spike.

The code to acheive this is:

int rele=11;
int signal=0;
int volt=3;

void setup()
{
  pinMode(rele,OUTPUT);
  pinMode(signal,INPUT);
  pinMode(volt,INPUT);
  Serial.begin(9600);
}
void loop()
{
  int x=0;
  while(1) 				//keep receiving the "voltage"
  {
  digitalWrite(rele,HIGH);			
  x = analogRead(volt);			//reading the voltage
  Serial.println(x);
  if(x>1000 || x < 5)			//test if it is a pick of tension
  {
   emergency_stop();			//if it is emergency stop
   delay(500);
   continue;
  }
  else
   {
     digitalWrite(rele,HIGH);
     delay(500);
   }
}
}
void emergency_stop()
{
  digitalWrite(rele,LOW);
}
 

 

In this code the logic is having an infinite loop running inside the loop function, with this we can always be receiving the “voltage” simulated by the potentiometer on the right.

The left potentiometer is adjusting the brightness of the led.

 

 The picture of our setup:

 arduino voltage spike

And here is the sketch:

arduino voltage spike

Alexandre Leitao

Gonçalo Neto

 

Arduino tutorial: Light lightness control.

Scritto da Alessandra De Rosa on . Postato in Formazione, Prodotti, Servizi, Tutorials Arduino

In this tutorial, we’re simply going to control the led’s lightness with the following components:

  • Arduino Uno
  • Breadboard
  • 1 Led
  • 1 Resistance
  • 1 Potentiometer
  • 1 Relay SRD-05VDC-SL-C

Firstly we’ll have to do the basics, which is connecting the 5V and the GND in arduino uno with the VCC and GND. From there, we do the same to the relay, VCC with VCC and GND with GND, from the breadboard to the relay. Also, the IN1 in the relay gets connected to the digital port 11 in the arduino uno.

Secondly, the middle entrance on the relay gets connected to the VCC in the bread board and the other one gets connected to the first potentiometer’s entrance .

The third entrance goes to the GND. The second entrance connects a resistance, which is connected to the first led’s entrance and finally the second led’s entrance connects to the ground.

Basically, we simply round the potentiometer left or right depending on the light we want the led to show, from high to low.

In the code, it’s not necessary more than simply “digitalWrite(pinRelay,HIGH);”, this makes the relay turn ON and letting all the system work.

Here is the sketch of this project:

arduino light

These pictures above represent this project working:

arduino light off

arduino_light_2

As you can see, one of the pictures has the led with very low light, while in the second one the led’s light is higher.

 

Alexandre leitao

Gonçalo Neto

Arduino Tutorial: how to build an external power source.

Scritto da Alessandra De Rosa on . Postato in Formazione, Prodotti, Servizi, Tutorials Arduino

For this Tutorial we are going to make an external power source for arduino.

Those are the components we need:

-1 Arduino Uno

-1 Breadboard

-1 Led

-1 Resistance

-1 Diode

-1 Relay ——–SRD-05VDC-SL-C

-1 9V Battery or 6 * 1.5V batteries

 

In this project we have a new component called Diode, which is used for controlling the flux of energy that runs on the circuit.

The schematic symbol is:

arduino diodo

This symbol is easy to understand, it’s a sideways triangle with a barrier at the end. In this symbol we can conclude that the energy flow goes from the part of the triangle opposite to the barrier. If you try to send energy through the end with the barrier to the other and test it, you will see that it is impossible to pass energy that way.

The diode is really important here, because it prevents energy passage directly from the arduino uno to the breadboard. What should happen is the energy passing from the batteries, to the arduino, then to the relay and finally to the breadboard.

So now that we know a little bit more about diodes, we can start our project with the external power source. This process is represented in the sketch below:

arduino external power source sketch

 

arduino external power source

As you can see we have a scheme with 2 electric power sources in parallel, which means if the main power source for arduino fails we have the batteries to maintain the circuit running.

Our code is just activating the relay with :

digitalWrite(rele,HIGH);

The purpose of using this diode is to make the energy flow like this:

batteries->arduino->Relay->circuit

or

Arduino power source->Relay->circuit

The circuit now has 2 power sources in parallel that work together to try to make the system always on.

This serves to show that the light continues ON even after you remove the cable from your computer.

When the relay is ON, the led remains ON. When it’s OFF, the led remains the same.

This was another tutorial made for you to understand better “electronics” with arduino.

 

 

Alexandre Leitao

Gonçalo Neto

Google+