Make Your Own Thirsty Plant Graph!

by techwillsaveus in Circuits > Electronics

1309 Views, 5 Favorites, 0 Comments

Make Your Own Thirsty Plant Graph!

Square_TP.jpg
DIY Thirsty Plant Graph

In this Instructable we’ll use Arduino and Processing to plot a graph with our moisture sensor, to see the relationship between the MOSFET transistor and the sensor.

You will need:

DIY Thirsty Plant Kit

DIY Start Arduino Kit

Some jumper wires and/or crocodile clips

We’ll also be using Arduino software (www.arduino.cc) to read the Thirsty Plant and Processing (www.processing.org) to plot the graph.

Setting Up the Hardware: Part One

TP6.jpg
TP4.jpg
TP2.jpg
TP5.jpg

Setting up: In our experiment we started off with a dry moisture sensor as it’s much easier to get the sensor wet than to dry it out!

To attach your Thirsty Plant to the Arduino you will need to run a jumper wire (preferably red) from the point where the resistor meets one side of the moisture sensor and the left leg of the MOSFET transistor.
To do this, push the jumper wire through the front of the Thirsty Plant, through the hole marked with the ones and zeros symbol. Then twist these wires together at the back. Attach the other end of this (red) wire to Analog Pin 0 on your Arduino.

Setting Up the Hardware: Part Two

TP1.jpg
TP7.jpg
TP3.jpg
TP8.jpg

We will need to ground the Thirsty Plant as well, this is to understand when there is power flowing through the LED.

To ground the Thirsty Plant, attach a jumper wire (preferably black) to the negative leg of the LED. Again, push the jumper wire through the front of the Thirsty Plant, through the hole marked with a ground symbol (three lines). Again, twist these wires together at the back. Plug the other end of this jumper wire (black) to a GND pin on the Arduino.

Coding With Arduino

Arduino:
We’ve attached our thirsty plant to analog input pin A0 so we’ll now need to write a sketch that takes a reading from that pin. In this sketch we’re reading the value from pin A0 and printing the values to Serial(9600).

char separator[] = " | ";

void setup()

{

Serial.begin(9600);

}

void loop()

{

int sensorValue = analogRead(A0);

Serial.print("Thirsty Plant"); //Label for the sensor

Serial.print(":"); //Seperator between values

Serial.print(sensorValue, DEC); //Actual value

/*

//You can add in this part of the code if you want to monitor more than one Thirsty Plant

Serial.print(separator);//Separate different readings

int sensorValue2 = analogRead(A1);

Serial.print("Thirsty Plant 2"); //Label for the sensor

Serial.print(":"); //Seperator between values

Serial.print(sensorValue2, DEC); //Actual value

Serial.print(separator);//Separate different readings

int sensorValue3 = analogRead(A2);

Serial.print("Thirsty Plant 3"); //Label for the sensor

Serial.print(":"); //Seperator between values

Serial.print(sensorValue3, DEC); //Actual value

*/

Serial.println();

}

Using Processing to Make the Graph

Processing:

If you haven’t used Processing before you can download the software from www.processing.org. Processing is very like arduino but its outputs are image based rather than hardware based. Processing will take the information we’ve printed to serial(9600) and use it to plot a graph.

Our sketch may look quite complicated but it allows the sketch to read multiple Thirsty Plant inputs and put all the graphs on one page. Read through it to see how it is working.

import processing.serial.*;

Serial myPort;

String delimiterBetweenMultipleValues = "|";

String delimiterBetweenLabelAndValue = ":";

int numserialreads=0;

int graphStartX = 100;

int textPadding = 2;

int circleDiameter = 3;

String[] valuePairs;

boolean drawPoint = false;

boolean drawCircle = true;

boolean drawLine = true;

int xPos = graphStartX; // horizontal position of the graph

int partH; // partial screen height

int valmin = 0; // Minimum Value of Graph

int valmax= 600; //Maximum value of Graph

void setup()

{

size(1366, 700); //adjust to your screen size

println(Serial.list()); //Get Serial Setup

myPort = new Serial(this, Serial.list()[0], 9600); //Open Serial Port at 9600

myPort.clear(); //Empty the Buffer

myPort.bufferUntil('\n'); //Don't generate a serialEvent() unless you get a newline character:

background (170, 219, 207); //Initial Background Colour

textSize(42); //Text Size

fill (237, 61, 138); //Font Colour

}

void draw()

{

//Everything happens in the serialEvent()

}

void keyPressed() //This will let us refresh the screen when he hit the 'n' key

{

if (key == 'n') {

xPos = 0;

background (170, 219, 207); //Wipes screen with turquoise background

}

}

void serialEvent (Serial myPort)

{

String inString = myPort.readStringUntil('\n'); //Get ASCII String:

if (inString != null) {

numserialreads++;

inString = trim(inString); // Trim off any white space

println(inString); //Show the incoming data string

if (numserialreads<20) //Reset Everything

{

println("initializing");

return;

}

if (numserialreads == 20) //Reset Everything

{

xPos = 0; //Return to 0 position

background(170, 219, 207, 255); // Clear screen and show turquoise background

}

valuePairs = split(inString, delimiterBetweenMultipleValues); //split incoming string into pairs of label/value and store in an array.

int totalinputs = valuePairs.length;

partH = height / totalinputs; //Divide screen up by number of sensors

for (int j=0; j

{

String[] pair;

pair = split(valuePairs[j], delimiterBetweenLabelAndValue);

String label;

label = pair[0];

text(label, 10, partH*(j+1) -10);

pair[1]=trim(pair[1]);

int value = int(pair[1]);

value = int(map(value, valmin, valmax, 0, partH)); //Map the value to the variable partial heights

if (j==0){

stroke(245, 230, 86);

}

if (j==1){

stroke(241, 90, 49);

}

if (j==2){

stroke(0, 173, 181);

}

line(xPos, partH*(j+1), xPos, partH*(j+1) - value); //graph its value

stroke(255); //dividing line colour

line(0, partH*(j+1), width, partH*(j+1));

}

if (xPos>= width)

{

xPos = 0;

background(170, 219, 207, 255); // Clear screen and show turquoise background

} else

{

xPos++; //increment the graph's horizontal position

}

}

}

void exit() {

myPort.stop();

}

Verify, Upload and Experiment!

Verify and Upload: Once you are happy with both your sketches upload to Arduino. Once your Arduino sketch is loaded you can press the Run button in processing to see your graph. Make sure your serial monitor in your Arduino application is turned off, otherwise Processing will not be able to read the serial port!

If you sensor is totally dry the graph should be quite high. If you pick it up in your hand so that you touch both of the nails you should see your graph begin to drop.

The peaks you see in your graph when it’s at its tallest are from the blinking LED, the peaks should correspond to the flashes it is making.

Place the sensor in a plant pot, water it, and watch the graph descend.

You can use this data to do many different things, maybe see how long it takes your soil to dry out, make your plant talk by tweeting you when it’s dry, or maybe try changing the resistor in your Thirsty Plant to see if it affects how dry your soil can be!