Thursday, October 22, 2009

Diggin' in the Dirt

Bob and I went to the local hardware store where we bought 3/4" PVC pipe, emitters, irrigation hose, elbow joints, and other things that we needed to get the students started in the garden. The previous class they dug up the trenches where the pipe will be laid down. The students measured out the necessary length of the pipe sections they needed and will begin cutting the pipe next class. We are also going to get started on the platform for the gravity feed system. Everyone seems to be pretty pleased with the work, and it sure is nice to spend some class time in the fresh air!

Monday, October 12, 2009

Student 3D Garden Plans Complete

The students in Bob's class (Principles of Engineering Design 2) have been creating 3D layouts of the garden. The example here shows the placement of the rain catchment barrels and the elevated staging barrel where we will most likely attach the plenum with valves for each watering "station". The students were able to use Google's SketchUp to quickly create their representations of the space. They picked it up really quickly, in part because of their experience with AutoCAD Inventor, but also because it is a very easy program to learn and video tutorials are free for download. Thanks Google!

Friday, August 14, 2009

Sensor station working prototype complete

Before leaving for my summer trip I managed to get a prototype built and installed on one of the planters in my yard. I didn't have time to hook it up to any irrigation system, but at least it allows me to see what the units will look like and what the best method for mounting might be. The next step is to route water from an outside water source. I'll probably use a bucket or something like that. One idea that was proposed was to have a pump push water up to a funnel that then delivers water to the system via gravity. So, the next step is to see how to get this working. I also need to write up a proposal for all of this and submit it to the district office - they like to know what I'm up to because I tend to be a little disorganized.

Friday, July 24, 2009

Version 2.0 of the Automated Watering System - Wireless is Working!

Well, its been a late night, but I finally got the prototype sensor station and the prototype irrigation controller communicating wirelessly. The sensor station takes a soil humidity reading and then using wireless serial communication sends the value to the controller. The controller checks the value and then turns on or off a solenoid valve. This one to one communication is pretty simple, but very cool to see in action.

Here is the code for the irrigation controller with only one pump:

/* 
 * This is a sketch for turning on a water pump
 * when a dryness threshold is met.  It uses serial
 * communication with a sensor station to check to see
 * what the current humidity level is.  It then turns on
 * a pump to water the plants.
 */
 
 int rxLed = 13;
 int redLed = 3;
 int pumpPin = 8;
 
 int inByte = -1;
 char inString[6];
 int stringPos = 0;
 
 void setup() {
   Serial.begin(9600);
   pinMode(redLed, OUTPUT);
   pinMode(pumpPin, OUTPUT);
   pinMode(rxLed, OUTPUT);
 }
 
 void loop() {
   
  if (Serial.available()) {
    // turn on RX LED whenever reading data
    digitalWrite(rxLed, HIGH);
    handleSerial();
  }
  else {
    // turn off the led when not reading data
    digitalWrite(rxLed, LOW);    
  }
}
 
 void checkPump(int sensorVal){
   if (sensorVal < 500) {
     digitalWrite(redLed, HIGH);
     digitalWrite(pumpPin, LOW);
   } else {
     digitalWrite(redLed, LOW);
     digitalWrite(pumpPin, HIGH);
   } 
 }
 
 void handleSerial() {
   inByte = Serial.read();

   // save only ASCII numeric characters (ASCII 0 - 9):
   if ((inByte >= '0') && (inByte <= '9')) {
     inString[stringPos] = inByte;
     stringPos++;
   }
   
   // if you get an * (end of message), 
   // then convert what you have to an integer:
   if (inByte == '*') {
     // convert string to number
     int humidity = atoi(inString);
     
     // see if the pump needs to be turned on
     checkPump(humidity);
     
     // put zeros in the array
     for (int c = 0; c < stringPos; c++) {
       inString[c] = 0;
     }
     
     // reset the string pointer:
     stringPos = 0;
   }
 }


And here is the code for the sensor station:

