Difference between revisions of "Garduino"

From Randomdata wiki
Jump to: navigation, search
(Changed format of pictures)
m
 
(6 intermediate revisions by the same user not shown)
Line 7: Line 7:
  
 
= Why =
 
= Why =
Why the Garduino? Well, we are very lazy and we want to be sure our garden is really fine in the hot summer days
+
Why the Garduino? Well, we are very lazy and we want to be sure our garden is doing fine in the hot summer days
  
 
= What =
 
= What =
Line 20: Line 20:
 
* Wind sensor
 
* Wind sensor
 
* Temperature sensor (ordered and installed soon)
 
* Temperature sensor (ordered and installed soon)
 +
 +
= Statistics =
 +
Our graph page: [http://www.randomdata.nl/garduino/graph.html]
 +
We build our graphs in cacti.
 +
  
 
= Actions =
 
= Actions =
Line 39: Line 44:
 
[[File:gArduino_picture.jpg]]<br>
 
[[File:gArduino_picture.jpg]]<br>
 
== Moist sensor ==
 
== Moist sensor ==
 +
The current 0.2 moist sensor is build of:
 +
* film canister (one with a flat cap!)
 +
* two INOX screws (about >8 cm)
 +
* Wire (we used CAT5)
 +
* Epoxy
 +
 +
=== HOW to build: ===
 +
* Open the film canister and screw the screws thru the cap
 +
* Drill a hole in the bottom of the canister and put the wire thru
 +
* Strip the wire and connect two of them to the screws in the cap
 +
* Mix the epoxy and will the canister (Be sure to ventilate!)
 +
* Add the cap to the canister and put it upside-down so the epoxy will protect the connections of the screws
 +
* Connect the other end of the wires to you gArduino configuration
 +
 +
=== Overview ===
 
[[File:gArduino_moistsensor.jpg]]
 
[[File:gArduino_moistsensor.jpg]]
 +
 +
=== Nice to have: ===
 +
* Build the circuit into the moist sensor, this will increase the quality of the measurements
 +
* Stacking option of multi sensors
 +
 
== Solar sensor ==
 
== Solar sensor ==
The solar sensor is just an solar panel, we need to adjust it a bit because it's working to well. For this we will use a filter.<br>
+
The solar sensor is just a solar panel, we need to adjust it a bit because it's working to well. For this we will use a filter.<br>
[[File:gArduino_moistsensor.jpg]]
+
[[File:gArduino_solarsensor.jpg]]
  
 
== Code ==
 
== Code ==
 
My programming skill's aren't the best.... but it's functioning :-)<br>
 
My programming skill's aren't the best.... but it's functioning :-)<br>
 
As you can see, I added an ethernet shield to monitor the data. You can do this monitoring also by using the USB serial connection.
 
As you can see, I added an ethernet shield to monitor the data. You can do this monitoring also by using the USB serial connection.
This code is also re-used code from several example's of the Arduino toolkit. You will probably recognize some.
+
We are working on live cacti graphs... soon they will be available.
 +
 
 +
Some of the code is re-used code from several example's of the Arduino toolkit. You will probably recognize some.
  
Current dev version of the gArduino is v0.3 alpha
+
Current dev version of the gArduino is v0.5 alpha
 
<pre>
 
<pre>
 
/*
 
/*
  *  
+
  * AnalogInput
 +
* by DojoDave <http://www.0j0.org>
 +
*
 +
* Turns on and off a light emitting diode(LED) connected to digital 
 +
* pin 13. The amount of time the LED will be on and off depends on
 +
* the value obtained by analogRead(). In the easiest case we connect
 +
* a potentiometer to analog pin 2.
 +
*
 +
* http://www.arduino.cc/en/Tutorial/AnalogInput
 +
*/
  
int potPin = 0;        // select the input pin for the sensor
+
int potPin = 0;        // select the input pin for the moist sensor
int solarPin = 1;         // select the input pin for the sensor
+
int solarPin = 5;       // select the input pin for the solar sensor
int ledprobe = 9;         // select the input pin for the sensor
+
int tempPin = 4;        // select the input pin for the temp sensor
 +
int ledprobe = 9;       // select the input pin for the sensor
 
int ledPin1 = 8;        // select the pin for the LED
 
int ledPin1 = 8;        // select the pin for the LED
 
int val = 0;            // variable to store the value coming from the sensor
 
int val = 0;            // variable to store the value coming from the sensor
Line 64: Line 101:
 
int valtmp = 0;        // variable to temperary store the total probe details
 
int valtmp = 0;        // variable to temperary store the total probe details
 
int interval = 32;      // the total ammount of probes before advertising the average, caution!!! the max count is 32 if measurring a max 1024 vallue!!! WILL BE CORRECTED WITH long int soon
 
int interval = 32;      // the total ammount of probes before advertising the average, caution!!! the max count is 32 if measurring a max 1024 vallue!!! WILL BE CORRECTED WITH long int soon
int probedelay = 300;  // the delay between the probes in milliseconds
+
int probedelay = 100;  // the delay between the probes in milliseconds
 
int wet = 350;          // the probevalue to decide what wet is
 
int wet = 350;          // the probevalue to decide what wet is
 
int dry = 200;          // the probevalue to decide what too dry is
 
int dry = 200;          // the probevalue to decide what too dry is
  
#include <Ethernet.h>
+
#include "Ethernet.h"
 +
#include "WebServer.h"
  
 
// network configuration.  gateway and subnet are optional.
 
// network configuration.  gateway and subnet are optional.
Line 76: Line 114:
 
byte subnet[] = { 255, 255, 255, 0 };
 
byte subnet[] = { 255, 255, 255, 0 };
  
// telnet defaults to port 23
+
/* This creates an instance of the webserver.  By specifying a prefix
Server server(23);
+
* of "/", all pages will be at the root of the server. */
 +
#define PREFIX "/garduino"
 +
WebServer webserver(PREFIX, 80);
 +
 
 +
/* commands are functions that get called by the webserver framework
 +
* they can read any posted data from client, and they output to the
 +
* server to send data back to the web browser. */
 +
void helloCmd(WebServer &server, WebServer::ConnectionType type)
 +
{
 +
  /* this line sends the standard "we're all OK" headers back to the
 +
    browser */
 +
  server.httpSuccess();
 +
 
 +
  /* if we're handling a GET or POST, we can output our data here.
 +
    For a HEAD request, we just stop after outputting headers. */
 +
  if (type != WebServer::HEAD)
 +
  {
 +
    /* this defines some HTML text in read-only memory aka PROGMEM.
 +
    * This is needed to avoid having the string copied to our limited
 +
    * amount of RAM. */
 +
    P(helloMsg) = "<h1>Hello, World!</h1>";
 +
 
 +
    /* this is a special form of print that outputs from PROGMEM */
 +
    server.printP(helloMsg);
 +
  }
 +
}
 +
 
 +
void moistCmd(WebServer &server, WebServer::ConnectionType type)
 +
{
 +
  /* this line sends the standard "we're all OK" headers back to the
 +
    browser */
 +
  server.httpSuccess();
 +
 
 +
  /* if we're handling a GET or POST, we can output our data here.
 +
    For a HEAD request, we just stop after outputting headers. */
 +
  if (type != WebServer::HEAD)
 +
  {
 +
    //Print Moist val on http
 +
    server.print(val);
 +
  }
 +
}
 +
 
 +
void solarCmd(WebServer &server, WebServer::ConnectionType type)
 +
{
 +
  /* this line sends the standard "we're all OK" headers back to the
 +
    browser */
 +
  server.httpSuccess();
 +
 
 +
  /* if we're handling a GET or POST, we can output our data here.
 +
    For a HEAD request, we just stop after outputting headers. */
 +
  if (type != WebServer::HEAD)
 +
  {
 +
    //Print Solar on http
 +
    int valsolar = analogRead(solarPin);
 +
    server.print(valsolar);
 +
  }
 +
}
 +
 
 +
void tempCmd(WebServer &server, WebServer::ConnectionType type)
 +
{
 +
  /* this line sends the standard "we're all OK" headers back to the
 +
    browser */
 +
  server.httpSuccess();
 +
 
 +
  /* if we're handling a GET or POST, we can output our data here.
 +
    For a HEAD request, we just stop after outputting headers. */
 +
  if (type != WebServer::HEAD)
 +
  {
 +
    //Print Solar on http
 +
    int valtemp = analogRead(tempPin);
 +
    server.print(valtemp);
 +
  }
 +
}
  
  
Line 87: Line 197:
 
     // initialize the ethernet device
 
     // initialize the ethernet device
 
   Ethernet.begin(mac, ip, gateway, subnet);
 
   Ethernet.begin(mac, ip, gateway, subnet);
   // start listening for clients
+
 
   server.begin();
+
   /* setup our default command that will be run when the user accesses
 +
  * the root page on the server */
 +
  webserver.setDefaultCommand(&helloCmd);
 +
 
 +
  /* run the same command if you try to load /index.html, a common
 +
  * default page name */
 +
  webserver.addCommand("index.html", &helloCmd);
 +
  webserver.addCommand("moist", &moistCmd);
 +
  webserver.addCommand("solar", &solarCmd);
 +
  webserver.addCommand("temp", &tempCmd);
 +
  /* start the webserver */
 +
   webserver.begin();
 +
 
 
}
 
}
  
