Mostrando entradas con la etiqueta hardware. Mostrar todas las entradas
Mostrando entradas con la etiqueta hardware. Mostrar todas las entradas

23 jun 2016

Cacharros en mi container: ¡Experimentando con Arduino y la Domótica!


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...
A medio camino entre lo que tengo y lo que quiero, este diagrama intenta hacer comprensible las posibilidades y rendimientos, así como el potencial que encierra una herramienta como Arduino (tengo tres plaquitas ahora operativas para los experimentos), una Raspberry pi por emplear, un puñado de sensores, relés, luces, sonidos, pantallas y teclados y un largo etcétera de posibilidades para cacharrear. Una pasada.

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
actualizado: Pongo el código que creo esta corriendo en los cacharros, aunque no garantizo que sea la misma versión. En cualquier caso, con fines didácticos, muestra en gran medida el objetivo de mi experimento personal:

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!
ARDUCAN 001:
//     _____                
//    /    /____
//   /    /    /____
//  /____/    /    /____
//  |   /____/    /    /|
//  |___|   /____/    / |
//      |___|   /____/  /
//          |___|    | /
//              |____|/

//___________________________
//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!

3 abr 2016

3D, Money and Power - Independent Research Regarding Computer and Human Interaction


Dear Sirs,

It was about two years ago that I decided to re conciliate with what I usually call mekhane, or machine, starting to approach and study once again in my life the state of the art regarding computer networks, human and machine interactuation and related aspects in present running days.

My first inscription quote was acquiring an AMD desktop unit pret-a-porter, machine I got to buy in a mainstream electro domestics company -with windows preinstalled also thus prepaid-, from where I am typing these actual lines and that has accomplished wonderfull tasks during my study development.

Second investment on my personal education was another improved middle class gaming machine, also from AMD manufacturer, this time delivered from Madrid from a well unowned internet computer online store, with a really nice Free and Open-source -up to my scarce understanding- Debian desktop GNU/Linux distribution that I personally installed.

Both really smooth, and for my expectations at this time -I maintain as a hobby some cryptocoin mining activity- it is doing an amazing work. I am very happy with its performance and under some requirements both can be used for different tasks for common goals. I have also invested in Arduino boards multiple sensors and actuators, relays and also a raspberry pi, all of which of most value in the so called Internet of Things experimentation field.

As you may understand I am a self-made studier, that is I did not have a teacher but many during my life, all people whom I respect and that formed part of my life experience for long and short periods of time. I also or neither never had a very much defined study object -a program I could say-, but the will to learn new things and feel alive, the enthusiasm for learning.

I feel now as if the initial work is done, but when I interact with one, many or some of the aspects I once hand-printed in paper so to make up my mind, the whole puzzle changes and it makes me feel I get a small clue of what one is all and all is one means. This is unfinished work, and it is and will be licenced with Creative Commons v 4.0 International Atribution. So I just decided to publish this paper, in case anybody would like to have a say regarding this interesting fields, please feel free to contact me in most suitable way.

Sincerely yours,

Luis Rodriguez