luni, 22 aprilie 2013

Un modul bluetooth si Arduino

   Seria experimentelor cu diverse module si o placa de dezvoltare (compatibila) Arduino a ajuns la modulul bluetooth in varianta ieftina, tip HC-06
   
   Din neatentie, am comandat de pe eBay prima data doar placa adaptoare 5V la 3,3V, apoi si adevaratul modul bluetooth,
asa ca a trebuit sa apelez la un prieten cu mai multa experienta (Narcis de la MULTITEC), care mi-a lipit in 2 minute cele 2 placute cu o "statie" clasica termostatata, pentru a nu apare posibilitatea defectarii modulului datorita inductiei, daca ar fi folosit un pistol de lipit.
   Am gasit destul de putine informatii relevante, cele pe care le-am urmat fiind cele de la http://english.cxem.net/arduino/arduino4.php (si instructables.com).

   Primul test a fost acela in care am alimentat modului, cautandu-l cu un telefon... LED-ul rosu de pe modul se aprinde cu intermitenta cand modulul HC-06 nu este conectat cu alt dispozitiv bluetooth.
   Numele modulului nostru este "linvor" si parola este "1234".

   Am incercat prima data exemplul care transmite de la Arduino prin bluetooth la calculator un mesaj de salut si numarul de mesaje, sketch-ul fiind:

int cnt = 0;    // Counter

 void setup() {
   Serial.begin(9600);   // Initialization
 }

 void loop() {
   cnt++;
   Serial.print("Hello niq_ro from Arduino! Counter:");  // print message
   Serial.println(cnt);    // print counter
   delay(1000);   // wait 1 sec
 }

IMPORTANT: Cand se incarca sketch-ul in Arduino modulul bluetooth trebuie deconectat (scos din mufa), dupa care se reconecteaza...




   Apoi am modificat un pic programiorul, dar nesemnificativ din punct de vedere al functionarii

int cnt = 0;    // Counter

 void setup() {
   Serial.begin(9600);   // Initialization
 }

 void loop() {
   cnt++;
   Serial.print("Hello niq_ro from Arduino!");
   Serial.print('\n');
   Serial.print( "Counter: ");  // print message
   Serial.println(cnt);    // print counter
   Serial.print('\n');
   delay(1000);   // wait 1 sec
 }



   Singura diferenta fata de ce e in articolul rusesc este aceea ca nu am reusit sa conectez modulul bluetooth "linvor" cu modulul  cuplat direct la calculator, folosind doar programul mentionat acolo (Tera Term VT), inainte trebuind sa pornesc si programul IVT Bluesoleil care sa faca conexiunea intre ele.  

   Am trecut la pasul doi, cu transmisie in ambele sensuri (aprinderea si stingerea unui LED conectat la Arduino de la tastatura, apoi afisarea starii pe ecranul calculatorului), folosind placuta cu LED-ul multicolor.



   Sketch-ul este:
char incomingByte;  // incoming data
int  LED = 10;      // LED pin

void setup() {
  Serial.begin(9600); // initialization
  pinMode(LED, OUTPUT);
  Serial.println("Press 1 to LED ON or 0 to LED OFF...");
}

void loop() {
  if (Serial.available() > 0) {  // if the data came
    incomingByte = Serial.read(); // read byte
    if(incomingByte == '0') {
       digitalWrite(LED, LOW);  // if 1, switch LED Off
       Serial.println("LED OFF. Press 1 to LED ON!");  // print message
    }
    if(incomingByte == '1') {
       digitalWrite(LED, HIGH); // if 0, switch LED on
       Serial.println("LED ON. Press 0 to LED OFF!");
    }
  }
}






     Am realizat si un filmulet numit Arduino and Bluetooth module(I):
   Pentru a fi sigur ca am transmisie corecta prin bluetooth, am conectat pe Arduino la alt calculator (ca nu am avut alta sursa de alimentare) si am dat comenzi de pe calculatorul meu, primind si confirmarea starii LED-lui, apoi am alimentat pe Arduino de la un alimentator independent si l-am mutat la cca. 9m de calculator...
   Filmuletul care prezinta modul de conectare si functionare la aceasta distanta se numeste Arduino and bluetooth module (II)

   Pentru a "exploata" la maxim posibiltatile LED-lui multicolor de pe placuta mea, am modificat un pic sketch-ul, pentru a aprinde LED-ul rosu prin apasarea tastei 1, LED-ul albastru prin apasarea tastei 2, LED-ul verde prin apasarea tastei 3, respectiv stingerea lor prin apsarea tastei 0:


// adapted sketch from http://english.cxem.net/arduino/arduino4.php
// by niq_ro from http://www.tehnic.go.ro &
// http://nicuflorica.blogspot.com
// version 3m0