/* 
 * A Garden Sensor Station
 * Sends the moisture sensor reading via serial communication.
 */
 
 int moistureSensor = 0;
 // to show communication
 int txLed = 13;
 
 int moistureVal;
 
 void setup() {
   Serial.begin(9600);
   pinMode(txLed, OUTPUT);
 }
 
 void loop() {
   
   // Get sensor reading and send it.
   moistureVal = analogRead(moistureSensor);
   digitalWrite(txLed, HIGH);
   Serial.print(moistureVal, DEC);
   Serial.print('*'); // end of message marker
   digitalWrite(txLed, LOW);
     
   delay(2000); // wait   
 }


I see some possible benefits to having the sensor station just transmit to the irrigation controller whether or not the irrigation controller should turn on, but one of the disadvantages that I see with that is that you now have all the irrigation logic spread across all the sensor stations. So, the choice I made was to make the sensor stations "dumb" and the irrigation controller "smart". If I want to make changes to the irrigation amount, timing, sensitivity, etc. I just have to go to one micro-controller.

Next up: getting the whole thing in place and watering some real plants!

Thursday, July 23, 2009

Marin Municipal Water District checks out our project!


Charlene Burgi who is a Water Conservation Specialist Supervisor for the Marin Municipal Water District came to San Rafael High School yesterday to see what we were planning. We spoke with her about our design and she was delighted to see what the students will be doing in our garden to save energy and water. Many ideas were discussed concerning the opportunities for MMWD to get involved with the project and how they might be able to assist. We discussed the possibility of using the Sustainable Living Lab as a demonstration site for the MMWD. This would give us the ability to extend this project beyond the confines of the school and get the students involved in the community. Cool!