Line 106: Line 228:
 
    
 
    
  
//    if (valcnt = interval) {
+
val = (valtot / valcnt);
              val = (valtot / valcnt);
+
if (val < 300) //TODOPARAMETER
              if (val < 300)  
+
  {
                {
+
  digitalWrite(ledPin1, HIGH);  // turn the ledPin on
                digitalWrite(ledPin1, HIGH);  // turn the ledPin on
+
  }
                }
+
  else  
                       
+
  {
              else {
+
  digitalWrite(ledPin1, LOW);  // turn the ledPin off
                  digitalWrite(ledPin1, LOW);  // turn the ledPin off
+
  }
                  }
+
 
// Print monitoring details on serial port
+
Serial.println(val);  
              Serial.print(valtot);
+
              Serial.print(" delen door ");
+
              Serial.print(valcnt);
+
              Serial.print(" is ");
+
              Serial.print(val);
+
              Serial.print("        ");
+
  
// Print monitoring details on ethernet             
+
/* process incoming connections one at a time forever */
                Client client = server.available();
+
webserver.processConnection();
                if (client)
+
                {
+
                server.print("Moist:");
+
                server.println(val);
+
                server.print("Solar");
+
                server.println(analogRead(solarPin));
+
                server.println("");
+
                }
+
             