char incomingByte;  // incoming data
int  LED1 = 11;      // red LED pin 
int  LED2 = 10;      // blue LED pin 
int  LED3 = 9;      // green LED pin 

void setup() {
  Serial.begin(9600); // initialization
  pinMode(LED1, OUTPUT);
  pinMode(LED2, OUTPUT);
  pinMode(LED3, OUTPUT);
  Serial.println("Press 1 to LED ON or 0 to LED OFF...");
}

void loop() {
  if (Serial.available() > 0) {  // if the data came
    incomingByte = Serial.read(); // read byte
    if(incomingByte == '0') {
       digitalWrite(LED1, LOW);  // if 1, switch LED Off
       digitalWrite(LED2, LOW);  // if 1, switch LED Off
       digitalWrite(LED3, LOW);  // if 1, switch LED Off
       Serial.println("All LEDs are OFF. Press 1 to RED LED ON! Press 2 to BLUE LED ON! Press 3 to GREEN LED ON!");  // print message
    }
    if(incomingByte == '1') {
       digitalWrite(LED1, HIGH); // if 0, switch LED on
       Serial.println("RED LED is now ON. Press 0 to have all LED OFF!");
    }
    if(incomingByte == '2') {
       digitalWrite(LED2, HIGH); // if 0, switch LED on
       Serial.println("BLUE LED is now ON. Press 0 to have all LED OFF!");
    }
    if(incomingByte == '3') {
       digitalWrite(LED3, HIGH); // if 0, switch LED on
       Serial.println("GREEN LED is now ON. Press 0 to have all LED OFF!");
    }

  }
}

   Am facut si un filmulet cu acest tip de program (sketch), care se numeste Arduino and bluetooth module (III)

   Niste poze cu informatiile care le furnizeaza programul IVT BlueSoleil despre modulul meu:
si alte poze de la teste:


si un al patrulea filmulet numit Arduino and bluetooth module (IV)

   Am marit numarul de posibiltati de combinare a culorilor, 


sketch-ul devenind:
// adapted sketch from http://english.cxem.net/arduino/arduino4.php
// by niq_ro from http://www.tehnic.go.ro &
// http://nicuflorica.blogspot.com
// version 4m0 by Nicu FLORICA - 04.2013, Craiova - ROMANIA

char incomingByte;  // incoming data
int  LED1 = 11;      // red LED pin 
int  LED2 = 10;      // blue LED pin 
int  LED3 = 9;      // green LED pin 

void setup() {
  Serial.begin(9600); // initialization
  pinMode(LED1, OUTPUT);
  pinMode(LED2, OUTPUT);
  pinMode(LED3, OUTPUT);
  Serial.println("Press 1 to 7 or 0 to RGB LED ON or OFF...");
  Serial.println("adapted sketch by niq_ro from http://nicuflorica.blogspot.com");
}