We also talked with Ed (the district's facility guru) about what we were doing and he had some great suggestions and some good news. He told us that power would not be a problem, which might allow us to avoid using a large battery bank for the irrigation control unit. Although this does put us back on the electrical grid, our solar array would be grid tied, and we could monitor the energy used and the energy produced. I am of the opinion that the grid IS a great battery, and it eliminates some complexity in the system. The sensor stations would still be solar powered, so that would give the students exposure to two different solar power storage methods. He also believed that pumps would be better than solenoid valves because it would eliminate the need to have our rain catchment barrels up high on a platform. He suggested that we should avoid elevating the water tanks because we would need to secure them for seismic activity! Wow, I didn't even think about that. So, we might have a hybrid design where we have our larger main tank(s) on the ground, and a pump keeps a smaller elevated staging tank full. The water for the garden comes from the staging tank, and that tank will be small enough that we wouldn't need to create such a significant structure for it.

Next step for me is to get the wireless Arduino's talking - that will be for my next post. Cheers.

Friday, July 17, 2009

Change to Prototype - Solar Modular Design

I met today with Bob, and we decided to make a few changes to the system. Here are the changes:
  1. The sensor stations will be powered via a rechargeable 9V battery, and will be hooked up to a small solar panel that will charge the battery (don't have this yet). We think this will give us the advantage of not having to string a bunch of wires around the garden, and if the configuration of the garden changes (which it might), then we can easily relocate the sensor stations.
  2. The sensor stations will use wireless communication via XBee modems (shown in the photo) to communicate with a central irrigation control unit. This will raise the price of the sensor stations considerably, but we think that the added benefit of having the students learn to program a wireless module will be great! This was something we were planning on doing next year, so it looks like we have a great way to integrate that into the project.
  3. The irrigation system will be regulated via solenoids (shown in the photo) that will open/close a valve. These solenoids are 24V so we might be able to use two 12V car batteries to power these, and then again, use a small solar array to recharge these.
  4. The sensor stations will transmit their sensor readings to the control unit which will identify the valve that needs to be turned on/off based on an identifier associated with the sensor station.
  5. The sensor stations will be constructed using an Arduino, a 9V Battery and holder, and a circuit for charging the battery. These will all reside in a water-proof container and then mounted to the bottom of a PVC pole. The PVC pole will have the small solar module attached to the top and the wires will run down the pipe to the sensor station weather-proof container that will be at the base.
So, I need to modify my prototype so that two Arduino's are talking to each other via XBee modules, and then have one sense the soil humidity and send that reading over to the other Arduino which will turn on the solenoid.
I also need to check out how to charge a 9V battery with a solar panel. This tutorial on Instructables.com looks like its going to be handy.

Version 1.0 For The Automated Watering System



Here is the code that I wrote to make the Arduino turn on/off the little water pump based on the soil humidity:

/*
* This is a sketch for turning on a water pump
* when a dryness threshold is met.
*/

// analog pin 0
int moistureSensor = 0;
// digital pin 12
int redLed = 12;
// digital pin 11       
int greenLed = 11;
// digital pin 7     
int pumpPin = 7;

// variable to hold moisture value
int moistureVal;       

void setup() {
 Serial.begin(9600);
 pinMode(greenLed, OUTPUT);
 pinMode(redLed, OUTPUT);
 pinMode(pumpPin, OUTPUT);
}

void loop() {

 // Read from the moisture sensor
 moistureVal = analogRead(moistureSensor);
 Serial.println(moistureVal);

 if (moistureVal < 500) {
     // turn on the water pump
     digitalWrite(pumpPin, LOW);
     digitalWrite(redLed, HIGH);
     digitalWrite(greenLed, LOW);
     // water for 2 seconds
     delay(2000); 
   } else {
     // turn the pump off
     digitalWrite(pumpPin, HIGH);
     digitalWrite(greenLed, HIGH);
     digitalWrite(redLed, LOW);
   }
   
   delay(1000);  // wait   
 }

Tuesday, July 14, 2009

The Arduino Now Pumps Water!

It was really just a matter of changing a few lines of code and then attaching the relay wires to the breadboard to get the pump working via the Arduino. Although I really didn't have any doubts that it would work, it was nice to see it in action.
What I have now is a small working model of how the automated irrigation system is going to work. Here is the basic setup:
  1. On the far left is the Arduino connected to a small white solder-less breadboard. Two white wires connect to the two nails acting as the humidity sensor (input).
  2. Two more two white wires connect to the relay (output) that is a small black box between the breadboard and the small pot where the nails are inserted.
  3. The relay is connected to the water pump with two more white wires (22 gage).
  4. The nails are inserted into the soil and the resistivity of the soil between the nails changes based on the humidity level of the soil.
  5. The Arduino reads the resistance as an input that is scaled from 0 to 1024 (theoretically anyway). 0 means maximum resistance, or no electrical flow, and 1024 means no resistance.
  6. The Arduino checks this value to see if it is below a threshold, and then sends a LOW signal to the relay. The relay switches (via an electromagnet) and opens up the electrical flow to the pump completing the circuit (its pretty cool, you can hear the "click" of the electromagnet moving in the housing).
  7. The pump turns on, the soil gets wet and the Arduino sees the change in the resistivity between the nails, so it then turns off the pump.
I see this being a great lab exercise for students to test out with some nails and a little pump and small container of soil. It really covers the basic control flow of any robotic system - input, decision, output.
There are some modifications that will need to be made, but I will talk about those next time. I will also post the code and schematic as soon as I can.

Monday, July 13, 2009

First SLL Meeting: A Long Task List and Some Questions...

Lot's to report from today! Today my fellow teachers (Bob and Maya posing for the camera with shy puppy in back) who will be working on the SLL met to discuss the project and look at a number of things that needed to be addressed. It was a great day for a meeting in the garden, so we sat in the shade and came up with a list of action items:
  1. Can we get 110V power outside? If so, are we going to need to use conduit so that we are in compliance with code? (If we can't get power to the outside, then it seems that we might need to consider an "off-grid" solution which certainly has its advantages and disadvantages.) Bob is going to check on this.
  2. Is the pipe coming off the roof the drainage pipe? If it is, can we intersect it for our rain catchment barrels? There might be code issues here too because it looks like the drainage pipe goes into the ground somewhere...Bob is going to see if he can get these answers from maintenance.
  3. We decided to do away with small water pumps and instead are going to use gravity to supply the pressure. That means we are going to use solenoid valves to turn on/off the flow of water. I need to change my proof of concept to see how well this will work. It shouldn't be a big deal but I'm going to have to use a transformer.
  4. We are going to build a platform for the rain barrels, but we needed to get the dimensions of the barrels first to calculate how much they are going to weigh when filled. Bob and I are going to check this out.
  5. Maya is going to look at how we are going to secure and cover the 1/2 inch irrigation lines that will go from the catchment system to the beds. She has a contact in the community with a gardening organization that promotes sustainability in agriculture.
  6. Maya is going to get the quote from Urban Farmer to see how much the irrigation lines and sprinkler heads are going to cost.
  7. Besides working on the prototype, I need to start thinking about the PV system, and where we are going to mount that.
Well, it was certainly a big day, and we certainly have our work cut out for us, but we all seemed pretty excited about the project. The students will certainly be busy when they arrive back from break!

Friday, July 10, 2009

Moisture Sensor Is Working.

So, the moisture sensor was very easy to wire up. You just need one 10k resistor, stick the nails into the soil and voila! I put the nails into some soil that was pretty dry and the sensor reading was around 250. I then took a glass of water and poured just a little in, and instantly the sensor was reading in the mid 300's. I was impressed by how sensitive it was. I poured the rest of the water (about how much I would put if I were watering the plant) and the sensor read around 600. This gives me some kind of baseline for how the sensor will work. I also wired up two LED's - one red for when the moisture drops below 300, and a green one when above 300. Next up, wiring the little pump. I'll need to get a bucket with water as this pump will burn out if its not submersed in water.

Thursday, July 9, 2009

A Place to Start: Garduino

I knew someone would have have done something like this before, and I thought I might even have stumbled across something when I was checking out one of my favorite DIY sites instructables.com. With a little searching, I found a great tutorial on setting up something called a Garduino.
For those of you who might not be familiar with the Arduino, its a very inexpensive micro-controller that I had used for my robotics unit this past year. There is a tremendous amount of enthusiasm and support for this platform. Its really easy to learn and there are some great free instructional online tutorials.
So, this tutorial shows how to set up a small house plant water system using an Arduino micro-controller, a small aquarium pump, and a selection of inexpensive sensors. Its a great little tutorial and with just a few minor changes, it really has most of what I need.
About a week later after getting most of the equipment and supplies together (pump, 22 guage wire, nails, relays, resistors, diodes, and Arduino) I was ready to do some soldering!
I soldered the relay terminals to the 22 guage wire. Lesson learned: the terminals (especially #1) is really weak and it broke twice - good thing I had more on hand! I also made the mistake of cutting the wrong side of the pump's power cord - DON'T cut the "ridged" side of the cable! I also soldered the nails to the wire. As I was soldering the wire to the nails, I noticed a residue forming on the nail that was making the solder slide right off. Sure would like to know what that was.
Ok, tomorrow I'm going to set up the moisture sensor!

Sustainable Living Lab Blog Launched!

Today I decided that it would be a good idea to record the progress of the Sustainable Living Lab in a web log. I will post from time to time any progress that has been made towards the creation of the SSL. This blog will also give me the ability to track my own progress, as this project is also part of a class that I am taking as part of a Master's in Science Teaching program at the New Mexico Institute of Mining and Technology (New Mexico Tech).
What is the SLL? Well, in brief, its an experiential learning opportunity for students enrolled in San Rafael High School's Academy of Physics and Technology to design and build an automated resource management system for the organic garden at our school. It will include:
  1. An automated irrigation system based on soil humidity levels
  2. A rain catchment system
  3. A energy use monitoring system
  4. A small solar array to power all components (sensors, control unit, and irrigation pumps)
This project is being funded through a PG&E Bright Ideas Grant and we are extremely thankful for their financial support.
The next step is for me to begin the process of creating a miniature proof of concept before I jump into purchasing the components of the system. It should be an incredible learning experience for the students and myself. Please feel free to post any comments if you have any questions or suggestions!