In articolul Using a Photocell este prezentat un material foarte bun, din care m-am inspirat si eu.
Dupa ce ma incercat primele 2 exemple de acolo, am modificat sketch-ul ca la un anumit prag de intuneric sa se cupleze un releu, iar la lumina foarte slaba (intuneric), inca unul.
Circuitul de conectare al fotorezistentei, este foarte simplu, necesitand doar o rezistenta:
iar placa cu 2 relee are comanda la pinii D7, respectiv D8.
Logica de comanda este inversata, adica daca pe pinul de comanda este 0 logic (LOW), releul este actionat si daca este 1 logic (HIGH) este neconectat, cum am prezentat mai de mult in articolul Placa cu 4 relee pentru Arduino (.. si nu numai).
Montajul testat arata asa (mai contine si alte parti de circuit, nefolosite):
Pe ecran am obtinut:
Sketch-ul adaptat de mine este:
/* 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/
*/
int photocellPin = 0; // the cell and 10K pulldown are connected to a0
int photocellReading; // the analog reading from the analog resistor divider
int relayPin = 7; // 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
}
void loop(void) {
digitalWrite(relayPin, HIGH); // first auxiliar light is off
digitalWrite(relayPin2, HIGH); // second auxiliar light is off
photocellReading = analogRead(photocellPin);
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("***********************************************");
} 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("***********************************************");
} 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("***********************************************");
} 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("***********************************************");
} 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("***********************************************");
}
delay(2500);
}
Am facut si un filmulet, numit teste cu fotorezistenta, 2 relee si Arduino, in care se vede mai bine ce am explicat pana acum:
21.01.2014
Am desenat si schema de conexiuni, pentru a nu aparea confuzii:
Niciun comentariu:
Trimiteți un comentariu