De mis experimentos con Arduino algunos artículos de este blog han ido recogiendo aquello que -por curioso o fascinante- fui aprendiendo con la experiencia. Decidí en algún momento dar un paso atrás, dejar de investigar acerca del código concreto que es necesario para correr la máquina, en el como y con que para contemplar el cuadro con otra perspectiva. Y para ello empleé Libre Draw de la suite de LibreOffice, un "must" del software Libre, si es que tal cosa existe en realidad. Y esto es lo que dibujé:
![]() |
Cuadrados y círculos de muchos colores, con lineas que los unen... fascinante ¿no es así? ...Tantos estudios para esto... |
![]() |
dos unidades de arduino, unos cuantos relés, conexiones, un sensor de luz junto a la pantalla LCD, un sensor de humedad y temperatura en la parte superior... |
¡Ah claro se me olvidaba!, también hace falta un par de versos de idioma máquina para hacerlo funcionar junto. Algo del código esta por ahí en articulos anteriores pero prometo publicar lo que creo que esta ahora corriendo en los artefactos solo para el Marca. ¡¡El "marcachonedo" después!!
![]() |
La pantalla LCD, el sensor de luminosidad y un interruptor para apagar la luz que se activa con el sensor de ultrasonidos |
![]() |
Esta placa de arduino tiene un shield ethernet pero no me atrevo a conectarlo a la red... ¡hay que ser un valiente para hacer eso! |
// _____
// / /____
// / / /____
// /____/ / /____
// | /____/ / /|
// |___| /____/ / |
// |___| /____/ /
// |___| | /
// |____|/
//___________________________
//habiController is habitat automation code for Arduino.
//any questions or comments are welcome.
//contact habitainer@gmail.com
int HALLPin = 5;
int waterSensor = 10;
int LEDPin = 12;
int FotoRpin = A0;
int lightLevel;
int Relay = 4;
int pumpRelay = 11;
int sendSound = 6;
int getSound = 7;
int lightRelay = 3;
long distancia;
long tiempo;
//___________________________
void setup() {
pinMode(LEDPin, OUTPUT);
pinMode(HALLPin, INPUT);
pinMode(Relay, OUTPUT);
pinMode(waterSensor, INPUT);
pinMode(pumpRelay,OUTPUT);
pinMode(sendSound, OUTPUT);
pinMode(getSound, INPUT);
pinMode(lightRelay, OUTPUT);
Serial.begin(9600);
}
//___________________________
void loop() {
//...........................
lightLevel=analogRead(FotoRpin);
{
if (lightLevel > 560)
{
digitalWrite(Relay,HIGH);
Serial.println("room light on");
}
if (lightLevel <= 560)
{
digitalWrite(Relay,LOW);
Serial.println("room light off");
}
//...........................
if(digitalRead(HALLPin)==HIGH)
{
digitalWrite(LEDPin, HIGH);
Serial.println("open door");
}
else
{
digitalWrite(LEDPin, LOW);
Serial.println("closed door");
}
//...........................
if(digitalRead(waterSensor)==LOW)
{
digitalWrite(pumpRelay, LOW),
Serial.println("pump on");
delay(6846);
}
else
{
digitalWrite(pumpRelay, HIGH);
Serial.println("pump off");
}
//...........................
digitalWrite(sendSound, LOW);
delayMicroseconds(3);
digitalWrite(sendSound, HIGH);
delayMicroseconds(10);
tiempo=pulseIn(getSound, HIGH);
distancia= int(0.017*tiempo);
Serial.print("Distancia ");
Serial.print(distancia);
Serial.println(" cms");
if(distancia <50 span="">
{digitalWrite(lightRelay, LOW);
Serial.println("mehane lights on");
}
if(distancia >=50)
{digitalWrite(lightRelay, HIGH);
Serial.println("mekhane lights off");
}
//...........................
Serial.println("________________________");
delay(2468);
}
}
//......................................................................
// Luis Rodriguez Alonso. October 2015. habitainer@gmail.com
// http://habican.blogspot.com.es/
// publicado bajo GNU GENERAL PUBLIC LICENSE
// https://gnu.org/licenses/gpl-3.0.en.html
ARDUCAN 002:
// ____ //
// / /___ //
// / / /___ //
// /____/ / /____ //
// | /____/ / /| //
// |___| /____/ / | //
// |___| /____/ / //
// |___| | / //
// |____|/ //
#include
#include
#include
#include
#define DHTPIN 9
#define DHTTYPE DHT11
LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
int DS18S20_Pin = 12;
int sensorPin1 = A0;
int sensorPin2 = A1;
int Relay = 8;
int photoRPin = A3;
int lightLevel;
int LEDpin = 13;
int alarm = 7;
OneWire ds(DS18S20_Pin);
DHT dht(DHTPIN, DHTTYPE);
void setup(void) {
Serial.begin(9600);
pinMode(alarm,OUTPUT);
dht.begin();
lcd.begin(16,2);
pinMode(Relay, OUTPUT);
digitalWrite(7, LOW);
delay(220);
digitalWrite(7,HIGH);
delay(880);
digitalWrite(7,LOW);
delay(160);
digitalWrite(7,HIGH);
delay(620);
for(int i = 0; i< 3; i++)
{
lcd.backlight();
delay(250);
lcd.noBacklight();
delay(250);
}
lcd.backlight();
lcd.setCursor(0,0);
lcd.print("Habican-Habitainer");
delay(260);
lcd.setCursor(0,1);
lcd.print("smart container ;)");
delay(680);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("DIYdomotics sys");
lcd.setCursor(0,1);
lcd.print("ARDUino_habiCAN");
delay(1358);
}
void loop(void) {
int h = dht.readHumidity();
int t = dht.readTemperature();
lightLevel=analogRead(photoRPin);
float lecture = lightLevel * (5.0 / 1023);
lcd.clear();
lcd.setCursor(12,1);
lcd.print(lecture);
if(lightLevel > 526 )
{
digitalWrite(LEDpin, HIGH);
lcd.backlight();
}
else if(lightLevel < 526 )
{
digitalWrite(LEDpin, LOW);
lcd.noBacklight();
}
float temperature = getTemp();
int reading1 = analogRead(sensorPin1);
float voltage1 = reading1 * 5.0;
voltage1 /= 1024.0;
float temperatureC1 = (voltage1 - 0.5) * 100;
int reading2 = analogRead(sensorPin2);
float voltage2 = reading2 * 5.0;
voltage2 /= 1024.0;
float temperatureC2 = (voltage2 - 0.5) * 100;
float diferencialT = temperatureC1 - temperatureC2;
float diferencialTE = t - temperature;
lcd.setCursor(6,0);
lcd.print(temperature);
lcd.setCursor(8,0);
lcd.print(" ");
lcd.setCursor(0,1);
lcd.print(h);
lcd.setCursor(0,0);
lcd.print(t);
lcd.setCursor(13,0);
lcd.print(diferencialTE);
lcd.setCursor(12,1);
lcd.print(temperatureC2);
if( t < temperature + 6.00 )
{
digitalWrite(Relay, HIGH);
lcd.setCursor(6,1);
lcd.print("=]");
}
else if( abs(diferencialT) > 99.00 )
{
digitalWrite(Relay, HIGH);
lcd.setCursor(6,0);
lcd.print("read error");
}
else
{
digitalWrite(Relay, LOW);
lcd.setCursor(6,1);
lcd.print("=>");
}
delay(3260);
}
float getTemp(){
byte data[12];
byte addr[8];
if ( !ds.search(addr)) {
ds.reset_search();
return -1000;
}
if ( OneWire::crc8( addr, 7) != addr[7]) {
Serial.println("CRC is not valid!");
return -1000;
}
if ( addr[0] != 0x10 && addr[0] != 0x28) {
Serial.print("Device is not recognized");
return -1000;
}
ds.reset();
ds.select(addr);
ds.write(0x44,1);
byte present = ds.reset();
ds.select(addr);
ds.write(0xBE);
for (int i = 0; i < 9; i++) {
data[i] = ds.read();
}
ds.reset_search();
byte MSB = data[1];
byte LSB = data[0];
float tempRead = ((MSB << 8) | LSB);
float TemperatureSum = tempRead / 16;
return TemperatureSum;
}
//......................................................................
// Luis Rodriguez Alonso. October 2015. habitainer@gmail.com
// http://habican.blogspot.com.es/
// publicado bajo GNU GENERAL PUBLIC LICENSE
// https://gnu.org/licenses/gpl-3.0.en.html
ARDUCAN 003:
// ____ //
// / /___ //
// / / /___ //
// /____/ / /____ //
// | /____/ / /| //
// |___| /____/ / | //
// |___| /____/ / //
// |___| | / //
// |____|/ //
// ArduLightResponseSystem
// Led on (only when) the light is out.
int photoRPin = 0;
int lightLevel;
int LEDpin = 13;
void setup()
{
Serial.begin(9600);
}
void loop()
{
lightLevel=analogRead(photoRPin);
Serial.println(lightLevel);{
if(lightLevel > 526)
{
digitalWrite(13, HIGH);
}
else if(lightLevel <= 526){
digitalWrite(13, LOW);
}
delay(250);
}
}
//......................................................................
// Luis Rodriguez Alonso. October 2015. habitainer@gmail.com
// http://habican.blogspot.com.es/
// publicado bajo GNU GENERAL PUBLIC LICENSE
// https://gnu.org/licenses/gpl-3.0.en.html
Y recuerda: El conocimiento es libre. ¡Compártelo!