Arduino: auto-refresh della pagina web, prima parte della risoluzione dei bug – Resoconto attività 28 luglio 2014

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

Today we dedicated our time on trying to fix the bug we had in our project, which was receiving and process the data returned by the web page properly.
Unfortunately we couldn’t finish it, however we think we have a solution and we will apply it tomorrow.

 

28 of July 2014

Alexandre Leitao            
Gonçalo Neto 

Arduino: auto-refresh della pagina web – Resoconto attività 25 luglio 2014

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

Today we made an addiction to the last project, the page auto refreshes itself so we don’t have to do it. We spent a lot of time finding and trying to fix a bug where the arduino couldn’t receive the values that the user would put in the text box from the web page.

Another problem was that we could not have two different text boxes having different values and it took us time trying to solve it and we couldn’t all of it yet.

We’ll be fixing it on Monday.

 

25 of July 2014

Alexandre Leitao

Gonçalo Neto

Tutorial Arduino: how to control temperature, light and system from browser.

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

For this new tutorial, we’re going to explain how to control the temperature, light and the system (ON/OFF).

Components:

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

 

 

In this project, we can check the temperature in the room that the sensor is located and write the temperature we want it to be, as in the last project. In addiction, we’re able to check the light the sensor can get. Depending on the temperature we want and the real one, there’s a text saying if it is equal, too low or too high. The text about the light is als pretty simple.

We simulate the Air conditioner with leds that turn on.

How it looks:

arduino air conditioner led

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

arduino air conditioner same temperature

When the temperature chosen is lower than the actual one:

arduino air conditioner lower temperature

When the temperature chosen is higher than the actual one:

arduino air conditioner higher temperature

The sketch:

arduino air conditioner temperature light

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;
  
  
/*inizio client*/

EthernetClient client = server.available();
if (client) {
  boolean currentLineIsBlank = true;
  while (client.connected()) {
    if (client.available()) {
      char c = client.read();
        readString.concat(c); //storages character
      //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 web page
                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); 
            }
          }
        }
          }
          
        // 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();
         
        } 
    }
  }

   


} // fine loop
}


24 of July 2014

Alexandre Leitao

Gonçalo Neto

Arduino: livello di luminosità unita al controllo della temperatura – Resoconto attività 24 luglio 2014

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

Today, we started doing a new project that included a photoresistor, this project had a new interface, and a new feature similar to the last one, unfortunately we couldn’t finish it, it was going well until a bug appear. We spent a lot of time trying to fix it, but we couldn’t find the bug so we used the project from yesterday and added a new feature the light level of the room the circuit is in.

We did the code and the tutorial for this project and we are still trying to find the bug in the other code.

 

24 of July 2014

Alexandre Leitao

Gonçalo Neto

Tutorial Arduino: How to check and adjust room temperature from browser

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.

Here’s how it looks:

 arduino_air_conditioning1

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

arduino_airconditioning

When the temperature chosen is lower than the actual one:

arduino_airconditioning2

When the temperature chosen is higher than the actual one:

arduino_airconditioning3

The sketch:

arduino_air_conditioning8

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 
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

  Serial.begin(9600);
}

void loop()
{
  // Temperature:
  float x=0, x2= 0;
  float from_sv=0;
  x = analogRead(5);


  x2 += (95.0 * vrif * x) / 1024.0;
  Serial.println(x2);


  /*inizio client*/

  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) {
          Serial.print(readString);

          if(readString.indexOf("L=1") > 0) {
            digitalWrite(outPin, HIGH); 
            LEDON = true;
            Serial.print("ON pin ");
            Serial.println(outPin);
          }
          else
          {
            if(readString.indexOf("L=0") > 0){
              digitalWrite(outPin, LOW);
              LEDON = false;
              Serial.print("OFF pin ");
              Serial.println(outPin);
            }
            if(readString.indexOf("T=") > 0)
            }
            // Web Page html
            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("<head><title>ARDUINO Led Control</title><meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1' ><a href=""https://www.hydrasolutions.it""><img src=""https://2.bp.blogspot.com/-p5i_N2bHBOk/U7b48Dwy_tI/AAAAAAAAABY/IEIbQcWPJRQ/s1600/logotr.png"" alt=""Hydra Icon/></a><br><br></head><body>");

          client.print("<p><a href='/?L=1'>ACCENDI</a> | <a href='/?L=0'>SPEGNI</a></p>");

          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>");
          client.print("<tr><th>Reference Temperature</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.println("<th><?PHP echo $_SESSION['data'];?> </th></tr>");
          client.println("<tr><th>Temperature of the room</th>");
          client.print("<th>");     
          client.print(x2);   
          client.println("</th>"); 
          client.println("</body></html>");
          readString="";
          client.stop();

        } 
      }
    }




  } // fine loop
}


23 of July 2014

Alexandre Leitao

Gonçalo Neto

Google+