void loop() {
  if (Serial.available() > 0) {  // if the data came
    incomingByte = Serial.read(); // read byte
    if(incomingByte == '0') {
       digitalWrite(LED1, HIGH); // if 0, switch LED on
       digitalWrite(LED2, HIGH); // if 0, switch LED on 
       digitalWrite(LED3, HIGH); // if 0, switch LED on 
       delay (100);
       digitalWrite(LED1, LOW);  // if 1, switch LED Off
       digitalWrite(LED2, LOW);  // if 1, switch LED Off
       digitalWrite(LED3, LOW);  // if 1, switch LED Off
       Serial.println("All LEDs are OFF.");  // print message
       Serial.println("Press 1 to RED LED ON!");
         Serial.println("Press 2 to BLUE LED ON!");
           Serial.println("Press 3 to GREEN LED ON!");
             Serial.println("Press 4 to RED & BLUE LEDs ON!");
               Serial.println("Press 5 to RED & GREEN LEDs ON!");
                 Serial.println("Press 6 to BLUE & GREEN LEDs ON!");
                   Serial.println("Press 7 to RED & BLUE & GREEN LEDs ON!");
       }
    if(incomingByte == '1') {
      // first all LEDs will be OFF 
       digitalWrite(LED1, LOW);  // if 1, switch LED Off
       digitalWrite(LED2, LOW);  // if 1, switch LED Off
       digitalWrite(LED3, LOW);  // if 1, switch LED Off
       digitalWrite(LED1, HIGH); // if 0, switch LED on
       Serial.println("RED LED is now ON. Press 0 to have all LED OFF!");
    }
    if(incomingByte == '2') {
       digitalWrite(LED1, LOW);  // if 1, switch LED Off
       digitalWrite(LED2, LOW);  // if 1, switch LED Off
       digitalWrite(LED3, LOW);  // if 1, switch LED Off
       digitalWrite(LED2, HIGH); // if 0, switch LED on
       Serial.println("BLUE LED is now ON. Press 0 to have all LED OFF!");
    }
    if(incomingByte == '3') {
       digitalWrite(LED1, LOW);  // if 1, switch LED Off
       digitalWrite(LED2, LOW);  // if 1, switch LED Off
       digitalWrite(LED3, LOW);  // if 1, switch LED Off
       digitalWrite(LED3, HIGH); // if 0, switch LED on
       Serial.println("GREEN LED is now ON. Press 0 to have all LED OFF!");
    }
    if(incomingByte == '4') {
       digitalWrite(LED1, LOW);  // if 1, switch LED Off
       digitalWrite(LED2, LOW);  // if 1, switch LED Off
       digitalWrite(LED3, LOW);  // if 1, switch LED Off
       digitalWrite(LED1, HIGH); // if 0, switch LED on
       digitalWrite(LED2, HIGH); // if 0, switch LED on 
       Serial.println("RED & BLUE LEDs is now ON. Press 0 to have all LED OFF!");
    }
    if(incomingByte == '5') {
       digitalWrite(LED1, LOW);  // if 1, switch LED Off
       digitalWrite(LED2, LOW);  // if 1, switch LED Off
       digitalWrite(LED3, LOW);  // if 1, switch LED Off
       digitalWrite(LED1, HIGH); // if 0, switch LED on
       digitalWrite(LED3, HIGH); // if 0, switch LED on 
       Serial.println("RED & GREEN LEDs is now ON. Press 0 to have all LED OFF!");
    }
    if(incomingByte == '6') {
       digitalWrite(LED1, LOW);  // if 1, switch LED Off
       digitalWrite(LED2, LOW);  // if 1, switch LED Off
       digitalWrite(LED3, LOW);  // if 1, switch LED Off
       digitalWrite(LED2, HIGH); // if 0, switch LED on
       digitalWrite(LED3, HIGH); // if 0, switch LED on 
       Serial.println("BLUE & GREEN LEDs is now ON. Press 0 to have all LED OFF!");
    }
    if(incomingByte == '7') {
       digitalWrite(LED1, LOW);  // if 1, switch LED Off
       digitalWrite(LED2, LOW);  // if 1, switch LED Off
       digitalWrite(LED3, LOW);  // if 1, switch LED Off
       digitalWrite(LED1, HIGH); // if 0, switch LED on
       digitalWrite(LED2, HIGH); // if 0, switch LED on 
       digitalWrite(LED3, HIGH); // if 0, switch LED on 
       Serial.println("RED & BLUE & GREEN LEDs is now ON. Press 0 to have all LED OFF!");
    }
  }
}
iar filmuletul, care prezinta functionarea se numeste Arduino and bluetooth module (V)

08.mai.2013
   Am mai gasit niste informatii, care pot fi utile la http://www.hobbytronics.co.uk/bluetooth-module-connection

09.mai.2013
   M-am mai jucat un pic cu modulul bluetooth si am modiifcat putin sketch-ul pentru a stinge LED-urile si la apasarea tastelor 8 si 9 (fata de cel dinainte cand se stingeau doar la cifra 0):


// adapted sketch from http://english.cxem.net/arduino/arduino4.php
// by niq_ro from http://www.tehnic.go.ro &
// http://nicuflorica.blogspot.com
// version 4m1 by Nicu FLORICA - 05.2013, Craiova - ROMANIA

char incomingByte;  // incoming data
int  LED1 = 11;      // red LED pin 
int  LED2 = 10;      // blue LED pin 
int  LED3 = 9;      // green LED pin 

void setup() {
  Serial.begin(9600); // initialization
  pinMode(LED1, OUTPUT);
  pinMode(LED2, OUTPUT);
  pinMode(LED3, OUTPUT);
    Serial.println("Press 1 to RED LED ON!");
         Serial.println("Press 2 to BLUE LED ON!");
           Serial.println("Press 3 to GREEN LED ON!");
             Serial.println("Press 4 to RED & BLUE LEDs ON!");
               Serial.println("Press 5 to RED & GREEN LEDs ON!");
                 Serial.println("Press 6 to BLUE & GREEN LEDs ON!");
                   Serial.println("Press 7 to RED & BLUE & GREEN LEDs ON!");
    Serial.println("Press 0, 8 or 9 to have all LED OFF!");
  Serial.println("adapted sketch by niq_ro from http://nicuflorica.blogspot.com");
}

