Make Your Own Thirsty Plant Graph!

Introduction: Make Your Own Thirsty Plant Graph!

About: Technology Will Save Us is a haberdashery for making technology in everyday life. We design, manufacture and sell DIY technology Kits and run workshops to help people become makers and creators of technology, …

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 ( to read the Thirsty Plant and Processing ( to plot the graph.

Step 1: Setting Up the Hardware: Part One

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.

Step 2: Setting Up the Hardware: Part Two

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.

Step 3: Coding With 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()




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




Step 4: Using Processing to Make the Graph


If you haven’t used Processing before you can download the software from 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) {


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

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

if (numserialreads<20) //Reset Everything





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);


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() {



Step 5: 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!

Be the First to Share


    • Potato Speed Challenge

      Potato Speed Challenge
    • Mason Jar Speed Challenge

      Mason Jar Speed Challenge
    • Bikes Challenge

      Bikes Challenge