openobject.org

Project

From Physical Programming

The Project that I decided upon was a simply experiment that could be pushed further and further. I wanted to use an LDR (Light Dependent Resistor) as an motion sensor device to allow an array of LEDS to work, to fade in and fade out much there was no movement.

Instead of creating a matrix i created a simply box to conceal my cricuit inside and try to create a mild interactive box that someone could play with for round 5 to 10 secs.

The idea is that an array of LEDS is connected to each side of the box. Connecting the LDR's the Analog Inputs, five in total. They would when a motion or lack of light passed across the top of the box or sides. Creating some little amount of feedback that the observer can take in.

12 LEDS in total create the array, two and each side and four upon the top. I have setup up so that two LEDS will run of a 10k resistor and then back into the ground of the board. Much like the diagram.

This is the code that I will use, its not complete but i was experimenting with ledPin's and the number that I can control in the one sketch. I wanted to setup my code, by having a more complex version of the Arduino offers for LDRS. I was trying to create a sketch, that in the one basic code would allow for all analog inputs and array's to work on a variable. By having something like this:

int sensorPin [a] = {0, 1, 2, 3, 4};
int ledPin [] = {3, 5, 6, 9, 10, 11};// PWM outputs so that the LEDS can fade  in and out  
                                      
int val = a                                       

Fading Motion Sensor.

int sensorPin = 0; // select the input pin for the sensor

int ledPin [] = {3, 5, 6, 9, 10, 11}; //selected pins for array of leds

int val = 0; // variable to store the value coming from sensor

void setup()

{int [a]

pinMode (ledPin[a], OUTPUT); //ledPin as an OUTPUT

}void loop() {

val = analogRead (sensorPin); // read value from sensor

digitalWrite (ledPin, HIGH);

delay (val); digitalWrite (ledPin, LOW);

delay (val);

}

Contents

Experimenting with the Arduino

This is the first time I have ever used a Arduino or this kind of software, so to start out I thought I'd do some playing around with some of the simply aspects and code that are available on the website.

http://arduino.cc/en/Tutorial/HomePage


Experiment One