void loop() {
  if (Serial.available() > 0) {  // if the data came
    incomingByte = Serial.read(); // read byte
    if(incomingByte == '0' || incomingByte == '8' || incomingByte == '9') {
     //  digitalWrite(LED1, HIGH); // if 0, switch LED on
     //  digitalWrite(LED2, HIGH); // if 0, switch LED on 
     //  digitalWrite(LED3, HIGH); // if 0, switch LED on 
     //   delay (10);
       digitalWrite(LED1, LOW);  // if 1, switch LED Off
       digitalWrite(LED2, LOW);  // if 1, switch LED Off
       digitalWrite(LED3, LOW);  // if 1, switch LED Off
       Serial.println("All LEDs are OFF.");  // print message
       Serial.println("Press 1 to RED LED ON!");
         Serial.println("Press 2 to BLUE LED ON!");
           Serial.println("Press 3 to GREEN LED ON!");
             Serial.println("Press 4 to RED & BLUE LEDs ON!");
               Serial.println("Press 5 to RED & GREEN LEDs ON!");
                 Serial.println("Press 6 to BLUE & GREEN LEDs ON!");
                   Serial.println("Press 7 to RED & BLUE & GREEN LEDs ON!");
       }
    if(incomingByte == '1') {
      // first all LEDs will be OFF 
       digitalWrite(LED1, LOW);  // if 1, switch LED Off
       digitalWrite(LED2, LOW);  // if 1, switch LED Off
       digitalWrite(LED3, LOW);  // if 1, switch LED Off
       digitalWrite(LED1, HIGH); // if 0, switch LED on
       Serial.println("RED LED is now ON. Press 0, 8 or 9 to have all LED OFF!");
    }
    if(incomingByte == '2') {
       digitalWrite(LED1, LOW);  // if 1, switch LED Off
       digitalWrite(LED2, LOW);  // if 1, switch LED Off
       digitalWrite(LED3, LOW);  // if 1, switch LED Off
       digitalWrite(LED2, HIGH); // if 0, switch LED on
       Serial.println("BLUE LED is now ON. Press 0, 8 or 9 to have all LED OFF!");
    }
    if(incomingByte == '3') {
       digitalWrite(LED1, LOW);  // if 1, switch LED Off
       digitalWrite(LED2, LOW);  // if 1, switch LED Off
       digitalWrite(LED3, LOW);  // if 1, switch LED Off
       digitalWrite(LED3, HIGH); // if 0, switch LED on
       Serial.println("GREEN LED is now ON. Press 0, 8 or 9 to have all LED OFF!");
    }
    if(incomingByte == '4') {
       digitalWrite(LED1, LOW);  // if 1, switch LED Off
       digitalWrite(LED2, LOW);  // if 1, switch LED Off
       digitalWrite(LED3, LOW);  // if 1, switch LED Off
       digitalWrite(LED1, HIGH); // if 0, switch LED on
       digitalWrite(LED2, HIGH); // if 0, switch LED on 
       Serial.println("RED & BLUE LEDs is now ON. Press 0, 8 or 9 to have all LED OFF!");
    }
    if(incomingByte == '5') {
       digitalWrite(LED1, LOW);  // if 1, switch LED Off
       digitalWrite(LED2, LOW);  // if 1, switch LED Off
       digitalWrite(LED3, LOW);  // if 1, switch LED Off
       digitalWrite(LED1, HIGH); // if 0, switch LED on
       digitalWrite(LED3, HIGH); // if 0, switch LED on 
       Serial.println("RED & GREEN LEDs is now ON. Press 0, 8 or 9 to have all LED OFF!");
    }
    if(incomingByte == '6') {
       digitalWrite(LED1, LOW);  // if 1, switch LED Off
       digitalWrite(LED2, LOW);  // if 1, switch LED Off
       digitalWrite(LED3, LOW);  // if 1, switch LED Off
       digitalWrite(LED2, HIGH); // if 0, switch LED on
       digitalWrite(LED3, HIGH); // if 0, switch LED on 
       Serial.println("BLUE & GREEN LEDs is now ON. Press 0, 8 or 9 to have all LED OFF!");
    }
    if(incomingByte == '7') {
       digitalWrite(LED1, LOW);  // if 1, switch LED Off
       digitalWrite(LED2, LOW);  // if 1, switch LED Off
       digitalWrite(LED3, LOW);  // if 1, switch LED Off
       digitalWrite(LED1, HIGH); // if 0, switch LED on
       digitalWrite(LED2, HIGH); // if 0, switch LED on 
       digitalWrite(LED3, HIGH); // if 0, switch LED on 
       Serial.println("RED & BLUE & GREEN LEDs is now ON. Press 0, 8 or 9 to have all LED OFF!");
    }
  }
}


Ministatie meteo cu senzorul DHT11 si.. Arduino

   Desi o statie meteo ofera mai multe date decat temperatura si umiditatea, am considerat ca si aceste date sunt "bune" pentru o "ministatie meteo"...
   Totul se bazeaza pe un senzor dedicat DHT11, care nu are o precize uimitoare, dar pentru aplicatii casnice este  acceptabil (domeniu de temperatura 0..50oC cu precizie de +2oC, respectiv umiditate 20..90%RH cu o precizie de +5%RH).
   Inainte de a face vreo proba, m-am documentat un pic si primele adrese relevante ar fi:
