Tutti gli oggetti elettrici saranno connessi a internet

Per esempio, quando tutti gli oggetti elettrici di casa tua saranno connessi a internet, il loro consumo di corrente sarà negoziato di volta in volta con il contatore, che sarà anche lui connesso a internet, e con l’Enel.

Alla lavatrice dirai “lava entro domani alle otto”: lei aspetterà che il forno finisca prima di partire e prenoterà con l’Enel  il momento meno caro per lavare.

Risultato: verranno livellati i picchi sia del consumo che della produzione, con risparmi che potrebbero essere importanti. Tieni presente che la bolletta energetica italiana nel 2011 è stata di 60 miliardi di Euro, quindi ogni singolo punto percentuale risparmiato varrebbe ben 600 milioni di Euro.

Spannometricamente, un risparmio annuale del 5% basterebbe da solo in sette anni a ripagare i 20 miliardi di Euro necessari alla copertura in fibra ottica di tutta l’Italia.

Arduino: aprire 15 officine di innovazione in Italia

Massimo Banzi, padre di Arduino, lancia un progetto che mi piace tantissimo: trovare 10.000 persone disposte a metterci 100€ a testa, e mettere in piedi 15 Officine Arduino in 12 mesi.

Massimo, io ci sto. Facciamolo! Per esempio a Como ci sono enormi spazi non utilizzati nella ex Caserma De Cristoforis, una Officina Arduino ci starebbe benissimo.

Visualizzazione ingrandita della mappa

Domotica con Arduino e Android

Il fine settimana è dedicato fisso alle meraviglie di Arduino: oggi ho trovato Domotic Home, un sito molto interessante che ti permette di controllare facilmente un Arduino connesso a internet (con lo shield Ethernet o con quello WiFi) in due modi:

  • via una interfaccia web
  • via una app gratuita di Android (wow!)

Una volta registrato sul sito, inserisci la configurazione IP del tuo Arduino, gli dici quali pin sono collegati a cosa, e il sito ti restituisce il codice semi-funzionante, che vanno corrette alcune chiamate che sono cambiate nella versione 1.0.

Mi si aprono mondi.

Il mio Arduino è WiFi

Continua la saga di Gaspar Torriero gone Arduino: l’ultimo capitolo si intitola “Il WiFi funziona, finalmente”, e non è stato semplice.

Prima di tutto ho dovuto saldare i piedini della scheda, ed è stata la mia prima volta con in mano un saldatore. Poi ho cominciato le mie prove, e non funzionava niente: dopo molto scartabellare tra forum e blog, ha finalmente trovato una libreria che funziona con il modulo WiFi e la versione 1.0 di Arduino (per la cronaca, è questa), dato che quella fornita dal fabbricante SparkFun non è aggiornata.

Insomma, sono a buon punto e il mio progetto Arduino, fammi il caffè è a un passo dalla realizzazione. Nel frattempo ho visto che nel reparto elettricità dell’Esselunga si vende un temporizzatore per apparecchi elettrici a meno di 10 €.

Arduino, stai fresco!

Il caldo è ormai dietro l’angolo e mi troverà pronto: ho collegato all’Arduino un ventilatore e l’ho programmato perché si accenda da solo oltre una certa temperatura. Ho aggiunto anche una luce che cambia colore a seconda della temperatura rilevata. Ingedienti:

  • Breadboard
  • Ventilatore
  • Arduino 2009
  • Sensore temperatura
  • Relè
  • Led RGB tipo anodo comune
  • Connettori assortiti

Prossimo passo: impostare la temperatura di accensione da una interfaccia web, e regolare la luce del led a seconda della luce ambiente.

Se è vero che code is poetry, quanto segue dopo il salto si colloca abbastanza sotto a capolavori come “La Vispa Teresa”. Sicuramente esistono altri dieci modi più eleganti per gestire le combinazioni di colori da associare alle diverse temperature, ma la mia ignoranza enciclopedica per ora non mi permette altro.

Se puoi e vuoi illuminarmi, ne sarò felice.

 int greenPin = 5;
 int redPin = 6;
 int bluePin = 4;
 int tPin = A2; // Temperature sensor pin
 int lPin = A1; // Light sensor pin
 int temp; // Temperature in C°
 int outPin = 9; // fan relais pin 
 int luce; // light in Lux; not used

