Saturday, March 23, 2013

Grass Led

For my grass I want leds that fad on and off. I wrote a program to do what I wanted:
Here is the code for that:


const int led1 = 3;
const int led2 = 5;
const int led3 = 6;
const int led4 = 9;
const int led5 = 10;

int fadeAmount1 = 1;
int fadeAmount2 = 1;
int fadeAmount3 = 1;
int fadeAmount4 = 1;
int fadeAmount5 = 1;
int brightness1 = 0;
int brightness2 = 51;
int brightness3 = 102;
int brightness4 = 153;
int brightness5 = 0;


void setup() {
 
  Serial.begin(9600);
 
}

void loop() {
 
  analogWrite(led1, brightness1);
  analogWrite(led2, brightness2);
  analogWrite(led3, brightness3);
  analogWrite(led4, brightness4);
  analogWrite(led5, brightness5);


  // change the brightness for next time through the loop:
  brightness1 = brightness1 + fadeAmount1;
  brightness2 = brightness2 + fadeAmount2;
  brightness3 = brightness3 + fadeAmount3;
  brightness4 = brightness4 + fadeAmount4;
  brightness5 = brightness5 + fadeAmount5;

  // reverse the direction of the fading at the ends of the fade:
  if (brightness1 == 0 || brightness1 == 255) {
    fadeAmount1 = -fadeAmount1 ;
  }    
  if (brightness2 == 0 || brightness2 == 255) {
    fadeAmount2 = -fadeAmount2;
  }    
  if (brightness3 == 0 || brightness3 == 255) {
    fadeAmount3 = -fadeAmount3;
  }      
  if (brightness4 == 0 || brightness4 == 255) {
    fadeAmount4 = -fadeAmount4 ;
  }    
  if (brightness5 == 0 || brightness5 == 255) {
    fadeAmount5 = -fadeAmount5;
  }    
  // wait for 30 milliseconds to see the dimming effect  
  //delay(30);                    
  Serial.println(brightness1);
}

The problem is that when I tried to add this to the code I previously had with the servos and the range sensor in it, it freaked out and did this:
Here is the code for the entire program. It works just fine with the range finder and the servos. The range finder is a little slow so I don't know if that might be causing problems.

#include <Servo.h>

Servo grass;
Servo flower;

const int led1 = 3;
const int led2 = 5;
const int led3 = 6;
const int led4 = 9;
const int led5 = 10;

int fadeAmount1 = 1;
int fadeAmount2 = 1;
int fadeAmount3 = 1;
int fadeAmount4 = 1;
int fadeAmount5 = 1;
int brightness1 = 0;
int brightness2 = 51;
int brightness3 = 102;
int brightness4 = 153;
int brightness5 = 0;


#include <Ultrasonic.h>

#define TRIGGER_PIN  12
#define ECHO_PIN     13

Ultrasonic ultrasonic(TRIGGER_PIN, ECHO_PIN);


void setup() {
 
  Serial.begin(9600);
  grass.attach(14);//pins 9 and 10 don't work with servos
  flower.attach(2);

}

void loop() {
 
   grass.write(92);
   flower.write(179);
/*  
   float cmMsec, inMsec;
  long microsec = ultrasonic.timing();

  cmMsec = ultrasonic.convert(microsec, Ultrasonic::CM);
  inMsec = ultrasonic.convert(microsec, Ultrasonic::IN);
  Serial.print("MS: ");
  Serial.print(microsec);
  Serial.print(", CM: ");
  Serial.print(cmMsec);
  Serial.print(", IN: ");
  Serial.println(inMsec);
  //delay(1000);
*/
  analogWrite(led1, brightness1);
  analogWrite(led2, brightness2);
  analogWrite(led3, brightness3);
  analogWrite(led4, brightness4);
  analogWrite(led5, brightness5);


  // change the brightness for next time through the loop:
  brightness1 = brightness1 + fadeAmount1;
  brightness2 = brightness2 + fadeAmount2;
  brightness3 = brightness3 + fadeAmount3;
  brightness4 = brightness4 + fadeAmount4;
  brightness5 = brightness5 + fadeAmount5;

  // reverse the direction of the fading at the ends of the fade:
  if (brightness1 == 0 || brightness1 == 255) {
    fadeAmount1 = -fadeAmount1 ;
  }    
  if (brightness2 == 0 || brightness2 == 255) {
    fadeAmount2 = -fadeAmount2;
  }    
  if (brightness3 == 0 || brightness3 == 255) {
    fadeAmount3 = -fadeAmount3;
  }      
  if (brightness4 == 0 || brightness4 == 255) {
    fadeAmount4 = -fadeAmount4 ;
  }    
  if (brightness5 == 0 || brightness5 == 255) {
    fadeAmount5 = -fadeAmount5;
}
}

I had the range finder code commented out because I thought it might be causing issues, but that didn't seem to help at all.

Ultrasonic Distance Sensor HC-SR04

I was figuring out how to use my range sensor. I downloaded the Arduino library for it here:
HCSR04 Ultrasonic Library

For directions on how to install an Arduino library go to
Arduino Libraries

The library comes with examples, I was using the UltrasonicStdDev to test my sensor.

Here is a diagram of how to wire the sensor to the Arduino:

I also tried this New Ping library from:
I had trouble getting it to run:

Thursday, March 14, 2013

In Progress

Initial Sketching:
This is the first try at the project. It had a few hiccups as far as what I was originally intending. I wrote the "Modifications" above after crafting this first version. 

This is how I made the fiber optic elements I am using for this project.

Tuesday, March 12, 2013

Materials Ideas and More Sketches

I love the diffusion of the light by these leaves. I think my flowers are going to be something similar to this. I love the warm glow of the light and the organic-ness of using leaves in this way. 

http://www.save-on-crafts.com/leaflights1.html

I was thinking of maybe buying lamps to get the fiber optic filaments from. They are super cheap on amazon, but then they get you with the shipping. Maybe try fishing line?


http://www.amazon.com/gp/offer-listing/B000Z9C0W2/ref=zg_bs_5486433011_price?ie=UTF8&condition=new


Sunday, March 3, 2013

Sketches

Here are some sketches for my midterm project. I'm hoping that I after I post these I will have many more wonderful ideas.