http://www.hobbyist.co.nz/?q=taxonomy/term/10
http://learn.adafruit.com/dht/connecting-to-a-dhtxx-sensor
http://playground.arduino.cc/main/DHT11Lib
http://stigern.net/blog/?p=373
http://arduino-info.wikispaces.com/PROJECT-Temp-Humidity-Display
http://dalxxdht11.blogspot.ro/2012/12/dht11-library-for-arduino-uno.html

   Prima proba s-a facut cu senzorul DHT11 avand pinul conectat la A2 (analog 2) de la Arduino, iar afisajul cu cristale lichide cu 16 coloane si 2 randuri LCD1602 conectat ca in exemplele de pe site-ul Arduino,

sketck-ul folosit fiind:


// LCD1602A 
// * LCD RS pin to digital pin 12
// * LCD Enable pin to digital pin 11
// * LCD D4 pin to digital pin 5
// * LCD D5 pin to digital pin 4
// * LCD D6 pin to digital pin 3
// * LCD D7 pin to digital pin 2
// * LCD R/W pin to ground
// * 10K resistor:
// * ends to +5V and ground
// * wiper to LCD VO pin (pin 3)

//Celsius to Fahrenheit conversion
double Fahrenheit(double celsius)
{
        return 1.8 * celsius + 32;
}

double Kelvin(double celsius)
{
        return celsius + 273.15;
}

double dewPoint(double celsius, double humidity)
{
        double RATIO = 373.15 / (273.15 + celsius);  // RATIO was originally named A0, possibly confusing in Arduino context
        double SUM = -7.90298 * (RATIO - 1);
        SUM += 5.02808 * log10(RATIO);
        SUM += -1.3816e-7 * (pow(10, (11.344 * (1 - 1/RATIO ))) - 1) ;
        SUM += 8.1328e-3 * (pow(10, (-3.49149 * (RATIO - 1))) - 1) ;
        SUM += log10(1013.246);
        double VP = pow(10, SUM - 3) * humidity;
        double T = log(VP/0.61078);   // temp var
        return (241.88 * T) / (17.558 - T);
}

// delta max = 0.6544 wrt dewPoint()
// 5x faster than dewPoint()
// reference: http://en.wikipedia.org/wiki/Dew_point
double dewPointFast(double celsius, double humidity)
{
        double a = 17.271;
        double b = 237.7;
        double temp = (a * celsius) / (b + celsius) + log(humidity/100);
        double Td = (b * temp) / (a - temp);
        return Td;
}

#include <dht11.h>
dht11 DHT11;
#define DHT11PIN A2 // sensor pin is at A2
// include the library code:
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup()
{
  Serial.begin(9600);
  Serial.println("DHT11 TEST PROGRAM ");
  Serial.print("LIBRARY VERSION: ");
  Serial.println(DHT11LIB_VERSION);
  Serial.println();
    // set up the LCD's number of columns and rows: 
  lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.print("ministatie meteo");
}

void loop()
{
  Serial.println("\n");

  int chk = DHT11.read(DHT11PIN);

  Serial.print("Read sensor: ");
  switch (chk)
  {
    case DHTLIB_OK: 
                Serial.println("OK"); 
                break;
    case DHTLIB_ERROR_CHECKSUM: 
                Serial.println("Checksum error"); 
                break;
    case DHTLIB_ERROR_TIMEOUT: 
                Serial.println("Time out error"); 
                break;
    default: 
                Serial.println("Unknown error"); 
                break;
  }

  Serial.print("Humidity (%): ");
  Serial.println((float)DHT11.humidity, 2);

  Serial.print("Temperature (oC): ");
  Serial.println((float)DHT11.temperature, 2);

  Serial.print("Temperature (oF): ");
  Serial.println(Fahrenheit(DHT11.temperature), 2);

  Serial.print("Temperature (K): ");
  Serial.println(Kelvin(DHT11.temperature), 2);

  Serial.print("Dew Point (oC): ");
  Serial.println(dewPoint(DHT11.temperature, DHT11.humidity));

  Serial.print("Dew PointFast (oC): ");
  Serial.println(dewPointFast(DHT11.temperature, DHT11.humidity));

  delay(2000);

 // set the cursor to column 0, line 1
  // (note: line 1 is the second row, since counting begins with 0):
  lcd.setCursor(1, 1);
  // print the number of seconds since reset:
  lcd.print((float)DHT11.temperature, 1);
  lcd.write(0b11011111);
  lcd.print("C H=");

  lcd.print((float)DHT11.humidity, 1);
  lcd.print("%");
}




   Am facut si un filmulet numit ministatie meteo cu DHT11, LCD1602 si Arduino (I):

   Am conectat apoi afisajul LCD 1602A cu interfata i2c cu sketch-ul gasit la http://blog.gotencool.com/2012_03_01_archive.html modificand adresa de la 0x27 la 0x20

