ArduShop.ro

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

marți, 21 ianuarie 2014

O fotorezistenta si Arduino (II)

   Fata de articolul precedent, in care am afisat datele pe ecranul de monitorizare seriala, acum o sa afisez pe un LCD1602 (afisaj alfanumeric cu 16 coloane si 2 randuri).
   Deoarece, in ultima perioada, am conectat afisajul doar la pinii D2..D7, o sa mut comanda releului de la D7 la D9, cel de-al doilea ramanand pe D8.
   Schema de conectare devine:
   Un sketch, netestat inca, ar fi de genul:
/* Photocell simple testing sketch. 
Connect one end of the photocell to 5V, the other end to Analog 0.
Then connect one end of a 10K resistor from Analog 0 to ground
For more information see http://learn.adafruit.com/photocells 
niq_ro adapted software program in 20.01.2014, see http://nicuflorica.blogspot.com/
*/

#include <LiquidCrystal.h>
// use LiquidCrystal.h library for alphanumerical display 1602
LiquidCrystal lcd(2,3,4,5,6,7);
/*                                    -------------------
                                      |  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   |
                                      -------------------
*/

int photocellPin = 0;     // the cell and 10K pulldown are connected to a0
int photocellReading;     // the analog reading from the analog resistor divider
 
int relayPin = 9;         // first relay control
int relayPin2 = 8;        // second relay control
 
void setup(void) {
  // We'll send debugging information via the Serial monitor
  Serial.begin(9600); 
  pinMode(relayPin, OUTPUT);  // pin "relayPin" is output pin
  pinMode(relayPin2, OUTPUT);  // pin "relayPin" is output pin

 lcd.begin(16, 2); // set up the LCD's number of columns and rows: 
 lcd.clear(); // clear the screen
 lcd.setCursor(0, 0); // put cursor at colon 0 and row 0
 lcd.print("Fotorezistenta"); // print a text
 lcd.setCursor(0, 1); // put cursor at colon 0 and row 1
 lcd.print("comanda 2 relee"); // print a text
 delay (2000);
 lcd.clear(); // clear the screen

 lcd.clear(); // clear the screen
 lcd.setCursor(1, 0); // put cursor at colon 1 and row 0
 lcd.print("Photoresistor"); // print a text
 lcd.setCursor(0, 1); // put cursor at colon 0 and row 1
 lcd.print("control 2 relay"); // print a text
 delay (2000);

 }
 
void loop(void) {
  digitalWrite(relayPin, HIGH);  // first auxiliar light is off
  digitalWrite(relayPin2, HIGH);  // second auxiliar light is off
  photocellReading = analogRead(photocellPin);  
 
 lcd.clear(); // clear the screen
 if (photocellReading >999) 
 {
lcd.setCursor(0, 0); // put cursor at colon 0 and row 0
 }
 else if (photocellReading >99) 
 {
lcd.setCursor(1, 0); // put cursor at colon 1 and row 0
 }
 else if (photocellReading >9) 
 {
lcd.setCursor(2, 0); // put cursor at colon 2 and row 0
 }
 else
{
lcd.setCursor(3, 0); // put cursor at colon 3 and row 0
 }
 lcd.print(photocellReading); // print a text
 lcd.print(" lx");
  
  Serial.print(photocellReading);     // the raw analog reading
  Serial.print(" lux"); 
  // We'll have a few threshholds, qualitatively determined
  if (photocellReading < 20) {
    Serial.println(" - Dark (intuneric)"); 
    digitalWrite(relayPin, LOW);  // first auxiliar light is on
    digitalWrite(relayPin2, LOW);  // second auxiliar light is on
    Serial.println("All lights are on (Toate luminile sunt aprinse).");
    Serial.println("***********************************************");
  lcd.print(" - Dark");
  lcd.setCursor(2, 1); // put cursor at colon 0 and row 1
  lcd.print("Lights are on");

  } else if (photocellReading < 200) {
    Serial.println(" - Dim (intunecat)");
    digitalWrite(relayPin, LOW);  // first auxiliar light is on
    digitalWrite(relayPin2, HIGH);  // second auxiliar light is off
    Serial.println("First light are on (Un circuit de lumina e aprins).");
    Serial.println("***********************************************");
  lcd.print(" - Dim");
  lcd.setCursor(0, 1); // put cursor at colon 0 and row 1
  lcd.print("1st light are on");

  } else if (photocellReading < 500) {
    Serial.println(" - Light (lumina normala)");
    digitalWrite(relayPin, HIGH);  // first auxiliar light is off
    digitalWrite(relayPin2, HIGH);  // second auxiliar light is off
    Serial.println("All lights are off (Toate luminile sunt stinse).");
    Serial.println("***********************************************");
  lcd.print(" - Light");
  lcd.setCursor(0, 1); // put cursor at colon 0 and row 1
  lcd.print("All lights off!");

  } else if (photocellReading < 800) {
    Serial.println(" - Bright (lumina buna)");
    digitalWrite(relayPin, HIGH);  // first auxiliar light is off
    digitalWrite(relayPin2, HIGH);  // second auxiliar light is off
    Serial.println("All lights are off (Toate luminile sunt stinse).");
    Serial.println("***********************************************");
  lcd.print(" - Bright");
  lcd.setCursor(0, 1); // put cursor at colon 0 and row 1
  lcd.print("All lights off!");

  } else {
    Serial.println(" - Very bright (lumina puternica)");
    digitalWrite(relayPin, HIGH);  // first auxiliar light is off
    digitalWrite(relayPin2, HIGH);  // second auxiliar light is off
    Serial.println("All lights are off (Toate luminile sunt stinse).");
    Serial.println("***********************************************");
  lcd.print("-Dazzling");
  lcd.setCursor(0, 1); // put cursor at colon 0 and row 1
  lcd.print("All lights off!");
  }
  delay(1500);
}
   Am reusit sa fac si o poza:
  Dupa mai multe incercari,am reusit sa fac poze cu cele 4 cazuri:
- lumina orbitoare (soare puternic):
- lumina normala:
- lumina slabuta, s-a aprins un set de lumini, pentru compensare:
- intuneric, s-au aprins ambele circuite de lumini, pentru a compensa lipsa lumnii naturale:
   Filmuletul teste cu fotorezistenta, 2 relee si Arduino (II) realizat cu un aparat photo FujiFilm S5700 este de o calitate slabuta, datorita luminii foarte slabe din camera, dar care ajuta la intelegerea modului de comportare al montajului. 
   Un alt filmulet,numit teste cu fotorezistenta, 2 relee si Arduino (III), a fost facut cu o camera video Praktica DVC 10.1 HDMI:

Niciun comentariu:

Trimiteți un comentariu

Senzor de masurare tensiune si curent INA219

   Am achizitionat de curand, de la colaboratorii mei de la  ArduShop.ro , un modul cu senzor INA219, care poate masura tensiuni pana la 26V...