Friday, 12 September 2014

Sistema de riego con Arduino

Hola! Dejo un proyectito para una huerta indoor.
Prueba de concepto

Probando 1





Los componentes que estoy utilizando son:
  • Arduino ADK para controlar todo
  • Bomba de agua 12v
  • Luz de sodio de alta presion 400w
  • Relee shield para controlar la lampara de sodio y la bomba de agua
  • Display 160 caracteres
  • DHT11 como sensor de temperatura y humedad ambiente
  • Soil meter como sensor de humedad en tierra
  • ds18b20 como sensor de temperatura del agua
  • Buzzer como alarma
  • Reloj rtc para guardar la hora y poder controlar las luces y la bomba de agua

El codigo esta en github 

Labels: , , , , ,

Thursday, 11 September 2014

Luces inteligentes con arduino

Hola! Despues de andar bastante manija con música y luces pude terminar un proyecto de luces audioritmicas usando un arduino y un micrófono (sensor)
El codigo esta disponible en github y el tutorial en este post.
Aqui un video de como queda. Luces RGB (tira led) y UV

Labels: , ,

Tuesday, 1 July 2014

Real Time Clock para Arduino

 Pequeño tutorial para hacer funcionar un reloj tiempo real que utilizo para mi arduino.
El modelo es Tiny RTC I2C Modules y es el de la foto.
Como pueden ver, la batería es recargable.
La conexión es la siguiente:



|     RTC       |   Arduino |
|     GND       |      GND   |
|     VCC       |        +5V   |
|     SDA       |        A4     |
|     SCL       |         A5     |
|     BAT       |      +3.3v   |



Código:

Poner la hora

  1. /* Downloaded from http://projectsfromtech.blogspot.com/
  2. *Connect SCL, SDA, Vcc, and GND
  3. *Set date in function below.
  4. *Upload and enjoy!
  5. */
  6.  
  7.  
  8. //Arduino 1.0+ Only
  9.  
  10. #include "Wire.h"
  11.  
  12. #define DS1307_ADDRESS 0x68
  13. byte zero = 0x00; //workaround for issue #527
  14.  
  15. void setup(){
  16.   Wire.begin();
  17.  
  18.  
  19.  
  20.   Serial.begin(9600);
  21.   setDateTime(); //MUST CONFIGURE IN FUNCTION
  22. }
  23.  
  24. void loop(){
  25.   printDate();
  26.   delay(1000);
  27. }
  28.  
  29. void setDateTime(){
  30.  
  31.   byte second =     00; //0-59
  32.   byte minute =      37; //0-59
  33.   byte hour =        23; //0-23
  34.   byte weekDay =    1; //1-7
  35.   byte monthDay =    30; //1-31
  36.   byte month =       7; //1-12
  37.   byte year  =       14; //0-99
  38.  
  39.   Wire.beginTransmission(DS1307_ADDRESS);
  40.   Wire.write(zero); //stop Oscillator
  41.  
  42.   Wire.write(decToBcd(second));
  43.   Wire.write(decToBcd(minute));
  44.   Wire.write(decToBcd(hour));
  45.   Wire.write(decToBcd(weekDay));
  46.   Wire.write(decToBcd(monthDay));
  47.   Wire.write(decToBcd(month));
  48.   Wire.write(decToBcd(year));
  49.  
  50.   Wire.write(zero); //start
  51.  
  52.   Wire.endTransmission();
  53.  
  54. }
  55.  
  56. byte decToBcd(byte val){
  57. // Convert normal decimal numbers to binary coded decimal
  58.   return ( (val/10*16) + (val%10) );
  59. }
  60.  
  61. byte bcdToDec(byte val)  {
  62. // Convert binary coded decimal to normal decimal numbers
  63.   return ( (val/16*10) + (val%16) );
  64. }
  65.  
  66. void printDate(){
  67.  
  68.   // Reset the register pointer
  69.   Wire.beginTransmission(DS1307_ADDRESS);
  70.   Wire.write(zero);
  71.   Wire.endTransmission();
  72.  
  73.   Wire.requestFrom(DS1307_ADDRESS, 7);
  74.  
  75.   int second = bcdToDec(Wire.read());
  76.   int minute = bcdToDec(Wire.read());
  77.   int hour = bcdToDec(Wire.read() & 0b111111); //24 hour time
  78.   int weekDay = bcdToDec(Wire.read()); //0-6 -> sunday - Saturday
  79.   int monthDay = bcdToDec(Wire.read());
  80.   int month = bcdToDec(Wire.read());
  81.   int year = bcdToDec(Wire.read());
  82.  
  83.   //print the date EG   3/1/11 23:59:59
  84.   Serial.print(month);
  85.   Serial.print("/");
  86.   Serial.print(monthDay);
  87.   Serial.print("/");
  88.   Serial.print(year);
  89.   Serial.print(" ");
  90.   Serial.print(hour);
  91.   Serial.print(":");
  92.   Serial.print(minute);
  93.   Serial.print(":");
  94.   Serial.println(second);
  95.  
  96. }

