From b2f39314006c4d4c098e00ecae8c9cfab56b8756 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20=C3=81lvarez?= Date: Sat, 12 Mar 2016 18:22:05 +0100 Subject: [PATCH] =?UTF-8?q?simplificaci=C3=B3n=20del=20sensor=20de=20luz,?= =?UTF-8?q?=20reportando=20voltaje=20y=20lumens=20simplemente.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Además añado pruebas del sensor de sonido. --- sketch_lcd/sketch_lcd.ino | 33 +++++++-------------------------- sketch_sound/sketch_sound.ino | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 26 deletions(-) create mode 100644 sketch_sound/sketch_sound.ino diff --git a/sketch_lcd/sketch_lcd.ino b/sketch_lcd/sketch_lcd.ino index baa7257..627b418 100644 --- a/sketch_lcd/sketch_lcd.ino +++ b/sketch_lcd/sketch_lcd.ino @@ -31,11 +31,7 @@ LiquidCrystal lcd(9, 10, 4, 5, 6, 7); // syntax: LiquidCrystal(rs, enable, d4, d int timer = 0; int milis = 0; int ticks = 0; -int tmp = 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 +int luz = 0; 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) { return; } - ticks = timer; - loops++; - tmp = analogRead(PHOTORES_APin); - luzMin = min(luzMin, tmp); - luzMax = max(luzMax, tmp); - luzSum += tmp; + luz = analogRead(PHOTORES_APin); if (timer == 59) { // 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(" i:"); Serial.print(hic); - Serial.print(" la:"); - Serial.print(luzSum/loops); - Serial.print(" ln:"); - Serial.print(luzMin); + Serial.print(" lv:"); + Serial.print(luz); Serial.print(" lx:"); - Serial.print(luzMax); + Serial.print(Lux(luz)); Serial.println(""); lcd.clear(); @@ -103,16 +92,10 @@ void loop() { // put your main code here, to run repeatedly: digitalWrite(13, HIGH); delay(100); digitalWrite(13, LOW); - - // reset counters - loops = 0; - luzMin = 1024; - luzMax = 0; - luzSum = 0; } lcd.setCursor(10, 2); - lcd.print(tmp); + lcd.print(luz); lcd.setCursor(14, 2); 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 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 = (2500 / Vout-500) / 10; + double lux = (2500 / Vout-500) / 10; return lux; } -*/ /* GRAFANA: SELECT (2500 / (mean("avg") * 0.0048828125) - 500) / 10, diff --git a/sketch_sound/sketch_sound.ino b/sketch_sound/sketch_sound.ino new file mode 100644 index 0000000..5e17f39 --- /dev/null +++ b/sketch_sound/sketch_sound.ino @@ -0,0 +1,35 @@ + +/* +http://www.princetronics.com/sound-sensitive-lights-w-sound-sensor-arduino/ +*/ + +#include + +#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); +}