#include <Wire.h>
  
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x20,16,2); // 0x27 es la direccion del LCD 16x2
void setup(){
    lcd.init(); 
    lcd.backlight(); //enciende la iluminacion
    lcd.setCursor(0, 0);
    lcd.print("Probando i2c");
}
void loop(){
    delay(1000);
}



apoi am combinat cele 2 sketch-uri:

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x20,16,2); // 0x27 es la direccion del LCD 16x2
//Celsius to Fahrenheit conversion
double Fahrenheit(double celsius)
{
        return 1.8 * celsius + 32;
}

double Kelvin(double celsius)
{
        return celsius + 273.15;
}

double dewPoint(double celsius, double humidity)
{
        double RATIO = 373.15 / (273.15 + celsius);  // RATIO was originally named A0, possibly confusing in Arduino context
        double SUM = -7.90298 * (RATIO - 1);
        SUM += 5.02808 * log10(RATIO);
        SUM += -1.3816e-7 * (pow(10, (11.344 * (1 - 1/RATIO ))) - 1) ;
        SUM += 8.1328e-3 * (pow(10, (-3.49149 * (RATIO - 1))) - 1) ;
        SUM += log10(1013.246);
        double VP = pow(10, SUM - 3) * humidity;
        double T = log(VP/0.61078);   // temp var
        return (241.88 * T) / (17.558 - T);
}

// delta max = 0.6544 wrt dewPoint()
// 5x faster than dewPoint()
double dewPointFast(double celsius, double humidity)
{
        double a = 17.271;
        double b = 237.7;
        double temp = (a * celsius) / (b + celsius) + log(humidity/100);
        double Td = (b * temp) / (a - temp);
        return Td;
}


si 

#include <dht11.h>
dht11 DHT11;
#define DHT11PIN A2 // sensor pin is at A2

void setup()
{
  Serial.begin(9600);
  Serial.println("DHT11 TEST PROGRAM ");
  Serial.print("LIBRARY VERSION: ");
  Serial.println(DHT11LIB_VERSION);
  }

void loop()
{
  Serial.println("\n");
  int chk = DHT11.read(DHT11PIN);
  Serial.print("Read sensor: ");
  switch (chk)
  {
    case DHTLIB_OK: 
                Serial.println("OK"); 
                break;
    case DHTLIB_ERROR_CHECKSUM: 
                Serial.println("Checksum error"); 
                break;
    case DHTLIB_ERROR_TIMEOUT: 
                Serial.println("Time out error"); 
                break;
    default: 
                Serial.println("Unknown error"); 
                break;
  }

  Serial.print("Humidity (%): ");
  Serial.println((float)DHT11.humidity, 2);

  Serial.print("Temperature (oC): ");
  Serial.println((float)DHT11.temperature, 2);

  Serial.print("Temperature (oF): ");
  Serial.println(Fahrenheit(DHT11.temperature), 2);

  Serial.print("Temperature (K): ");
  Serial.println(Kelvin(DHT11.temperature), 2);

  Serial.print("Dew Point (oC): ");
  Serial.println(dewPoint(DHT11.temperature, DHT11.humidity));

  Serial.print("Dew PointFast (oC): ");
  Serial.println(dewPointFast(DHT11.temperature, DHT11.humidity));
  delay(2000);

 //LCD16x2 with i2c control - see http://www.tehnic.go.ro
  lcd.init(); 
  lcd.backlight(); //voi aprinde si led-ul de fundal
  // set up the LCD's number of columns and rows: 
  //lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.print("ministatie meteo");
  lcd.setCursor(1, 1);
  // print the number of seconds since reset:
  lcd.print((float)DHT11.temperature, 1);
  lcd.write(0b11011111);
  lcd.print("C H=");
  lcd.print((float)DHT11.humidity, 1);
  lcd.print("%");
  delay(2000);
}




   Un filmulet, care prezinta modul de functionare, se numeste ministatie meteo cu DHT11, LCD1602 si Arduino (II)



    Am schimbat un pic aranjamentul din sketch:

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x20,16,2); // 0x27 es la direccion del LCD 16x2

//Celsius to Fahrenheit conversion
double Fahrenheit(double celsius)
{
        return 1.8 * celsius + 32;
}

double Kelvin(double celsius)
{
        return celsius + 273.15;
}