+
              valcnt = 0;
+
              valtot = 0; 
+
//  }
+
}
+
  
 +
valcnt = 0;
 +
valtot = 0;
 +
}
 
</pre>
 
</pre>
  
 
[[Category:Projects]]
 
[[Category:Projects]]
 
[[Category:Arduino]]
 
[[Category:Arduino]]

Latest revision as of 12:43, 23 June 2009

The gArduino is a Automated Garden Facility (AGF) and it's build on the Arduino platform. It is used to automate your garden. Our primary goal is to "water" the garden and monitor the garden environment. Currently we have build the gArduino to measure the water status of a plant. The information is collected by an NSLU2 mini linux server. The information will be published soon on cacti graphs.


Why

Why the Garduino? Well, we are very lazy and we want to be sure our garden is doing fine in the hot summer days

What

We have several sensors. Currently we have build these ones:

  • Moist sensor
  • Solar sensor
  • Water level sensor (same as moist)

Some sensors which can be attached in the future:

  • Rain sensor (will be adjusted moist sensor)
  • Wind sensor
  • Temperature sensor (ordered and installed soon)

Statistics

Our graph page: [1] We build our graphs in cacti.


Actions

  • start the pump
  • water circuit selector
  • Call for help:
    • Out of water
    • Ground is not getting wet
  • Monitor
    • How much water is needed and how often
    • Weather/water conditions
    • Graphs in cacti
    • etc.

Details

Overview

This is a small overview, and technical overview will be posted soon. The relais and pump or missing in the code for now.
GArduino overview.jpg
File:GArduino picture.jpg

Moist sensor

The current 0.2 moist sensor is build of:

  • film canister (one with a flat cap!)
  • two INOX screws (about >8 cm)
  • Wire (we used CAT5)
  • Epoxy

HOW to build:

  • Open the film canister and screw the screws thru the cap
  • Drill a hole in the bottom of the canister and put the wire thru
  • Strip the wire and connect two of them to the screws in the cap
  • Mix the epoxy and will the canister (Be sure to ventilate!)
  • Add the cap to the canister and put it upside-down so the epoxy will protect the connections of the screws
  • Connect the other end of the wires to you gArduino configuration

Overview

GArduino moistsensor.jpg

Nice to have:

  • Build the circuit into the moist sensor, this will increase the quality of the measurements
  • Stacking option of multi sensors

Solar sensor

The solar sensor is just a solar panel, we need to adjust it a bit because it's working to well. For this we will use a filter.
File:GArduino solarsensor.jpg

Code

My programming skill's aren't the best.... but it's functioning :-)
As you can see, I added an ethernet shield to monitor the data. You can do this monitoring also by using the USB serial connection. We are working on live cacti graphs... soon they will be available.

Some of the code is re-used code from several example's of the Arduino toolkit. You will probably recognize some.

Current dev version of the gArduino is v0.5 alpha

/*
 * AnalogInput
 * by DojoDave <http://www.0j0.org>
 *
 * Turns on and off a light emitting diode(LED) connected to digital  
 * pin 13. The amount of time the LED will be on and off depends on
 * the value obtained by analogRead(). In the easiest case we connect
 * a potentiometer to analog pin 2.
 *
 * http://www.arduino.cc/en/Tutorial/AnalogInput
 */