void setup()
{
  pinMode(redPin, OUTPUT);
  pinMode(greenPin, OUTPUT);
  pinMode(bluePin, OUTPUT);
  pinMode(outPin, OUTPUT);

  analogWrite(redPin, 255);
  analogWrite(greenPin, 255);
  analogWrite(bluePin, 255);
//  Serial.begin(9600);

}

void loop()
{
  // from V to °C
  temp = ( 5.0 * analogRead(tPin) * 100.0) / 1024.0;
  // from V to Lux, not used
  luce = (analogRead(lPin) * 10000.0) / 1024.0;

  if(temp <= 18) {
    analogWrite(bluePin, 0);
    analogWrite(greenPin,255);
    analogWrite(redPin,255);
  }
  else if(temp == 19) {
    analogWrite(bluePin, 51);
    analogWrite(greenPin,255);
    analogWrite(redPin,255);
  }
  else if(temp == 20) {
    analogWrite(bluePin, 102);
    analogWrite(greenPin,255);
    analogWrite(redPin,255);
  }
  else if(temp == 21) {
    analogWrite(bluePin, 153);
    analogWrite(greenPin,153);
    analogWrite(redPin,255);
  }
  else if(temp == 22) {
    analogWrite(bluePin, 204);
    analogWrite(greenPin,102);
    analogWrite(redPin,255);
  }
  else if(temp == 23) {
    analogWrite(bluePin, 255);
    analogWrite(greenPin,51);
    analogWrite(redPin,255);
  }
  else if(temp == 24) {
    analogWrite(bluePin, 255);
    analogWrite(greenPin,0);
    analogWrite(redPin,255);
  }
  else if(temp == 25) {
    analogWrite(bluePin, 255);
    analogWrite(greenPin,51);
    analogWrite(redPin,255);
  }
  else if(temp == 26) {
    analogWrite(bluePin, 255);
    analogWrite(greenPin,102);
    analogWrite(redPin,204);
  }
  else if(temp == 27) {
    analogWrite(bluePin, 255);
    analogWrite(greenPin,153);
    analogWrite(redPin,153);
  }
  else if(temp == 28) {
    analogWrite(bluePin, 255);
    analogWrite(greenPin,204);
    analogWrite(redPin,102);
  }
  else if(temp == 29) {
    analogWrite(bluePin, 255);
    analogWrite(greenPin,255);
    analogWrite(redPin,51);
  }
  else if(temp >= 30) {
    analogWrite(bluePin, 255);
    analogWrite(greenPin,255);
    analogWrite(redPin,0);
  }
if(temp > 27) {
  digitalWrite(outPin, HIGH);
  }
  else {
    digitalWrite(outPin, LOW);
  }

delay(10000);
//  Serial.println(temp);
//  Serial.println();

}

Arduino, fammi il caffè! V0.1

Ho raggiunto i primi due obiettivi che mi ero posto con l’Arduino, ovvero

  1. prendere l’ora da internet tramite il Net Time Protocol
  2. accendere la macchina del caffè all’ora prefissata

Ma non è finita: adesso bisogna (bisogna!) che l’ora di accensione venga impostata via web, non inserita banalmente a mano nel codice. Per fare questo occorre che sia contemporaneamente attivo il cliente NTP e il server web, e grosse nubi si addensano sul mio orizzonte di entusiasta ignorante.

Inoltre non è bello che l’Arduino debba autisticamente chiedere l’ora a NTP ogni minuto: meglio sarebbe se chiedesse solo una volta al giorno per sincronizzare con un suo orologio interno.

Come dire che ho le sere impegnate fino a primavera. Il codice fino a questo punto, dopo il salto: come sempre, eventuali commenti, critiche e suggerimenti sono molto bene accetti.

/*
 Arduino, fammi il caffè! V.0.1
 
 created 4 Sep 2010 
 by Michael Margolis
 modified 17 Sep 2010
 by Tom Igoe
 modified 18 Feb 2012
 by Gaspar Torriero
 
 This code is in the public domain.

 */

#include <SPI.h>
#include <Ethernet.h>
#include <EthernetUdp.h>

int cHH; // current hour
int cMM; // current minute
int cSS; // current second
int outPin = 8; // connected to coffee machine via relè

