Tutorial Arduino: control of temperature and light with a buzzer – Controllo della temperature e della luminosità con l’aggiunta di un buzzer

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

For this tutorial consists on controlling the light using a buzzer and controlling the temperature.

Here are the components we used:

  • 1 Arduino
  • 1 Ethernet Shield
  • 1 Relay
  • 1 Temperature sensor
  • 1 Light sensor
  • 3 Leds
  • 3 Resistors
  • 1 Buzzer

The web page has one table for the temperature with a text box and the actual temperature and one simple table for the light.

Depending on the values we put comparing with the temperature, above the table appears text saying when to turn on/off the air conditioner.

For the light, depending on the light sensor gets, if the light level is 10% higher/lower than the internal reference temperature the buzzer makes sound (in the video it is set to 60%).

How it looks:

arduino temperature and light control refresh with buzzer

Same temperature:

arduino temperature and light control refresh with buzzer

Lower temperature:

arduino temperature and light control refresh with buzzer

Higher temperature:

arduino temperature and light control refresh with buzzer

Code:

#include <String.h>
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = {  
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; // mac address
byte ip[] = { 
  192, 168, 1, 25 }; // ip arduino internet in
byte subnet[] = { 
  255, 255, 255, 0 }; //subnet mask
EthernetServer server(80); //server port
String readString; //string
String string;
int temp1=0 , temp2=0;
int vrif = 1.1;
int Rele = 0, lastlight=0;
int Ref_light=60;

void setup(){
  Ethernet.begin(mac, ip, subnet);
  analogReference(INTERNAL); //lowers the voltage reference
  pinMode(8,OUTPUT); //cold
  pinMode(9,OUTPUT); // hot
  pinMode(7,OUTPUT); // rele
  pinMode(6,OUTPUT);
  pinMode(5,INPUT);
  pinMode(0,INPUT);

  Serial.begin(9600);
}
void loop()
{
  /*Client*/

  int i=0; //y1 = temperatura e light = light level from user
  long int Rlight=0;
  float TempAverage=0;
  int y1=0, light=0, dif=0; // references posted by the user!
  EthernetClient client = server.available();

  TempAverage=analogRead(5);
  Rlight=analogRead(0);

  TempAverage = (90.0 * vrif * TempAverage) / 1024.0;

  Rlight*=100;
  Rlight/=1024;

  if (client) {
    boolean currentLineIsBlank = true;
    //tone(13,960,1000);
    while (1) 
    {
      if (client.available()) {

        char c = client.read();

        readString.concat(c); 
        //Serial.println(readString);
        //if HTTP request has ended
        if (c == '\n' &&  currentLineIsBlank) 
        {
          Serial.println(readString);
          string = readString;
          if(readString.indexOf("T=") > 0)
          {
            for(i=0;string[i];i++)
            {
              if(string[i] == 'T' && string[i+1] == '=' && string[i+2] >=48  && string[i+2] <=57 && string[i+3] >= 48 && string[i+3] <= 57) 
              {
                switch(string[i+2])
                {                                                                                                       
                case 48: 
                  y1+= 0; 
                  break;
                case 49: 
                  y1+=10; 
                  break;
                case 50: 
                  y1+=20; 
                  break;
                case 51: 
                  y1+=30; 
                  break;
                case 52: 
                  y1+=40; 
                  break;
                case 53: 
                  y1+=50; 
                  break;
                case 54: 
                  y1+=60; 
                  break;
                case 55: 
                  y1+=70; 
                  break;
                case 56: 
                  y1+=80; 
                  break;
                case 57: 
                  y1+=90; 
                  break;
                }
                switch(string[i+3])
                {
                case 48: 
                  y1+= 0; 
                  break;
                case 49: 
                  y1+=1; 
                  break;
                case 50: 
                  y1+=2; 
                  break;
                case 51: 
                  y1+=3; 
                  break;
                case 52: 
                  y1+=4; 
                  break;
                case 53: 
                  y1+=5; 
                  break;
                case 54: 
                  y1+=6; 
                  break;
                case 55: 
                  y1+=7; 
                  break;
                case 56: 
                  y1+=8; 
                  break;
                case 57: 
                  y1+=9; 
                  break;
                }
              }
            }
          }
          break;
        }
      }
    }

    Serial.println(y1);
    Serial.println(light);



    if(temp1 < (int)TempAverage && temp1 != 0)
    {
      Rele=1;
    }
    if(temp1 > (int)TempAverage && temp1 != 0)
    {
      Rele=1; 
    }
    if(temp1 == (int)TempAverage && temp1 != 0)
    {
      Rele=0;
    }
    if(Rele == 1)
    TempAverage-=12;

    // Web page:
    client.println("<!DOCTYPE html>");
    client.println("<?php session_start(); ?>");
    client.println("<html> "); 
    client.println("<table><tr><th>");
    client.println(" <tr><td><table border=""><tr><th>Reference Temperature </th>");
    client.println("<th><form action="" method=""get""><input type=""text"" name=""T"" value=""Insert value""><input type=""submit"" value=""check""><?phpif(!isset($_GET['temp']))$var_1 = "";else$var_1 = $_GET['temp'];$_SESSION['data'] = $var_1;?></th>");
    client.println("<tr></tr><th>Reference temperature set to </th><th>");
    if(y1 == 0)
      client.print(temp1);
    else
      client.print(y1);



    client.print("</th><tr>");
    client.println("<tr><th>Temperature of the room   </th><th>");
    if(Rele == 1)
      TempAverage-=12;
    else
    {
    }
    client.println(TempAverage);
    client.print("</th></tr>");
    client.println("</table></td>");
    client.println("<td></td><td><table border="">");
    client.println("<tr><th>Light leven of the room    </th><th>");
    client.print(Rlight);
    client.print("%</th></tr></table></td></tr>");
    client.println("</table>");
    if(temp1 < (int)TempAverage && temp1 != 0)
    {
      client.println("<p>Turn heater ON!</p>");
      digitalWrite(7,HIGH); // RELE
      digitalWrite(8,LOW); // blue
      digitalWrite(9,HIGH); // reed
    }
    if(temp1 > (int)TempAverage && temp1 != 0)
    {
      client.println("<p>Turn Air conditioner ON!</p>");
      digitalWrite(7,HIGH); // RELE
      digitalWrite(8,HIGH); // blue
      digitalWrite(9,LOW); // reed
    } 
    if(temp1 == (int)TempAverage && temp1 != 0)
    {
      client.println("<p>Teperature OK!</p>");
      digitalWrite(7,LOW); // REL
      digitalWrite(8,LOW); // green
      digitalWrite(9,LOW); // reed
    }  
    client.println("</body></html>");
    readString="";
    if(y1 != temp1 && y1 != 0)
      temp1=y1;
    if(light != temp2 && light != 0)
      temp2=light;
    client.stop();
   delay(2000);
    if(light > Ref_light+10)
    {
      tone(6,960,1000);
      delay(500);
    }
    if(light < Ref_light-10)
    {
      tone(6,960,1000);
      delay(500);
    }
  }
}


30 of July 2014

Alexandre Leitao

Gonçalo Neto

Arduino: un buzzer che segnala le variazioni di luminosità – Resoconto attività 30 luglio 2014

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

Today we started a new project based on the project from yesterday. We added a buzzer which makes noise when the light level is 10% higher/lower than the internal reference temperature (it is set to 60% by default).

We managed to finish it, however we had some problems referring to the energy management and the buzzer.

In the end we made a tutorial with pictures and explanation and a video.

 

30 of July 2014

Alexandre Leitao

Gonçalo Neto

Tutorial arduino: room light and temperature levels check and adjust with autorefresh

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

For this tutorial, we’re going to explain you all about this project, which consists on controlling the temperature and the light from the web page. It’s based on old projects but this one has new features.

Here are the components we used:

  • 1 Arduino
  • 1 Ethernet Shield
  • 1 Relay
  • 1 Temperature sensor
  • 1 Light sensor
  • 3 Leds
  • 3 Resistors

The web page has two different tables, one for the temperature and one for the light. Above the text boxes appears the value we put in the text box, which represents the temperature/light we want it to be. Above that there’s the actual temperature/light in the room where the sensor is located.

Depending on the values we put comparing with the temperature, above the table appears text saying when to turn on/off the air conditioner.

How it looks:

arduino temperature and light control refresh

Same temperature:

arduino temperature and light control refresh

Lower temperature:

arduino temperature and light control refresh

Higher temperature:

arduino temperature and light control refresh

Code:

#include <String.h>

#include <SPI.h>

#include <Ethernet.h>



byte mac[] = {  
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; // mac address

byte ip[] = { 
  192, 168, 1, 25 }; // ip arduino internet in

byte subnet[] = { 
  255, 255, 255, 0 }; //subnet mask

EthernetServer server(80); //server port


int outPin = 9; // pin

String readString; //string

int temp1=0 , temp2=0;

int vrif = 1.1;

int Rele = 0;

void setup(){

  Ethernet.begin(mac, ip, subnet);
  pinMode(outPin, OUTPUT);
  analogReference(INTERNAL); //lowers the voltage reference
  pinMode(8,OUTPUT); //cold
  pinMode(9,OUTPUT); // hot
  pinMode(7,OUTPUT); // rele

  pinMode(5,INPUT);
  pinMode(0,INPUT);

  Serial.begin(9600);
}



void loop()

{
  /*Client*/
  String string;
  int i=0; //y1 = temperatura e light = light level from user
  long int Rlight=0;
  float TempAverage=0;
  int y1=0, light=0; // references posted by the user!
  EthernetClient client = server.available();





  TempAverage=analogRead(5);
  Rlight=analogRead(0);


  TempAverage = (95.0 * vrif * TempAverage) / 1024.0;

  Rlight*=100;
  Rlight/=1024;


  if (client) {

    boolean currentLineIsBlank = true;




    while (1) 
    {
      if (client.available()) {

        char c = client.read();

        readString.concat(c); 

        //Serial.println(readString);


        //if HTTP request has ended

        if (c == '\n' &&  currentLineIsBlank) 
        {

          Serial.println(readString);
          string = readString;
          if(readString.indexOf("T=") > 0)
          {
            for(i=0;string[i];i++)
            {
              if(string[i] == 'T' && string[i+1] == '=' && string[i+2] >=48 && string[i+3] <= 57) 
              {

                switch(string[i+2])
                {                                                                                                       
                case 48: 
                  y1+= 0; 
                  break;
                case 49: 
                  y1+=10; 
                  break;
                case 50: 
                  y1+=20; 
                  break;
                case 51: 
                  y1+=30; 
                  break;
                case 52: 
                  y1+=40; 
                  break;
                case 53: 
                  y1+=50; 
                  break;
                case 54: 
                  y1+=60; 
                  break;
                case 55: 
                  y1+=70; 
                  break;
                case 56: 
                  y1+=80; 
                  break;
                case 57: 
                  y1+=90; 
                  break;
                }
                switch(string[i+3])
                {
                case 48: 
                  y1+= 0; 
                  break;
                case 49: 
                  y1+=1; 
                  break;
                case 50: 
                  y1+=2; 
                  break;
                case 51: 
                  y1+=3; 
                  break;
                case 52: 
                  y1+=4; 
                  break;
                case 53: 
                  y1+=5; 
                  break;
                case 54: 
                  y1+=6; 
                  break;
                case 55: 
                  y1+=7; 
                  break;
                case 56: 
                  y1+=8; 
                  break;
                case 57: 
                  y1+=9; 
                  break;
                }

              }
            }

          }


          if(readString.indexOf("L=") > 0)
          {
            for(i=0;string[i];i++)
            {
              if(string[i] == 'L' &&string[i+1] == '=' && string[i+2] >=48 && string[i+3] <= 57) 
              {

                switch(string[i+2])
                {                                                                                                       
                case 48: 
                  light+= 0; 
                  break;
                case 49: 
                  light+=10; 
                  break;
                case 50: 
                  light+=20; 
                  break;
                case 51: 
                  light+=30; 
                  break;
                case 52: 
                  light+=40; 
                  break;
                case 53: 
                  light+=50; 
                  break;
                case 54: 
                  light+=60; 
                  break;
                case 55: 
                  light+=70; 
                  break;
                case 56: 
                  light+=80; 
                  break;
                case 57: 
                  light+=90; 
                  break;
                }
                switch(string[i+3])
                {
                case 48: 
                  light+= 0; 
                  break;
                case 49: 
                  light+=1; 
                  break;
                case 50: 
                  light+=2; 
                  break;
                case 51: 
                  light+=3; 
                  break;
                case 52: 
                  light+=4; 
                  break;
                case 53: 
                  light+=5; 
                  break;
                case 54: 
                  light+=6; 
                  break;
                case 55: 
                  light+=7; 
                  break;
                case 56: 
                  light+=8; 
                  break;
                case 57: 
                  light+=9; 
                  break;
                }

              }
            }
          }



          break;
        }



      }
    }
 

    if(temp1 < (int)TempAverage && temp1 != 0)
    {
      Rele=1;
    }
    if(temp1 > (int)TempAverage && temp1 != 0)
    {
     Rele=1; 
    }
    if(temp1 == (int)TempAverage && temp1 != 0)
    {
      Rele=0;
    }

    // Web page:

    client.println("<!DOCTYPE html>");
    client.println("<?php session_start(); ?>");

    client.println("<html> "); 

    client.println("<table><tr><th>");
   /* client.println("<table border=""><tr><th>System Status</th><th> ");
    if(Rele == 1)
    {
      client.println("ON");     
      client.println("</th></table><th></th></tr>");
    }
    else
    {
     client.println("OFF");
     client.println("</th></table><th></th></tr>");
    }
    */
    client.println(" <tr><td><table border=""><tr><th>Reference Temperature </th>");
    client.println("<th><form action="" method=""get""><input type=""text"" name=""T"" value=""Insert value""><input type=""submit"" value=""check""><?phpif(!isset($_GET['temp']))$var_1 = "";else$var_1 = $_GET['temp'];$_SESSION['data'] = $var_1;?></th>");
    client.println("<tr></tr><th>Reference temperature set to </th><th>");

    if(y1 == 0)
    client.print(temp1);
    else
    client.print(y1);



    client.print("</th><tr>");
    client.println("<tr><th>Temperature of the room   </th><th>");
    if(Rele == 1)
    TempAverage-=12;
    else
    {
    }
    client.println(TempAverage);
    client.print("</th></tr>");
    
    
    
    
    
    
    client.println("</table></td>");
    


    client.println("<td></td><td><table border=""><tr><th>Reference Light</th><th>");
    client.println("<form action="" method=""get""><input type=""text"" name=""L"" value=""Insert percentage""><input type=""submit"" value=""Try""><?phpif(!isset($_GET['temp']))$var_2 = "";else$var_2 = $_GET['temp'];$_SESSION['data'] = $var_2;?></th></tr>");
    client.println("<tr></tr><th>Refence light set to </th><th>");
    
    if(light == 0)
    client.print(temp2);
    else
    client.print(light);
    
    client.print("%</th>");
    client.println("<tr><th>Light leven of the room    </th><th>");
    client.print(Rlight);
    client.print("%</th></tr></table></td></tr>");

    client.println("</table>");
    
    
    if(temp1 < (int)TempAverage && temp1 != 0)
    {
      client.println("<p>Turn heater ON!</p>");
      digitalWrite(7,HIGH); // RELE
      digitalWrite(8,LOW); // blue
      digitalWrite(9,HIGH); // reed
      
    }
    if(temp1 > (int)TempAverage && temp1 != 0)
    {
      client.println("<p>Turn Air conditioner ON!</p>");
      digitalWrite(7,HIGH); // RELE
      digitalWrite(8,HIGH); // blue
      digitalWrite(9,LOW); // reed
    } 
     if(temp1 == (int)TempAverage && temp1 != 0)
    {
      client.println("<p>Teperature OK!</p>");
      digitalWrite(7,LOW); // REL
      digitalWrite(8,LOW); // green
      digitalWrite(9,LOW); // reed
    } 
    
    
    
    client.println("</body></html>");

    readString="";

    if(y1 != temp1 && y1 != 0)
   temp1=y1;
  
  if(light != temp2 && light != 0)
   temp2=light;
   
    client.stop();


  }
}


   29 of July 2014

Alexandre Leitao

Gonçalo Neto

Arduino: risoluzione bug e nuove aggiunte al progetto – Resoconto attività 29 luglio 2014

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

Today we kept trying to fix the bug we already had from yesterday. Fortunately, we were able to find it and fix it.

 With the bug out of the code, we managed to continue working on the project, which was controlling the temperature and the light from the web page. It’s based on old projects, but we added new features.

In the end, we made a video and a tutorial that includes pictures, detailed explanation and the code we used.

 

29 of July 2014

Alexandre Leitao

Gonçalo Neto

Tutorial Arduino: Temperature control with Auto-refresh

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

This tutorial will explain how this project works and its code. It is based on the last project but this time we’ll having more control of the leds, temperature and relay.

Components:

  • 1 Arduino
  • 1 Ethernet Shield
  • 1 BreadBoard
  • 3 Leds
  • 3 Resistances
  • 1 Temperature sensor

In this project, we’re able to check the temperature in the room that the temperature sensor is located and write the temperature we want it to be, depending on the temperature we want and the real one, there’s a text saying if it is equal, too low or too high.

We simulate the Air conditioning with leds that turn on.

This sketch automatically refreshes when the light values change.

Here’s how it looks:

 Arduino auto refresh web page

When the temperature chosen is the same as the actual one:

arduino_refresh_2

When the temperature chosen is lower than the actual one:

arduino_refresh_3

When the temperature chosen is higher than the actual one:

arduino_refresh_4

 

The sketch:

arduino_refresh_sketch

The code we used:

#include <String.h>
#include <SPI.h>
#include <Ethernet.h>
 
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; // mac address
byte ip[] = { 192, 168, 1, 25 }; // ip arduino internet in
byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
EthernetServer server(80); //server port
 
int outPin = 9; // pin 
int y1=0; // reference temperature
String readString; //string
boolean LEDON = false; // flag status
 
float vrif = 1.1; // for the temperature

void setup()
{
Ethernet.begin(mac, ip, subnet);
pinMode(outPin, OUTPUT);
analogReference(INTERNAL); //lowers the voltage reference
pinMode(8,OUTPUT); //cold
pinMode(10,OUTPUT); // hot
pinMode(7,OUTPUT); // rele
pinMode(0,INPUT);
Serial.begin(9600);
}
 
void loop()
{
  
  char string[100];
  int y=0;
  long int light=0;
  for(y=0;y<=100;y++) // put the string with 0
  {
    string[y]=0;
  }
  // Temperature:
  float x=0, x2= 0;
  float from_sv=0;
  x = analogRead(5); // temperature
  light= analogRead(0); // light

  // TEMPERATURE  
  x2 += (95.0 * vrif * x) / 1024.0; 
  //LIGHT
  light= light * 100 ;
  light= light / 1023;
  
  

EthernetClient client = server.available();
if (client) {
  boolean currentLineIsBlank = true;
  while (client.connected()) {
    if (client.available()) {
      char c = client.read();
        readString.concat(c); 
      //if HTTP request has ended
      if (c == '\n' && currentLineIsBlank) {
        String string =  String(readString);
        Serial.print(readString);
        if(readString.indexOf("L=1") > 0) {// (L=1 or L=0 will be in the string)
          digitalWrite(outPin, HIGH); 
          LEDON = true;
          Serial.print("ON pin ");
          Serial.println(outPin);
          }
          else
          {
            if(readString.indexOf("L=0") > 0){ // "<0" means "L=0" is there in the string
          
          digitalWrite(outPin, LOW); 
          LEDON = false;
          Serial.print("OFF pin ");
          Serial.println(outPin);
        }
        if(readString.indexOf("T=") > 0) // "T" is defined in the html part
        {
          y1=0; // y1 is 0 again
          for(int i=0;string[i]!= '\0';i++)
          {
            if(string[i]== 'T' && string[i+1]== '=')
            {
              Serial.println(string[i+2]); //prints what's next to the "="
              switch(string[i+2])
              {
                case 48: y1+= 0; break; // y1 represents the value returned by the site 
                case 49: y1+=10; break;
                case 50: y1+=20; break;
                case 51: y1+=30; break;
                case 52: y1+=40; break;
                case 53: y1+=50; break;
                case 54: y1+=60; break;
                case 55: y1+=70; break;
                case 56: y1+=80; break;
                case 57: y1+=90; break;
              }
              Serial.println(y1);
              switch(string[i+3])
              {
                case 48: y1+= 0; break;
                case 49: y1+=1; break;
                case 50: y1+=2; break;
                case 51: y1+=3; break;
                case 52: y1+=4; break;
                case 53: y1+=5; break;
                case 54: y1+=6; break;
                case 55: y1+=7; break;
                case 56: y1+=8; break;
                case 57: y1+=9; break;
              }
              
             Serial.println(y1); // y1 converts, I mean, we get the input like 22 but arduino reads it as another number from ASCII, tyhis way we have to convert to a normal number again(ex: input: 22 -> represents 55 -> converts to 22 again and prints to the web page)
            }
          }
          
          
        }
          }
          
        // WEB PAGE
        client.println("HTTP/1.1 200 OK.....");
        client.println("Content-Type: text/html");
        client.println();
      
        
       client.print("<html> <style> table ,th, dt{ border:1px solid black; border-collapse:collapse;}"); // creates the table and costumizes the border for the temperature
       client.println("th, dt {padding:5px;}</style>"); // also border costumization
       client.println("<table><tr><th>Led status:</th>");
       client.print("<th>");
          if (LEDON) {
              client.println("<span style='color:green; font-weight:bold;'>ON</span></font>");
            }
            else
            {
              client.println("<span style='color:grey; font-weight:bold;'>OFF</span></font>");
          }
      client.print("</th>");
      if(y1!=0)
      {
        client.println(" <th rowspan=""4"">");
      if((int)x2 == y1)
      {
        client.println("Temperature OK!!!</th>");
        digitalWrite(7,LOW);
        digitalWrite(8,LOW);
        digitalWrite(10,LOW);
        LEDON=false;
      }
      if(x2>y1)
      {
        client.println("Turn Heater ON!!</th>");
        digitalWrite(7,HIGH);
        digitalWrite(10,HIGH);
        digitalWrite(8,LOW);
        LEDON=true;
      }
      if(x2<y1)
      {
        client.println("Turn Air condicioning ON!!</th>");
        digitalWrite(7,HIGH);
        digitalWrite(8,HIGH);
        digitalWrite(10,LOW);
        LEDON=true;
      }
     
      }
      
      client.print("<tr><th>Reference Temperature wanted </th>"); client.print("<th> <form action="" method=""get""><input type=""text"" name=""T"" value=""Insert value""><input type=""submit"" value=""check""><?phpif(!isset($_GET['temp']))$var_1 = "";else$var_1 = $_GET['temp'];$_SESSION['data'] = $var_1;?></th>");
      client.print("<tr><th>Reference Temperature is set to</th><th>"); client.print(y1); client.print("</th><tr>");
    
      client.println("<?PHP echo $_SESSION['data'];?>");
      client.println("<tr><th>Temperature of the room</th>");
      client.print("<th>");     client.print(x2);   client.println("</th>"); 
       client.print("<tr><th>Light level</th><th>"); client.print(light); client.print("% </th><tr></table>");
        client.println("</body></html>");
 
        readString="";
        
        client.stop();
         
        } 
    }
  }
 }
 }


 23 of July 2014

Alexandre Leitao

Gonçalo Neto

Google+