Plant Assistant

Submitted by syh on Tue, 02/26/2013 - 20:21

Description: This plant assistant measures the ambient light around a houseplant, and the weight of the plant in the pot. As moisture levels decrease in the soil, the plant loses some of its weight, and the blue circle in the display gets smaller, indicating that it may be time to add some water. Additionally, as lighting around the plant decreases, the background of the display gets darker, which helps the viewer ascertain where in the house the plant should be placed, depending on its sunlight needs.
Note: I used a combination of the provided code and this tutorial (http://itp.nyu.edu/physcomp/Labs/SerialDuplex) to help write my Processing code.

Components:

 

  • Arduino Uno + USB cable

  • Breadboard

  • 2 LEDs (green, blue)

  • 2 220-ohm resistors

  • 2 10k-ohm resistors

  • 1 photocell

  • 1 force sensitive resistor

 

  • 2 pieces of cardboard

  • 1 piece of scrap felt


Arduino code:
/*
 Very basic code to output light and force sensor readings to serial.
 Used mainly in conjunction with Processing, but will map green LED
 to light values, and blue LED to force values.
*/


//sensor inputs
int sensorLight = 0;
int sensorTouch = 1;

//LED outputs
int blueOut = 9;
int greenOut = 11;

int valBrightG = 0;
int valBrightB = 0;

//variable for counting loops
int i = 0;

void setup()
{
 pinMode(blueOut, OUTPUT);
 pinMode(greenOut, OUTPUT);
 Serial.begin(9600);
}

void loop()
{
 i+=1; //count loop in case you want it
 
 //light sensor value sent to serial
 valBrightG = analogRead(sensorLight);
 Serial.print(valBrightG);
 analogWrite (greenOut, valBrightG);
 
 //separator
 Serial.print(",");
 
 //force sensor value sent to serial
 valBrightB = analogRead(sensorTouch);
 Serial.println(valBrightB);
 analogWrite(blueOut, valBrightB);
}

Processing code:
/*  Takes input from a photo cell and a force sensitive resistor.
   Works with Arduino code to read analog input.
   Creates a screen whose background shade changes according to ambient light,
   and a blue circle whose size changes according to pressure on sensor.
*/

import processing.serial.*;

String portname = "/dev/tty.usbmodemfa131";
Serial port;

// sensor info
float light, weight;

// screen size
int scrwidth = 600;
int scrheight = 600;

void setup(){

//screen setup
 size(scrwidth,scrheight);
 frameRate(10);
 smooth();
 
//port setup  
 port = new Serial(this, portname, 9600);
 port.bufferUntil('\n');
}

//draw the screen: background changes according ot light
//and blue circle size changes according to pressure
void draw() {
 background(light);
 fill(10,50,200);
 ellipse(width/2,height/2, weight,weight);
}

//read in serial events
void serialEvent(Serial p){
 String str = p.readString();
 if (str != null){
  str = trim(str);    
  int sensors[] = int(split(str, ','));
  
  //set sensor data; sensors[0] is light and sensors[1] is pressure
  if(sensors.length > 1){
    light = sensors[0]/2;
    weight = sensors[1]+100;     
  }   
 }
}

DSC02513.JPG
DSC02514.JPG
Screenshot.png
0
Your rating: None
Drupal theme by Kiwi Themes.