double dewPoint(double celsius, double humidity)
{
        double RATIO = 373.15 / (273.15 + celsius);  // RATIO was originally named A0, possibly confusing in Arduino context
        double SUM = -7.90298 * (RATIO - 1);
        SUM += 5.02808 * log10(RATIO);
        SUM += -1.3816e-7 * (pow(10, (11.344 * (1 - 1/RATIO ))) - 1) ;
        SUM += 8.1328e-3 * (pow(10, (-3.49149 * (RATIO - 1))) - 1) ;
        SUM += log10(1013.246);
        double VP = pow(10, SUM - 3) * humidity;
        double T = log(VP/0.61078);   // temp var
        return (241.88 * T) / (17.558 - T);
}

// delta max = 0.6544 wrt dewPoint()
// 5x faster than dewPoint()
// reference: http://en.wikipedia.org/wiki/Dew_point
double dewPointFast(double celsius, double humidity)
{
        double a = 17.271;
        double b = 237.7;
        double temp = (a * celsius) / (b + celsius) + log(humidity/100);
        double Td = (b * temp) / (a - temp);
        return Td;
}

#include <dht11.h>
dht11 DHT11;
#define DHT11PIN A2 // sensor pin is at A2

void setup()
{
  Serial.begin(9600);
  Serial.println("DHT11 TEST PROGRAM ");
  Serial.print("LIBRARY VERSION: ");
  Serial.println(DHT11LIB_VERSION);
  
lcd.init(); 
  lcd.backlight(); //voi aprinde si led-ul de fundal
  // set up the LCD's number of columns and rows: 
  //lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.print("ministatie meteo");
}
void loop()
{
  Serial.println("\n");
  int chk = DHT11.read(DHT11PIN);
  Serial.print("Read sensor: ");
  switch (chk)
  {
    case DHTLIB_OK: 
                Serial.println("OK"); 
                break;
    case DHTLIB_ERROR_CHECKSUM: 
                Serial.println("Checksum error"); 
                break;
    case DHTLIB_ERROR_TIMEOUT: 
                Serial.println("Time out error"); 
                break;
    default: 
                Serial.println("Unknown error"); 
                break;
  }

  Serial.print("Humidity (%): ");
  Serial.println((float)DHT11.humidity, 2);

  Serial.print("Temperature (oC): ");
  Serial.println((float)DHT11.temperature, 2);

  Serial.print("Temperature (oF): ");
  Serial.println(Fahrenheit(DHT11.temperature), 2);

  Serial.print("Temperature (K): ");
  Serial.println(Kelvin(DHT11.temperature), 2);

  Serial.print("Dew Point (oC): ");
  Serial.println(dewPoint(DHT11.temperature, DHT11.humidity));

  Serial.print("Dew PointFast (oC): ");
  Serial.println(dewPointFast(DHT11.temperature, DHT11.humidity));
  delay(2000);

 //LCD16x2 with i2c control - see http://www.tehnic.go.ro
  
  lcd.setCursor(0, 1);
  lcd.print("t=");
  lcd.print((float)DHT11.temperature, 1);
  lcd.write(0b11011111);
  lcd.print("C H=");
  lcd.print((float)DHT11.humidity, 1);
  lcd.print("%");
  delay(2000);
}

   Am introdus si partea de "reclama": "www.tehnic.go.ro creat de niq_ro", apoi "ministatie meteo versiunea 1m1" pastrand si posibilitatea monitorizarii seriale pe ecranul monitorului.



#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x20,16,2); // 0x20 is adress my I2C adapter
#include <dht11.h>
dht11 DHT11;
#define DHT11PIN A2 // sensor pin is at A2

void setup()
{
  Serial.begin(9600);
  Serial.println("DHT11 TEST PROGRAM ");
  Serial.print("LIBRARY VERSION: ");
  Serial.println(DHT11LIB_VERSION);
  
lcd.init(); 
  lcd.backlight(); //voi aprinde si led-ul de fundal
  // set up the LCD's number of columns and rows: 
  lcd.begin(16, 2);
  // Print a logo message to the LCD.
  lcd.print("www.tehnic.go.ro");  
  lcd.setCursor(0, 1);
  lcd.print("creat de niq_ro");
  delay (2500);
  lcd.clear();
   
  // Print a permanent message to the LCD.
  lcd.print("ministatie meteo");
  lcd.setCursor(2, 1);
  lcd.print("versiunea 1m1");
  delay (2500);
}
void loop()
{
  Serial.println("\n");
  int chk = DHT11.read(DHT11PIN);
  Serial.print("Read sensor: ");
  switch (chk)
  {
    case DHTLIB_OK: 
                Serial.println("OK"); 
                break;
    case DHTLIB_ERROR_CHECKSUM: 
                Serial.println("Checksum error"); 
                break;
    case DHTLIB_ERROR_TIMEOUT: 
                Serial.println("Time out error"); 
                break;
    default: 
                Serial.println("Unknown error"); 
                break;
  }

  Serial.print("Humidity (%): ");
  Serial.println((float)DHT11.humidity, 2);

  Serial.print("Temperature (oC): ");
  Serial.println((float)DHT11.temperature, 2);

 //LCD16x2 with i2c control - see http://www.tehnic.go.ro
  lcd.setCursor(0, 1);
  lcd.print("t=");
  lcd.print((float)DHT11.temperature, 1);
  lcd.write(0b11011111);
  lcd.print("C H=");
  lcd.print((float)DHT11.humidity, 1);
  lcd.print("%");
  delay(2000);
}

   Filmuletul care prezinta cum se numeste ministatie meteo cu DHT11, LCD1602 si Arduino (III)