I experiment is just using an LDR to control and LED. This is one straight off the Arduino website ( http://arduino.cc/en/Tutorial/AnalogInput ). I used this code an changed some of it to make a little more sense to me. This code is for the use of a potentiometer so I simply changed the pin name.

Image:Experimentone.jpg

The code

int sensorPin = 0;
int ledPin = 13;
int val = 0;
  void setup() {
    pinMode(ledPin, OUTPUT);
}
  void loop() {
    val = analogRead(sensorPin);
    digitalWrite(ledPin, HIGH);
    delay(val);
    digitalWrite(ledPin, LOW);
    delay(val);
} 

Experiment Two

Again here I used the website to create another experiment or test for myself. Although the code is there for this one I had some trouble getting it to work. I only have a small breadboard with no ground strip, so to fit six LED's became difficult. I had to create a ground at the end of each LED instead of running each through the ground strip on the breadboard. Having so many wires got confusing. Eventually I got it to work but I had to reduce the number of LED's to four so that I could fit them on the board and still understand what was going on with the circuit. http://arduino.cc/en/Tutorial/Loop

Image:Experimenttwo.jpg

Experiment Three

For this I wanted to see if I could have the array run whilst also running a vibrator. My major project is using small vibrating mechanism's to create feedback output for the deaf. For this I adapted two existing codes into allowing them to run as one and have both items working.

I used a PWM output to allow me to control the speed at which the motor would spin but found that anything under full (255) it wouldn't spin properly. During this experiment I also tried the incorporation of the LDR to control the on ana off of the motor (creating a motion sensor effect).

During this experiment I also played with taking the Arduino off the USB and connected it to a AC/DC adaptor. I'm looking a using a 9V stand alone battery with the Arduino so that it can be used away from the computer.

The code

int sensorPin = 2;    // select the input pin for the potentiometer
int ledPin = 11;      // select the pin for the LED
int timer = 100;       // The higher the number, the slower the  timing.
int pins[] = { 2, 3, 4, 5,  }; // an array of pin numbers
int num_pins = 4;           // the number of pins (i.e. the length of    array)
  void setup() {
   pinMode(ledPin, OUTPUT);  // declare the ledPin as an OUTPUT
   int i;
for (i = 0; i < num_pins; i++)//array elements are numbered from0to num_pins-1
   pinMode(pins[i], OUTPUT);      // set each pin as an output
}
void loop() {
 analogRead(sensorPin);  // read the value from the sensor
 analogWrite(ledPin, 0);  // turn the ledPin on
 analogWrite(ledPin, 255);   // turn the ledPin off
  int i;
   for (i = 0; i < num_pins; i++) { // loop through each pin...
   digitalWrite(pins[i], HIGH);   // turning it on,
   delay(timer);                  // pausing,
   digitalWrite(pins[i], LOW);    // and turning it off.
 }
 for (i = num_pins - 1; i >= 0; i--) { 
   digitalWrite(pins[i], HIGH);
   delay(timer);
   digitalWrite(pins[i], LOW);
 }
}

Experiment Four

I tried to add the use of a switch to control the use of the vibrator. I'm going to look at using pressure sensitive switches later in a progression to this project and wanted to know if i could do it here. As you can see in the code i have used the switch as the inPin and the motor as an normal ledPin. Allowing it to follow the the same HIGH, LOW OUTPUT commands as the LED would.

I did this because of the size of the motor of the vibrator. Its only really small and the voltage wouldn't be that great.

The Code

int ledPin = 11; // choose the pin for the LED
int inPin = 2;   // choose the input pin (for a pushbutton)
int val = 0;     // variable for reading the pin status
 void setup() {
  pinMode(ledPin, OUTPUT);  // declare LED as output
  pinMode(inPin, INPUT);    // declare pushbutton as input
}
 void loop(){
  val = digitalRead(inPin);  // read input value
  if (val == HIGH) {         // check if the input is HIGH (button released)
    digitalWrite(ledPin, LOW);  // turn LED OFF
  } else {

Image:Experimentfour.jpg

Making

The making of this was quite a challenge, although most of you probably think this concept was easy. I wired mine up so that I wasn't using the breadboard too much. I built it so that the breadboard is used to ground out the ciruit and give it power which is probably the whole thing. Basically I setup up two LEDS following a resistor from power through the breadboard and then back through the board into ground.

STEP ONE I had to build the box that it would fit into. I used MDF and pine to create a small raised box with enough room for all my wiring. I cleaned the box up with body filler and painted it white so that the LEDS would be easier to see in light situations.

Image:Step6.jpg Image:Step7.jpg Image:Steps5.jpg

STEP TWO Drilled the holes for the LED's and the LDR's so that I could move onto setup and soldering the wires for my circuit. I marked the holes by eye it really wasn't too important just as long as they roughly matched on all sides.

Image:Ledtop.jpg Image:Ledbottom.jpg

STEP THREE I sat thinking how hard it will be to wire this puppy, so i did some test run's to see whether the circuit would work. From this i had found that i has soldered the LED's in the wrong way and had to start over. It was hard to experiment whether I wasdoing the right thing without a Arduino. More a trail and error by it looks.

Image:Steps4.jpg Image:Steps3.jpg

STEP FOUR Once I was satisfied with how I was going to connect the parts I began to solder them together. I had resistor and two LED's so I wired having the resistor to the anode and the two LED's connected through the cathode and anode.

Image:Steps1.jpg

STEP FIVE They were six series of LED's that run through, the four lights for the top would be connected through the programming that allowed them to work identically of the different output pins but using the same input pin(same LDR.

Once all these had been soldered in the series with a ground wire, I moved onto the LDR only having one I wired it with one resistor so it can be connected up to the analog input 0 on the Arduino board.


Image:Steps.jpg Image:Steps2.jpg