Obtener la hora

  1. /* Downloaded from http://projectsfromtech.blogspot.com/
  2. *Connect SCL, SDA, Vcc, and GND
  3. *Open Serial Monitor and enjoy!
  4. */
  5.  
  6. //Arduino 1.0+ Only
  7.  
  8. #include "Wire.h"
  9. #define DS1307_ADDRESS 0x68
  10.  
  11. void setup(){
  12.   Wire.begin();
  13.   Serial.begin(9600);
  14. }
  15.  
  16. void loop(){
  17.   printDate();
  18.   delay(1000);
  19. }
  20.  
  21. byte bcdToDec(byte val)  {
  22. // Convert binary coded decimal to normal decimal numbers
  23.   return ( (val/16*10) + (val%16) );
  24. }
  25.  
  26. void printDate(){
  27.  
  28.   // Reset the register pointer
  29.   Wire.beginTransmission(DS1307_ADDRESS);
  30.  
  31.   byte zero = 0x00;
  32.   Wire.write(zero);
  33.   Wire.endTransmission();
  34.  
  35.   Wire.requestFrom(DS1307_ADDRESS, 7);
  36.  
  37.   int second = bcdToDec(Wire.read());
  38.   int minute = bcdToDec(Wire.read());
  39.   int hour = bcdToDec(Wire.read() & 0b111111); //24 hour time
  40.   int weekDay = bcdToDec(Wire.read()); //0-6 -> sunday - Saturday
  41.   int monthDay = bcdToDec(Wire.read());
  42.   int month = bcdToDec(Wire.read());
  43.   int year = bcdToDec(Wire.read());
  44.  
  45.   //print the date EG   3/1/11 23:59:59
  46.   Serial.print(month);
  47.   Serial.print("/");
  48.   Serial.print(monthDay);
  49.   Serial.print("/");
  50.   Serial.print(year);
  51.   Serial.print(" ");
  52.   Serial.print(hour);
  53.   Serial.print(":");
  54.   Serial.print(minute);
  55.   Serial.print(":");
  56.   Serial.println(second);
  57.  
  58. }

Bug:

Muestra una fecha invalida como 7/31/14 2:27:36

Labels: , ,

Tuesday, 3 June 2014

Arduino + Ethernet Shield v1.1

Hola
Si tienen el shield que estan viendo abajo, y tienen problemas para hacerlo funcionar, pueden bajar ésta librería (alojada en mi Gooogle Drive ;) )


Labels: , ,

Wednesday, 19 February 2014

Arduino + LED inteligente

Hola a todos,
Hoy les dejo un video de un Arduino Uno controlando una tira de led RGB.
Entren y pueden encontrar los materiales para hacerlo :) 
Saludos 

Requerimientos:

  • Arduino Uno
  • ULN2003AG
  • Sound Detector Module
  • Tira de Leds
  • Transformador de 12V

Diagrama:

