You are on page 1of 5

// Photocell simple testing sketch.

#include <LiquidCrystal.h>

LiquidCrystal lcd(7,8,9,10,11,12);
//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
int TR_PIN = A10;
double a1, b1, c1, d1, r2, r1, vo, tempC, tempF, tempK;
//For more information see http://learn.adafruit.com/photocells */

int photocellPin = 0;
int photocellReading;

// the cell and 10K pulldown are connected to a0


// the analog reading from the analog resistor divider

int in1 = 50;


int in2 = 48;
void setup(void) {
titlu();

// We'll send debugging information via the Serial monitor


Serial.begin(9600);
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);
digitalWrite(in1, HIGH);
digitalWrite(in2, HIGH);// releu
// initializare sez temp
a1 =3.354016E-03 ;
b1 = 2.569850E-04 ;

c1 = 2.620131E-06 ;
d1 = 6.383091E-08 ;

r1 = 9720.0;

pinMode(TR_PIN, INPUT);
//
}

void loop(void) {
photocellReading = analogRead(photocellPin); // citire fotorezistenta
// read the temp
vo = analogRead(TR_PIN);
vo = vo / (1023.0 / 5.0);
//temp();
Serial.print("Analog reading = ");
Serial.print(photocellReading);

// the raw analog reading

// lcd.print("Analog reading = ");


// lcd.print(photocellReading);
// We'll have a few threshholds, qualitatively determined
if (tempC<28){digitalWrite(in2, LOW);}

// modificare temp

else if (tempC>38){digitalWrite(in2, HIGH);}


if (photocellReading < 10) {lcd.clear(); titlu();temp();
lcd.setCursor(0, 4);
Serial.println(" - Dark");
lcd.print(" Becul este aprins ");

digitalWrite(in1, LOW);
} else if (photocellReading < 200) {lcd.clear(); titlu();temp();
lcd.setCursor(0, 4);
Serial.println(" - Dim");
lcd.print(" Becul este aprins ");
digitalWrite(in1, LOW);
} else if (photocellReading < 500) {lcd.clear(); titlu();temp();
lcd.setCursor(0, 4);
Serial.println(" - Light");
lcd.print(" Becul este stins ");
digitalWrite(in1, HIGH);
} else if (photocellReading < 800) {lcd.clear(); titlu();temp();
lcd.setCursor(0, 4);
lcd.print(" Becul este stins ");
Serial.println(" - Bright");
digitalWrite(in1, HIGH);
} else {
lcd.clear(); titlu();temp();
lcd.setCursor(0, 4);
lcd.print(" Becul este stins ");
Serial.println(" - Very bright");

digitalWrite(in1, HIGH);
digitalWrite(in2, HIGH);
}

// voltage divider calculation


// vo = 5 * r2 /(r1+r2)
// solve for r2
// get the exact value for voltage divider r1

r2 = ( vo * r1) / (5.0 - vo);

//equation from data sheet


tempK = 1.0 / (a1 + (b1 * (log(r2 / 10000.0))) + (c1 * pow(log(r2 / 10000.0), 2.0))
+ (d1 * pow(log(r2 / 10000.0), 3.0)));
tempC = (tempK - 273.15);
tempF = (tempC * 1.8) + 32.0;

Serial.println("Temp - degK " + String(tempK));


Serial.println("Temp - degC " + String(tempC));
Serial.println("Temp - degF " + String(tempF));
Serial.println(" ");
delay(1000);
}
void temp(){
lcd.setCursor(1, 2);
lcd.print("Temp - degC ");lcd.print(tempC);
}

void titlu(){

lcd.begin(20,4);
lcd.print("

341 EM");

lcd.setCursor(3, 1);
lcd.print("Diaconu Stefan");}

You might also like