ITP Blog

My journey in making things

Physical Computing – Lesson#3

For this week’s class, I kept practicing the lab exercises, plus started experimenting with Arduino code & the Arduino IDE.

Digital I/O:

I started with building simple applications, turning an LED on/off, using buttons and counting the presses, predominantly learning the ‘digitalRead()’ and ‘digitalWrite()’ functions.

arduino
Assembling lights and buttons

Analog I/O:

Through reading and writing digital values (essentially a high & low values), I kept on learning how analogRead & PWM work, and found a house project I was excited doing that incorporated all of these elements.

The Moisture Checker:

I decided to create a moisture checker that lights up one of three state LEDs to notify you whether the soil is wet enough, ok or bad. Since my actual plants are in my balcony, having the LED on at all time would be both wasted power consumption and might annoy the neighbors, therefore I decided to incorporate a solution for distance sensing to initialise or remove the LEDs.

20160921_131400

I started by defining the goals and scenario in which the thing would use, and once I got this done I moved to sketching the schematic for the assembly.

screen-shot-2016-09-27-at-11-12-32

For the LEDs themselves I decided it would be calmer to use a ‘breathing’ effect by having them fade from on to off in a wave like way. With that in mind I decided to use a loop which will iterate between 0-255 and turn on and off the correct LED.

void ledEffect(int moistureState){
 //Mimic the effect of a sine wave breathing effect for the leds
 //Is there any way I can use an actual number generator to not delay the loop?
 if(counter == 0){
 for(counter = 0; counter < 255; counter++){
 analogWrite(moistureState, counter);
 delay(10);
 }
 } else if (counter == 255){
 for(counter = 255; counter > 0; counter--){
 analogWrite(moistureState, counter);
 delay(10);
 }
 } else {
 counter = 0;
 }
}

The LED breathing effect

Reading the moisture sensor over serial:

Questions for class based on assignment:

  1. I am using a ‘for’ loop to iterate over values ranging from 0-255 in order to create the breathing effect for the LEDs. With that being said I am using the ‘delay()’ function which in return delays the whole loop while the LEDs are on, is there any other way of achieving this effect? perhaps a sine wave generator I can map to the values above without delaying the loop
  2. I find the sensor readings to be very jumpy in values, what would be a good technique to ‘filter’ the values I get back from the moisture sensor?

Hi I am Or, I am a director, developer and artist. My current interest in research is sound interaction, computer vision & immersive media development.

Leave a Reply

Your email address will not be published. Required fields are marked *