// Enter a MAC address for your controller below
byte mac[] = {
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

unsigned int localPort = 8888;      // local port to listen for UDP packets

IPAddress timeServer(192, 43, 244, 18); // time.nist.gov NTP server

const int NTP_PACKET_SIZE= 48; // NTP time stamp is in the first 48 bytes of the message

byte packetBuffer[ NTP_PACKET_SIZE]; //buffer to hold incoming and outgoing packets 

// A UDP instance to let us send and receive packets over UDP
EthernetUDP Udp;

void setup()
{
  // Serial.begin(9600); // uncomment for testing
  digitalWrite(outPin, LOW);

  // start Ethernet and UDP
  if (Ethernet.begin(mac) == 0) {
    // Serial.println("Failed to configure Ethernet using DHCP"); // uncomment for testing
    // no point in carrying on, so do nothing forevermore:
    for(;;)
      ;
  }
  Udp.begin(localPort);
}

void loop()
{
  sendNTPpacket(timeServer); // send an NTP packet to a time server

    // wait to see if a reply is available
  delay(1000);
  if ( Udp.parsePacket() ) {
    // We've received a packet, read the data from it
    Udp.read(packetBuffer,NTP_PACKET_SIZE);  // read the packet into the buffer

    //the timestamp starts at byte 40 of the received packet and is four bytes,
    // or two words, long. First, esxtract the two words:

    unsigned long highWord = word(packetBuffer[40], packetBuffer[41]);
    unsigned long lowWord = word(packetBuffer[42], packetBuffer[43]);
    // combine the four bytes (two words) into a long integer
    // this is NTP time (seconds since Jan 1 1900):
    unsigned long secsSince1900 = highWord << 16 | lowWord;  

    // Unix time starts on Jan 1 1970. In seconds, that's 2208988800:
    const unsigned long seventyYears = 2208988800UL;
    // subtract seventy years:
    unsigned long epoch = secsSince1900 - seventyYears;  

    // print the hour, minute and second:
    cHH = (epoch  % 86400L) / 3600 + 1;
    cMM = (epoch  % 3600) / 60;
    cSS = epoch %60;

    /* uncomment for testing
    Serial.print("Local time is ");
    Serial.print(cHH);
    Serial.print(" hours, ");
    Serial.print(cMM);
    Serial.print(" minutes, and ");
    Serial.print(cSS);
    Serial.println(" seconds.");
    */

    // Turns on the coffee machine
    // at a fixed time.
    // Next goal: set time via web.
    if((cHH == 6) && (cMM > 44)) {
      digitalWrite(outPin, HIGH);
    }
  }
  // wait 60 seconds before asking for the time again
  // Next goal: let Arduino Keep the time
  // and synchronize daily.

  delay(60000); 

}

// send an NTP request to the time server at the given address 
unsigned long sendNTPpacket(IPAddress& address)
{
  // set all bytes in the buffer to 0
  memset(packetBuffer, 0, NTP_PACKET_SIZE); 
  // Initialize values needed to form NTP request
  // (see URL above for details on the packets)
  packetBuffer[0] = 0b11100011;   // LI, Version, Mode
  packetBuffer[1] = 0;     // Stratum, or type of clock
  packetBuffer[2] = 6;     // Polling Interval
  packetBuffer[3] = 0xEC;  // Peer Clock Precision
  // 8 bytes of zero for Root Delay & Root Dispersion
  packetBuffer[12]  = 49; 
  packetBuffer[13]  = 0x4E;
  packetBuffer[14]  = 49;
  packetBuffer[15]  = 52;

  // all NTP fields have been given values, now
  // you can send a packet requesting a timestamp: 
  Udp.beginPacket(address, 123); //NTP requests are to port 123
  Udp.write(packetBuffer,NTP_PACKET_SIZE);
  Udp.endPacket();
}

Arduino server: sempre meglio

Dal mio nuovo server su Arduino (che lascerò attivo qualche giorno),  non solo puoi vedere lo stato delle mie luci e la temperatura di camera mia, ma puoi anche comandare tre pin che per ora sono collegati a tre led colorati, ma che domani potrei associare tramite relè a qualsiasi apparecchio elettrico.

Tutto questo grazie alla libreria WebServer.h, che aggiunge funzionalità molto interessati e facili da programmare anche per un ignorante come me (che si diverte come un bambino).

Come sempre, critiche consigli e suggerimenti sono bene accetti.

 

 

Come sempre, il codice è dopo il salto.

/* Web_Demo.pde -- sample code for Webduino server library */

/*
 * To use this demo,  enter one of the following USLs into your browser.
 * Replace "host" with the IP address assigned to the Arduino.
 *
 * http://host/
 * http://host/json
 *
 * This URL brings up a display of the values READ on digital pins 0-9
 * and analog pins 0-5.  This is done with a call to defaultCmd.
 * 
 * 
 * http://host/form
 *
 * This URL also brings up a display of the values READ on digital pins 0-9
 * and analog pins 0-5.  But it's done as a form,  by the "formCmd" function,
 * and the digital pins are shown as radio buttons you can change.
 * When you click the "Submit" button,  it does a POST that sets the
 * digital pins,  re-reads them,  and re-displays the form.
 * 
 */

#include "SPI.h"
#include "Ethernet.h"
#include "WebServer.h"

int lPin = 1; // Light sensor pin
int tPin = 3; // Temperature sensor pin
int luce = 0; // light in Lux
float temp = 0.0; // Temperature in C°
String lstatus;

// no-cost stream operator as described at 
// http://sundial.org/arduino/?page_id=119
template<class T>
inline Print &operator <<(Print &obj, T arg)
{ obj.print(arg); return obj; }

// CHANGE THIS TO YOUR OWN UNIQUE VALUE
static uint8_t mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

// CHANGE THIS TO MATCH YOUR HOST NETWORK
static uint8_t ip[] = { 192, 168, XXX, XXX };

#define PREFIX ""

WebServer webserver(PREFIX, 80);

// commands are functions that get called by the webserver framework
// they can read any posted data from client, and they output to server

void jsonCmd(WebServer &server, WebServer::ConnectionType type, char *url_tail, bool tail_complete)
{
  if (type == WebServer::POST)
  {
    server.httpFail();
    return;
  }

  //server.httpSuccess(false, "application/json");
  server.httpSuccess("application/json");

  if (type == WebServer::HEAD)
    return;

  int i;
  server << "{ ";
  for (i = 0; i <= 9; ++i)
  {
    // ignore the pins we use to talk to the Ethernet chip
    int val = digitalRead(i);
    server << "\"d" << i << "\": " << val << ", ";
  }

  for (i = 0; i <= 5; ++i)
  {
    int val = analogRead(i);
    server << "\"a" << i << "\": " << val;
    if (i != 5)
      server << ", ";
  }

  server << " }";
}

void outputPins(WebServer &server, WebServer::ConnectionType type, bool addControls = false)
{
  P(htmlHead) =
    "<html>"
    "<head>"
    "<title>Arduinogaspar Web Server</title>"
    "<style type=\"text/css\">"
    "BODY { font-family: sans-serif }"
    "H1 { font-size: 14pt; text-decoration: underline }"
    "P { font-size: 10pt; }"
    "</style>"
    "</head>"
    "<body>"
    "<p>Digital Pin 5: green light<br>"
    "Digital Pin 4: yellow light<br>"
    "Digital Pin 3: red light<br>"
    "Values can be changed from the /form page<br>"
    "and can be exported from the /json page.<br>"
    "</p>";

  int i;
  server.httpSuccess();
  server.printP(htmlHead);

  if (addControls)
    server << "<form action='" PREFIX "/form' method='post'>";

  server << "<h1>Digital Pins</h1><p>";

  for (i = 0; i <= 9; ++i)
  {
    // ignore the pins we use to talk to the Ethernet chip
    int val = digitalRead(i);
    server << "Digital " << i << ": ";
    if (addControls)
    {
      char pinName[4];
      pinName[0] = 'd';
      itoa(i, pinName + 1, 10);
      server.radioButton(pinName, "1", "On", val);
      server << " ";
      server.radioButton(pinName, "0", "Off", !val);
    }
    else
      server << (val ? "HIGH" : "LOW");

    server << "<br/>";
  }

  server << "</p><h1>Analog Pins</h1><p>";
  for (i = 0; i <= 5; ++i)
  {
    int val = analogRead(i);
    server << "Analog " << i << ": " << val << "<br/>";
  }

  server << "</p>";
  server << "Temperature:" << temp << "°C<br/>";
  server << "Light is " << lstatus << "</p>";

  if (addControls)
    server << "<input type='submit' value='Submit'/></form>";

  server << "</body></html>";
}

void formCmd(WebServer &server, WebServer::ConnectionType type, char *url_tail, bool tail_complete)
{
  if (type == WebServer::POST)
  {
    bool repeat;
    char name[16], value[16];
    do
    {
      repeat = server.readPOSTparam(name, 16, value, 16);
      if (name[0] == 'd')
      {
        int pin = strtoul(name + 1, NULL, 10);
        int val = strtoul(value, NULL, 10);
        digitalWrite(pin, val);
      }
    } while (repeat);

    server.httpSeeOther(PREFIX "/form");
  }
  else
    outputPins(server, type, true);
}

void defaultCmd(WebServer &server, WebServer::ConnectionType type, char *url_tail, bool tail_complete)
{
  outputPins(server, type, false);
}

void setup()
{
  // set pins 0-8 for digital input
  for (int i = 0; i <= 9; ++i)
    pinMode(i, INPUT);
  pinMode(9, OUTPUT);

  Ethernet.begin(mac, ip);
  webserver.begin();

  webserver.setDefaultCommand(&defaultCmd);
  webserver.addCommand("json", &jsonCmd);
  webserver.addCommand("form", &formCmd);
}

void loop()
{
    temp = ( 5.0 * analogRead(tPin) * 100.0) / 1024.0; // Conversione voltaggio sensore in temperatura
    luce = (analogRead(lPin) * 10000.0) / 1024.0; //Conversione voltaggio sensore in Lux
    if (luce < 201) {
      lstatus = "OFF";
    }
    else {
      lstatus = "ON";
    }

  // process incoming connections one at a time forever
  webserver.processConnection();

  // if you wanted to do other work based on a connecton, it would go here
}

Arduino al pomodoro

Per trasformare il mio Arduino in un conta-pomodori ho seguito le facili istruzioni di Mike Stok, grazie al quale ho scoperto l’esistenza di  Fritzing, un tool di prototipazione dedicato al mondo Arduino che mi permette di disegnare queste cose:

Per adesso mi limito ad accendere il led rosso per 25 minuti alla pressione del bottone, con lampeggio nel minuto finale e passaggio al giallo per i 5 minuti successivi; quindi il led verde.

Prossimi passi: regolare automaticamente l’intansità del led in base alla luminosità dell’ambiente. Il codice l’ho messo dopo il salto.

// #define TEST_INTERVALS

#define HEARTBEAT_LED 13 

#define INITIAL_TCNT1  (65536 - 16000000 / 256)

#define PUSHBUTTON_INT 0

#define WORK_STATE     0
#define REST_STATE     1
#define FREE_STATE     2
#define N_STATES       3
#define INITIAL_STATE  FREE_STATE

int ledFor[]          = {
  3,         11,          5 };
#ifndef TEST_INTERVALS
int secsFor[]         = {
  25 * 60,     5 * 60,     0 * 60 };
#else
int secsFor[]         = {
  15,         10,          0 };
#endif
int nextStateTimer[]  = {
  REST_STATE, FREE_STATE, FREE_STATE };
int nextStateButton[] = {
  FREE_STATE, FREE_STATE, WORK_STATE };

volatile boolean heartbeatOn = false;

volatile int     brightnessFor[N_STATES];
volatile int     state;
volatile int     secsDuration;
volatile int     secsLeft;

ISR(TIMER1_OVF_vect) {
  noInterrupts();

  TCNT1 = INITIAL_TCNT1;

  heartbeatOn = !heartbeatOn;  
  digitalWrite(HEARTBEAT_LED, heartbeatOn ? HIGH : LOW);
  updateLeds();

  if (secsLeft > 0) {
    if (--secsLeft == 0) {
      enterState(nextStateTimer[state]);
    }
  }

  interrupts();
}

void buttonReleased() {
  noInterrupts();
  enterState(nextStateButton[state]);
  interrupts();
}

void updateLeds() {
  int i;

  // Clear all the "other" state leds
  for (i = 0; i < N_STATES; i++) {
    if (i != state) {
      brightnessFor[i] = 0;
    }
  }

  if (state == FREE_STATE) {
    brightnessFor[FREE_STATE] = 255;
  }
  else {
    int rampDownPeriod = 180;
    if (secsLeft > rampDownPeriod || heartbeatOn) {
      brightnessFor[state] = 255;
    }
    else {
      brightnessFor[state] = map(secsLeft, 0, rampDownPeriod, 64, 255);
    }
  }
}

void enterState (int newState) {
  state = newState;
  secsDuration = secsLeft = secsFor[newState];
  updateLeds();
}

void setup() {
  int i;
  pinMode(HEARTBEAT_LED, OUTPUT);
  enterState(INITIAL_STATE);
  attachInterrupt(PUSHBUTTON_INT, buttonReleased, RISING);
  TIMSK1 = 0x01;
  TCCR1A = 0x00;
  TCNT1  = INITIAL_TCNT1;
  TCCR1B = 0x04;
}

void loop () {
  int i;

  for (i = 0; i < N_STATES; i++) {
    analogWrite(ledFor[i], brightnessFor[i]);
  }

  delay(50);
}

La mia lampadina twitta

“Tutto ciò che è alimentato elettricamente è anche connesso a internet.”

(Tom Igoe)

La lampada del mio comodino twitta automaticamente i suoi cambiamenti di stato, grazie a

  • Arduino 2009
  • Ethernet Shield
  • Sensore luce

Bisognarà che le crei un account dedicato su twitter. Se sei interessato al codice, è qui sotto.

Essendo una prova, tengo aperta la porta seriale per controllare dalla consolle quel che succede, ma in produzione i vari Serial.print vengono tolti.

Se trovi errori o difetti e vuoi segnalarmeli, te ne sarò grato.

/* 
Twitter Light Client 0.2  
created on jan 28 2012
modified on jan 30 2012
by Gaspar Torriero
with many thanks to the Arduino community
at http://arduino.cc/en/Tutorial/HomePage
*/

#include <SPI.h>
#include <Ethernet.h>
#include <Twitter.h>

boolean oldStatus = 0;
boolean newStatus = 0;
int tPin = 0; // Temperature sensor pin
int lPin = 5; // Light sensor pin
float temp = 0.0; // Temperature in C°
int luce = 0; // light in Lux
byte mac[] = {
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = {
  192, 168, XXX, XXX }; // IP address of your Arduino
byte gateway[] = {
  192, 168, XXX, XXX }; // IP address of your router
byte subnet[] = {
  255, 255, 255, 0 };
Twitter twitter("XXXXXX-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"); // Your Twitter API code
String stringOne="La luce sul comodino è stata spenta";
String stringTwo="La luce sul comodino è stata accesa";
char msg[140];

void setup()
{
  Ethernet.begin(mac, ip, gateway, subnet);
  // Serial.begin(9600);
    luce = (analogRead(lPin) * 10000.0) / 1024.0; //Conversione voltaggio sensore in Lux
  if(luce < 201) {
    oldStatus=0;
    }
  else if(luce > 200) {
    oldStatus=1;
  }
}
void loop() {
  delay(50000);
  Serial.print(oldStatus);
  Serial.print(newStatus);
  Serial.println();
  Serial.println(luce);
  temp = ( 5.0 * analogRead(tPin) * 100.0) / 1024.0; // Conversione voltaggio sensore in temperatura
  luce = (analogRead(lPin) * 10000.0) / 1024.0; //Conversione voltaggio sensore in Lux
  if(luce < 201) {
    newStatus=0;
    stringOne.toCharArray(msg, 140);
  }
  else if(luce > 200) {
    newStatus=1;
    stringTwo.toCharArray(msg, 140);
  }
  if(newStatus != oldStatus) {
      Serial.println("connecting ...");
      if (twitter.post(msg)) {
        int status = twitter.wait(&Serial);
        if (status == 200) {
          Serial.println("OK.");
        } 
        else {
          Serial.print("failed : code ");
          Serial.println(status);
        }
      } 
      else {
        Serial.println("connection failed.");
      }
    delay(10000);
    oldStatus = newStatus;
    Serial.print(oldStatus);
    Serial.print(newStatus);
    Serial.println();
    Serial.println(luce);
  }
 }