Código:

  1. /**
  2.  * Cristian Marquez https://blog.cristianmarquez.me
  3.  * RGB controller with networking, potentiometer and android client
  4.  **/
  5. //External Libraries
  6. #include <SPI.h>
  7. #include <Ethernet.h>
  8. //Network
  9. byte mac[] = {
  10.   0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
  11. IPAddress ip(192,168,0,177);
  12. EthernetServer server(80);
  13. IPAddress gateway(192,168,0,1);
  14. IPAddress subnet(255, 255, 255, 0);
  15. //LED
  16. int redLedPin = 3;
  17. int greenLedPin = 5;
  18. int blueLedPin = 6;
  19. //Sensors
  20. int soundDetectorAnalogPin=A0;
  21. int soundDetectorDigitalPin=8;
  22. int potentiometerAnalogPin=A1;
  23. void setup()
  24. {
  25.   Serial.begin(9600); //Just for debugging
  26.   Ethernet.begin(mac, ip);
  27.   server.begin();
  28.   pinMode(soundDetectorDigitalPin, INPUT);
  29.   pinMode(redLedPin, OUTPUT);    
  30.   pinMode(greenLedPin, OUTPUT);    
  31.   pinMode(blueLedPin, OUTPUT);    
  32. }
  33. void loop()
  34. {
  35.   if (digitalRead(soundDetectorDigitalPin)==1){
  36.     int rand = random(1,11);
  37.     switch (rand)
  38.     {
  39.     case 1:
  40.       //red
  41.       turnLights(random(100, 255),0,0);
  42.       delay(150);
  43.       break;
  44.     case 2:
  45.       //green
  46.       turnLights(0,random(100, 255),0);
  47.       delay(150);
  48.       break;
  49.     case 3:
  50.       //blue
  51.       turnLights(0,0,random(100, 255));
  52.       delay(150);
  53.       break;
  54.     case 4:
  55.       //red+green
  56.       turnLights(random(100, 255),random(100, 255),0);
  57.       delay(150);
  58.       break;
  59.     case 5:
  60.       //red+blue
  61.       turnLights(random(100, 255),0,random(100, 255));
  62.       delay(150);
  63.       break;
  64.     case 6:
  65.       //green+blue
  66.       turnLights(0,random(100, 255),random(100, 255));
  67.       delay(150);
  68.       break;
  69.     case 7:
  70.       //red+green+blue
  71.       turnLights(random(100, 255),random(100, 255),random(100, 255));
  72.       delay(150);
  73.       break;
  74.     case 8:
  75.       //yellow
  76.       turnLights(255,255,0);
  77.       delay(150);
  78.       break;
  79.     case 9:
  80.       //white
  81.       turnLights(255,255,255);
  82.       delay(150);
  83.       break;
  84.     case 10:
  85.       //violet
  86.       turnLights(238,130,238);
  87.       delay(150);
  88.       break;    
  89.     }
  90.   }
  91.   else{
  92.     turnLights(0,0,0);
  93.   }
  94. }
  95. void useSerial()
  96. {
  97.   while (Serial.available() > 0) {
  98.     // look for the next valid integer in the incoming serial stream:
  99.     int red = Serial.parseInt();
  100.     // do it again:
  101.     int green = Serial.parseInt();
  102.     // do it again:
  103.     int blue = Serial.parseInt();
  104.     if (Serial.read() == '\n') {
  105.       turnLights(red,green,blue);
  106.     }
  107.   }
  108. }
  109. void useEthernet()
  110. {
  111.   EthernetClient client = server.available();
  112.   if (client) {
  113.     // an http request ends with a blank line
  114.     boolean currentLineIsBlank = true;
  115.     while (client.connected()) {
  116.       if (client.available()) {
  117.         char c = client.read();
  118.         // if you've gotten to the end of the line (received a newline
  119.         // character) and the line is blank, the http request has ended,
  120.         // so you can send a reply
  121.         if (== '\n' && currentLineIsBlank) {
  122.           // send a standard http response header
  123.           client.println("HTTP/1.1 150 OK");
  124.           client.println("Content-Type: text/html");
  125.           client.println();
  126.           // print the current readings, in HTML format:
  127.           client.print("Temperature: ");
  128.           break;
  129.         }
  130.         if (== '\n') {
  131.           // you're starting a new line
  132.           currentLineIsBlank = true;
  133.         }
  134.         else if (!= '\r') {
  135.           // you've gotten a character on the current line
  136.           currentLineIsBlank = false;
  137.         }
  138.       }
  139.     }
  140.     // give the web browser time to receive the data
  141.     delay(1);
  142.     // close the connection:
  143.     client.stop();
  144.   }
  145. }
  146. void turnLights(int red, int green, int blue)
  147. {
  148.   red = constrain(red, 0, 255);
  149.   green =  constrain(green, 0, 255);
  150.   blue =  constrain(blue, 0, 255);
  151.   analogWrite(redLedPin, red);
  152.   analogWrite(greenLedPin, green);
  153.   analogWrite(blueLedPin, blue);
  154. }

Labels: , , , ,