//Fuentes Alternas ITTG
//Compatible with the Arduino IDE 1.0
//Library version:1.1
#include <LiquidCrystal_I2C.h>
#include "DHT.h"
#define DHTPIN 2
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
const int I_entrada=A2;
double mVporA=185; //100 para 20A, 66 para 30A
double Iraw=0;
double ACSoffset=2500;
double Voltajei=0;
double Amps=0;
double voltaje=0;
double sensorIn=0;
LiquidCrystal_I2C lcd(0x27,20,4); // set the LCD address to 0x27 for a 16 chars and 2 line display
double Luz(int EntradaA1)
{
double Vsal=EntradaA1*0.0048828125; //volts
int lux=500/(10*((5-Vsal)/Vsal)); //usar esta ecuacion si el LDR esta en la parte sup del divisor de tension
//int lux=((2500/Vsal-500)/10)+90;
return lux;
}
void setup()
{
Serial.begin(9600);
dht.begin();
lcd.init(); // initialize the lcd
// Print a message to the LCD.
}
void loop()
{
//---------corriente-------------
Iraw=analogRead(I_entrada);
Voltajei=(Iraw/1024)*5000; //mV
Amps=(Voltajei-ACSoffset)/mVporA;
//-------voltaje panel-----------------------
int sensorIn=analogRead(A0);
voltaje=sensorIn*(0.0048828)*3.8;//0.0048828125)*4;
// 5/1024=0.0048828125
//Serial.print("Voltaje: ");
//Serial.print(voltaje);
//Serial.println(" V");
//delay(1000);
int lux1=Luz(analogRead(A1));
//-------------------
float h = dht.readHumidity();
// Read temperature as Celsius (the default)
float t = dht.readTemperature();
if (isnan(h) || isnan(t)) {
lcd.setCursor(2,3);
lcd.print("Failed to read from DHT sensor!");
return;
}
float hic = dht.computeHeatIndex(t, h, false);
lcd.backlight();
lcd.setCursor(0,0);
lcd.print("H%: ");
lcd.setCursor(4,0);
lcd.print(h);
lcd.setCursor(10,0);
lcd.print("T(C): ");
lcd.setCursor(15,0);
lcd.print(t);
lcd.setCursor(0,1);
lcd.print("Vfv(v):");
lcd.setCursor(7,1);
lcd.print(voltaje);
lcd.setCursor(0,3);
lcd.print("luxes : ");
lcd.setCursor(7,3);
lcd.print(lux1);
lcd.setCursor(13,1);
lcd.print("I:");
lcd.setCursor(15,1);
lcd.print(Amps);
}