ArduShop.ro

ArduShop.ro
cod Z4A413ZN reducere 5%, pentru vizitatorii paginilor mele !

miercuri, 16 octombrie 2013

Termometru dublu cu LM335Z si un afisaj LCD cu 16 coloane si 2 randuri (II)

   Mi-am adus aminte de placuta (brick-u') cu LED-ul RGB, de l-am prezentat in articolul Arduino si un LED multicolor (RGB):
si m-am gandit sa fac un "indicator de confort", sa zic asa, adica voi aprinde LED-ul albastru cand este temperatura mai scazuta decat 19 grade Celsius, pe cel verde cand este intre 19 si 26 grade, iar cel rosu daca temperatura este mai mare de 26 grade Celsius.

   Schema de conectare este simpla, combinatia celei de masurare:

 cu cea de afisare cu LED multicolor (RGB):

   Sketch-ul deriva din cel de masurare a 2 temperaturi:
/*
original sketch by niq_ro (Nicu FLORICA) from http://nicuflorica.blogspot.com
version 1.6
program original scris de mine (niq_ro) versiunea 1.6
..............................................................*/

#include <LiquidCrystal.h>
// folosesc libraria pentru afisaje LCD simple
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
// indic modul de legare, vezi mai jos:
/*                                    -------------------
                                      |  LCD  | Arduino |
                                      -------------------
 LCD RS pin to digital pin 7          |  RS   |   D7    |
 LCD Enable pin to digital pin 6      |  E    |   D6    |
 LCD D4 pin to digital pin 5          |  D4   |   D5    |
 LCD D5 pin to digital pin 4          |  D5   |   D4    |
 LCD D6 pin to digital pin 3          |  D6   |   D3    |
 LCD D7 pin to digital pin 2          |  D7   |   D2    |
 LCD R/W pin to ground                |  R/W  |   GND   |
                                      -------------------
*/
// http://arduino.cc/en/Reference/LiquidCrystalCreateChar

byte home13[8] = {
  B00011,
  B00100,
  B01000,
  B11111,
  B01000,
  B01000,
  B01111,
};

byte home23[8] = {
  B00000,
  B10110,
  B01110,
  B11111,
  B00100,
  B00100,
  B11100,
};

byte home33[8] = {
  B00011,
  B10110,
  B01110,
  B11111,
  B00100,
  B00100,
  B11100,
};

byte home03[8] = {
  B11111,
  B00000,
  B00000,
  B11111,
  B00000,
  B00000,
  B11111,
};

byte grad[8] = {
  B01100,
  B10010,
  B10010,
  B01100,
  B00000,
  B00000,
  B00000,
};

byte copac12[8] = {
  B00111,
  B01000,
  B10101,
  B10010,
  B01000,
  B00111,
  B00001,
  B00001,
};

byte copac22[8] = {
  B11000,
  B00110,
  B10101,
  B01001,
  B00010,
  B11100,
  B10000,
  B10000,
};



// variables 
// variabile 
int t1, t2;
float t10, t20;
float t11, t21;
float t12, t22;

int temperaturePin1 = A0; // output from first LM335 is put at analog input no.0
int temperaturePin2 = A1; // output from second LM335 is put at analog input no.1
// cei 2 senzori de temperaturia LM335 sunt legati la pinii A0 si A1

// other  
int led = 13; //pin for LED
int ledr = 11; //pin for red LED
int leda = 10; //pin for blue LED
int ledv = 9; //pin for green LED

void setup() {
  lcd.createChar(0, grad);
  lcd.createChar(1, home13);
  lcd.createChar(2, home23);
  lcd.createChar(3, home33);
  lcd.createChar(4, home03);
  lcd.createChar(5, copac12);
  lcd.createChar(6, copac22);
   
  lcd.begin(16, 2); // set up the LCD's number of columns and rows: 
 

pinMode(led, OUTPUT); 
 lcd.clear(); // clear the screen
 lcd.setCursor(0, 0); // put cursor at colon 2 and row 0 = left/up
 lcd.print("dual thermometer"); // print a text
 lcd.setCursor(1, 1); // put cursor at colon 0 and row 0 = left/down
 lcd.print("1.6 by niq_ro"); // print a text
 delay (2000);
 lcd.clear(); // clear the screen
 

} // END void setup
  
void loop(){

  digitalWrite(led, HIGH);  

  // Read and store Sensor Data
t11=0;
t21=0;
//lcd.clear(); // clear the screen

for (int x=1; x <= 5; x++)
  {
// calculate the value  
t1 = analogRead(temperaturePin1); // read value from temperature from first sensor (LM335);
 t10 = 100.0*(5.0*t1/1023-2.980)+25.0;
 t11 = t10 + t11;

t2 = analogRead(temperaturePin2); // read value from temperature from second sensor (LM335);
 t20 = 100.0*(5.0*t2/1023-2.980)+25.0;
 t21 = t20 + t21;

delay (500);
  }   

t12 = t11/5.0 -2.0 ; // average and corrected temperature  
t22 = t21/5.0 -1.0; // average and corrected temperature  

/*
t1 = analogRead(temperaturePin1); // read value from temperature from first sensor (LM335);
t2 = analogRead(temperaturePin2); // read value from temperature from first sensor (LM335);
t10 = (100.0*(5.0*t1/1023.0-2.980)+25.0)-1.0;
t20 = (100.0*(5.0*t2/1023.0-2.980)+25.0);
*/

analogWrite(ledr, 0); 
analogWrite(leda, 0); 
analogWrite(ledv, 0); 


    lcd.setCursor(3, 0);
    lcd.write(byte(1));
  //  lcd.write(byte(4));
    lcd.write(byte(3));
    lcd.print(":");
  //  lcd.print("t1="); 
    if (t12<10) lcd.print(" "); 
    if (t12>0.0) lcd.print("+"); 
    lcd.print(t12,1);
  //  lcd.write(0b11011111);
  lcd.write(byte(0));
    lcd.print("C");
      
    lcd.setCursor(3, 1);
  //  lcd.print("ext:");
    lcd.write(byte(5));
    lcd.write(byte(6));
    lcd.print(":");
  //  lcd.print("t2="); 
    if (t22<10) lcd.print(" "); 
    if (t22>0.0) lcd.print("+"); 
    lcd.print(t22,1);
   // lcd.write(0b11011111);
   lcd.write(byte(0));
    lcd.print("C");
    
digitalWrite(led, LOW); 

// temperature leds indicator
if (t12<=19.0) analogWrite(leda, 255);
if ((t12>19.0) and (t12<26.0)) analogWrite(ledv, 255);
if (t12>=26.0) analogWrite(ledr, 255);

delay(500);
lcd.setCursor(4, 0);
lcd.write(byte(2));

}
   
   Am realizat si un filmulet numit home vs outside temperature with LM335 and Arduino (IV), care explica mai bine cum se comporta montajul:
Schema completa este:

Niciun comentariu:

Trimiteți un comentariu