int potPin = 0;         // select the input pin for the moist sensor
int solarPin = 5;       // select the input pin for the solar sensor
int tempPin = 4;        // select the input pin for the temp sensor
int ledprobe = 9;       // select the input pin for the sensor
int ledPin1 = 8;        // select the pin for the LED
int val = 0;            // variable to store the value coming from the sensor
int valtot = 0;         // variable to store the total probe details
int valprobe = 0;       // variable to store the probe details
int valcnt = 0;         // variable to store the probe counter
int valtmp = 0;         // variable to temperary store the total probe details
int interval = 32;      // the total ammount of probes before advertising the average, caution!!! the max count is 32 if measurring a max 1024 vallue!!! WILL BE CORRECTED WITH long int soon
int probedelay = 100;   // the delay between the probes in milliseconds
int wet = 350;          // the probevalue to decide what wet is
int dry = 200;          // the probevalue to decide what too dry is

#include "Ethernet.h"
#include "WebServer.h"

// network configuration.  gateway and subnet are optional.
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192, 168, 1, 177 };
byte gateway[] = { 192, 168, 1, 1 };
byte subnet[] = { 255, 255, 255, 0 };

/* This creates an instance of the webserver.  By specifying a prefix
 * of "/", all pages will be at the root of the server. */
#define PREFIX "/garduino"
WebServer webserver(PREFIX, 80);

/* commands are functions that get called by the webserver framework
 * they can read any posted data from client, and they output to the
 * server to send data back to the web browser. */
void helloCmd(WebServer &server, WebServer::ConnectionType type)
{
  /* this line sends the standard "we're all OK" headers back to the
     browser */
  server.httpSuccess();

  /* if we're handling a GET or POST, we can output our data here.
     For a HEAD request, we just stop after outputting headers. */
  if (type != WebServer::HEAD)
  {
    /* this defines some HTML text in read-only memory aka PROGMEM.
     * This is needed to avoid having the string copied to our limited
     * amount of RAM. */
    P(helloMsg) = "<h1>Hello, World!</h1>";

    /* this is a special form of print that outputs from PROGMEM */
    server.printP(helloMsg);
  }
}

void moistCmd(WebServer &server, WebServer::ConnectionType type)
{
  /* this line sends the standard "we're all OK" headers back to the
     browser */
  server.httpSuccess();

  /* if we're handling a GET or POST, we can output our data here.
     For a HEAD request, we just stop after outputting headers. */
  if (type != WebServer::HEAD)
  {
    //Print Moist val on http
    server.print(val);
  }
}

void solarCmd(WebServer &server, WebServer::ConnectionType type)
{
  /* this line sends the standard "we're all OK" headers back to the
     browser */
  server.httpSuccess();

  /* if we're handling a GET or POST, we can output our data here.
     For a HEAD request, we just stop after outputting headers. */
  if (type != WebServer::HEAD)
  {
    //Print Solar on http
    int valsolar = analogRead(solarPin);
    server.print(valsolar);
  }
}

void tempCmd(WebServer &server, WebServer::ConnectionType type)
{
  /* this line sends the standard "we're all OK" headers back to the
     browser */
  server.httpSuccess();

  /* if we're handling a GET or POST, we can output our data here.
     For a HEAD request, we just stop after outputting headers. */
  if (type != WebServer::HEAD)
  {
    //Print Solar on http
    int valtemp = analogRead(tempPin);
    server.print(valtemp);
  }
}


void setup() {
  pinMode(ledPin1, OUTPUT);  // declare the ledPin as an OUTPUT
  pinMode(ledprobe, OUTPUT);  // declare the ledPin as an OUTPUT
  Serial.begin(9600);
  
    // initialize the ethernet device
  Ethernet.begin(mac, ip, gateway, subnet);
  
  /* setup our default command that will be run when the user accesses
   * the root page on the server */
  webserver.setDefaultCommand(&helloCmd);

  /* run the same command if you try to load /index.html, a common
   * default page name */
  webserver.addCommand("index.html", &helloCmd);
  webserver.addCommand("moist", &moistCmd);
  webserver.addCommand("solar", &solarCmd);
  webserver.addCommand("temp", &tempCmd);
  /* start the webserver */
  webserver.begin();

}

void loop() {
  
do
{
    digitalWrite(ledprobe, HIGH);  // turn the ledprobe on
    valprobe = analogRead(potPin); // read the value from the sensor
    delay(50);
    digitalWrite(ledprobe, LOW);  // turn the ledprobe off
    valtmp = valtot;
    valtot = valtmp + valprobe;
    valcnt = valcnt + 1;
    delay(probedelay - 50);
} while (valcnt != interval);
  

val = (valtot / valcnt);
if (val < 300) //TODOPARAMETER
  {
  digitalWrite(ledPin1, HIGH);  // turn the ledPin on
  }
  else 
  {
  digitalWrite(ledPin1, LOW);  // turn the ledPin off
  }
  
Serial.println(val);   

/* process incoming connections one at a time forever */
webserver.processConnection();

valcnt = 0;
valtot = 0;
}