As computing becomes more ubiquitous in our objects, designers need to be more aware of how to design meaningful interactions into electronically enhanced objects. At the University of Washington, a class of junior Interaction Design majors is exploring this question. These pages chronicle their efforts.

Thursday, May 2, 2013

Enrique & Karin - Week 4

We received our first sensor in the mail late last week. It reads the moisture levels in the soil. This week we wanted to test the sensor by having it detect the water in the soil and provide an analog output.

First we connected three different colored lights to the circuit board. Then we established numerical values for "dry", "moist", and "wet". Lastly we wrote the code that would take the moisture readings and prompt the correlating light to turn on and the one before it to turn off.

Below is a video of what our test looked like:

And this is the code that made it possible:


/*
  # Experiment code for the moisture sensor
  # Editor     : Karin & Enrique
  # Date       : 05.02.2013
  # Version    : 1.0
  # Connect the sensor to the A0(Analog 0) pin on the Arduino board
  # Connect LEDs to pin 13, 8 & 7
  # Give the sensor 5V input

  # the sensor value description
  # 0  ~500     in water
  # 500~700     humid soil
  # 700~1000     dry soil
*/

int green = 13;
int yellow = 8;
int red = 7;

int moistureValue = 0;

void setup(){
  // initialize the digital pins as outputs.
  pinMode(green, OUTPUT);
  pinMode(yellow, OUTPUT);
  pinMode(red, OUTPUT);

  Serial.begin(9600);
 }

void loop(){
  moistureValue = analogRead(0);
  Serial.print("Moisture Sensor Value: ");
  Serial.println(moistureValue, DEC);
  delay(100);

  //Light red if it's dry
  if (moistureValue >700){
     digitalWrite(red, HIGH);   // turn the LED on (HIGH is the voltage level)
     digitalWrite(yellow, LOW);   // turn the other LEDs off
     digitalWrite(green, LOW);
  }
  //Light green if it's really wet
  else if(moistureValue < 500){
     digitalWrite(green, HIGH);   // turn the LED on (HIGH is the voltage level)
     digitalWrite(yellow, LOW);  // turn the other LEDs off
     digitalWrite(red, LOW);
  }
  //Light Yellow if it's moist
  else{
    digitalWrite(yellow, HIGH);   // turn the LED on (HIGH is the voltage level)
    digitalWrite(red, LOW);   // turn the other LEDs off
    digitalWrite(green, LOW);
  }

}

No comments:

Post a Comment