15.mai.2013
   Am refacut sketch-ul, cu versiunea 2m0, folosind alte biblioteci, obtinand:
 



#include "DHT.h"
#define DHTPIN A2     // what pin we're connected to
#define DHTTYPE DHT11   // DHT 11 
DHT dht(DHTPIN, DHTTYPE);

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x20,16,2); // 0x20 is adresss for LCC 16x2

void setup(){
  dht.begin();
  lcd.init(); 
  lcd.backlight(); //backlight is now ON
  // set up the LCD's number of columns and rows: 
  lcd.begin(16, 2);
  // Print a logo message to the LCD.
  lcd.print("www.tehnic.go.ro");  
  lcd.setCursor(0, 1);
  lcd.print(" creat de niq_ro");
  delay (2500);
  lcd.clear();
   
  lcd.print(" senzor DHT11 +");
  lcd.setCursor(0, 1);
  lcd.print("i2c pt. LCD 16x2");
  delay (2500);
  lcd.clear();
  
  lcd.print("ministatie meteo");
  lcd.setCursor(0, 1);
  lcd.print("  versiune 2m0");
  delay (2500);
  lcd.clear();
}
void loop(){
  int h = dht.readHumidity();
  int t = dht.readTemperature();
  // check if returns are valid, if they are NaN (not a number) then something went wrong!
  if (isnan(t) || isnan(h)) {
    lcd.clear();
    lcd.print(" eroare senzor");
    lcd.setCursor(5, 1);
    lcd.print("DHT11");
  } else {
    //lcd.clear();
    lcd.print("temperatura="); 
    lcd.print(t);
    lcd.write(0b11011111);
    lcd.print("C");
    lcd.setCursor(0, 1);
    lcd.print("  umiditate="); 
    lcd.print(h);
    lcd.print("% ");
    }
    delay (2000);
    }

   Un filmulet cu noul mod de prezentare se numeste ministatie meteo cu DHT11, LCD1602 si Arduino (IV).

   Deoarece parametrii masurati nu se modifica prea repede, avand in vedere ca masurarea nu se face cu zecimale, iar eroarea de masura e mare (+2 grade Celsius, ca sa nu mai zic la umiditate de +5 procente) am "pus" un punct care se aprinde cu intermitenta pe randul al doilea, sketch-ul devenind versiunea 2m1:
#include "DHT.h"
#define DHTPIN A2     // what pin we're connected to
#define DHTTYPE DHT11   // DHT 11 
DHT dht(DHTPIN, DHTTYPE);

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x20,16,2); // 0x20 is adresss for LCC 16x2

void setup(){
  dht.begin();
  lcd.init(); 
  lcd.backlight(); //backlight is now ON
  // set up the LCD's number of columns and rows: 
  lcd.begin(16, 2);
  // Print a logo message to the LCD.
  lcd.print("www.tehnic.go.ro");  
  lcd.setCursor(0, 1);
  lcd.print(" creat de niq_ro");
  delay (2500);
  lcd.clear();
   
  lcd.print(" senzor DHT11 +");
  lcd.setCursor(0, 1);
  lcd.print("i2c pt. LCD 16x2");
  delay (2500);
  lcd.clear();
  
  lcd.print("ministatie meteo");
  lcd.setCursor(0, 1);
  lcd.print("  versiune 2m1");
  delay (2500);
  lcd.clear();
}
void loop(){
  int h = dht.readHumidity();
  int t = dht.readTemperature();
  // check if returns are valid, if they are NaN (not a number) then something went wrong!
  if (isnan(t) || isnan(h)) {
    lcd.clear();
    lcd.print(" eroare senzor");
    lcd.setCursor(5, 1);
    lcd.print("DHT11");
  } else {
    //lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("temperatura="); 
    lcd.print(t);
    lcd.write(0b11011111);
    lcd.print("C");
    lcd.setCursor(2, 1);
    lcd.print("umiditate="); 
    lcd.print(h);
    lcd.print("%");
    }
    delay (2000);
    lcd.setCursor(0, 1);
    lcd.print(".");
    delay(250);
    lcd.setCursor(0, 1);
    lcd.print(" ");
}