simplificación del sensor de luz, reportando voltaje y lumens simplemente.

Además añado pruebas del sensor de sonido.
This commit is contained in:
Sergio Álvarez 2016-03-12 18:22:05 +01:00
parent cc70861f09
commit b2f3931400
2 changed files with 42 additions and 26 deletions

View File

@ -31,11 +31,7 @@ LiquidCrystal lcd(9, 10, 4, 5, 6, 7); // syntax: LiquidCrystal(rs, enable, d4, d
int timer = 0; int timer = 0;
int milis = 0; int milis = 0;
int ticks = 0; int ticks = 0;
int tmp = 0; int luz = 0;
int loops = 0;
int luzMin = 1024; // máximo de lectura para el sensor
int luzMax = 0;
long luzSum = 0; // value use to exceed INT
void setup() { // put your setup code here, to run once: void setup() { // put your setup code here, to run once:
@ -52,14 +48,9 @@ void loop() { // put your main code here, to run repeatedly:
if (timer == ticks) { if (timer == ticks) {
return; return;
} }
ticks = timer; ticks = timer;
loops++;
tmp = analogRead(PHOTORES_APin); luz = analogRead(PHOTORES_APin);
luzMin = min(luzMin, tmp);
luzMax = max(luzMax, tmp);
luzSum += tmp;
if (timer == 59) { if (timer == 59) {
// Reading temperature or humidity takes about 250 milliseconds! // Reading temperature or humidity takes about 250 milliseconds!
@ -83,12 +74,10 @@ void loop() { // put your main code here, to run repeatedly:
Serial.print(t); Serial.print(t);
Serial.print(" i:"); Serial.print(" i:");
Serial.print(hic); Serial.print(hic);
Serial.print(" la:"); Serial.print(" lv:");
Serial.print(luzSum/loops); Serial.print(luz);
Serial.print(" ln:");
Serial.print(luzMin);
Serial.print(" lx:"); Serial.print(" lx:");
Serial.print(luzMax); Serial.print(Lux(luz));
Serial.println(""); Serial.println("");
lcd.clear(); lcd.clear();
@ -103,16 +92,10 @@ void loop() { // put your main code here, to run repeatedly:
digitalWrite(13, HIGH); digitalWrite(13, HIGH);
delay(100); delay(100);
digitalWrite(13, LOW); digitalWrite(13, LOW);
// reset counters
loops = 0;
luzMin = 1024;
luzMax = 0;
luzSum = 0;
} }
lcd.setCursor(10, 2); lcd.setCursor(10, 2);
lcd.print(tmp); lcd.print(luz);
lcd.setCursor(14, 2); lcd.setCursor(14, 2);
if (timer < 10) if (timer < 10)
@ -123,14 +106,12 @@ void loop() { // put your main code here, to run repeatedly:
} }
/* Not used now
double Lux(int RawADC0) { double Lux(int RawADC0) {
double Vout = RawADC0 * 0.0048828125; double Vout = RawADC0 * 0.0048828125;
//int lux=500/(10*((5-Vout)/Vout));//use this equation if the LDR is in the upper part of the divider //int lux=500/(10*((5-Vout)/Vout));//use this equation if the LDR is in the upper part of the divider
int lux = (2500 / Vout-500) / 10; double lux = (2500 / Vout-500) / 10;
return lux; return lux;
} }
*/
/* GRAFANA: /* GRAFANA:
SELECT (2500 / (mean("avg") * 0.0048828125) - 500) / 10, SELECT (2500 / (mean("avg") * 0.0048828125) - 500) / 10,

View File

@ -0,0 +1,35 @@
/*
http://www.princetronics.com/sound-sensitive-lights-w-sound-sensor-arduino/
*/
#include <LiquidCrystal.h>
#define SOUND_APin A1 // Pin Análogico al que he conectado el sensor de sonido
LiquidCrystal lcd(9, 10, 4, 5, 6, 7); // syntax: LiquidCrystal(rs, enable, d4, d5, d6, d7)
int timer = 0;
int milis = 0;
int sound = 0;
void setup() { // put your setup code here, to run once:
Serial.begin(9600);
lcd.begin(16, 2);
lcd.print(" hue hue hue ");
}
void loop() { // put your main code here, to run repeatedly:
sound = analogRead(SOUND_APin);
lcd.clear();
lcd.setCursor(10, 2);
lcd.print(sound);
Serial.println(sound);
delay(200);
}