Tuesday, November 30, 2010

code for slave arduinos

#include <Wire.h>
#define ADDRESS 65

// these are digital pins (leds)
int led[]={2,3,4,5,6,7,8,9,10,11,12,13,14,15,16};

// these are analog pins (photoresistors and pir)
int photo[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14};
int ambient = 15; // this is used for the comparison of each photoresistor
int light[15];

void setup() {      

  Serial.begin(9600);
  Wire.begin(ADDRESS);
  Wire.onReceive(receiveEvent);
 
  for(int i = 0; i< 15; i++){
    pinMode(led[i],OUTPUT);
  }

  for(int i = 0; i< 15; i++){
    pinMode(photo[i],INPUT);
  }

  pinMode(ambient, INPUT);
  
}


void loop() {
}

void receiveEvent(int val){

while (Wire.available() > 0){
val = Wire.receive();
int compare = analogRead(ambient);
Serial.println(val);

for(int i = 0; i< 15; i++){
 light[i] = analogRead(photo[i]);
}

if (val == 111){

  int delayTime = 250; //the time (in milliseconds) to pause between LEDs
                       //make smaller for quicker switching and larger for slower
 
  for(int i = 0; i < 15; i++){
    int offLED = i - 1;  //Calculate which LED was turned on last time through
    if(i == 0) {         //for i = 1 to 7 this is i minus 1 (i.e. if i = 2 we will
      offLED = 15;        //turn on LED 2 and off LED 1)
    }                    //however if i = 0 we don't want to turn of led -1 (doesn't exist)
                         //instead we turn off LED 7, (looping around)
    digitalWrite(led[i], HIGH);     //turn on LED #i
    digitalWrite(led[offLED], LOW); //turn off the LED we turned on last time
    delay(delayTime);
}
}
else if( val != 0){

// for the control of leds----------------------------------
for(int i = 0; i< 15; i++){
 
   if (light[i] > compare + 10){
      digitalWrite(led[i], HIGH);
   }
  
   else {
   digitalWrite(led[i], LOW);
   }
  
}
}

else if (val == 0){
  for (int i = 0; i< 15; i++){
    digitalWrite(led[i], LOW);
  }
}
}
}

code for master arduino

#include <Wire.h>
int ADDRESS[] = {65,42,43,60,61,62,64,65};

// these are digital pins (leds)
int led[]={2,3,4,5,6,7,8,9,10,11,12,13};

// these are analog pins (photoresistors and pir)
int photo[] = {0,1,2,3,4,5,6,7,8,9,10,11};
int ambient = 15; // this is used for the comparison of each photoresistor
int motion = 14; // pir sensor digital
int motion2 = 13; // second pir sensor
int sound = 12;

int light[12];

void setup() {      

  Serial.begin(9600);
  Wire.begin();
 
  for(int i = 0; i< 12; i++){
    pinMode(led[i],OUTPUT);
  }

  for(int i = 0; i< 12; i++){
    pinMode(photo[i],INPUT);
  }

  pinMode(ambient, INPUT);
  pinMode(motion, INPUT);
  pinMode(motion2, INPUT);
  
}


void loop() {

int compare = analogRead(ambient);
int val = analogRead(motion);
int val2 = analogRead(motion2);
int noise = analogRead(sound);
Serial.print(val);
Serial.print(' ');
Serial.print(val2);
Serial.print(' ');
Serial.println(noise);

for(int i = 0; i< 12; i++){
 light[i] = analogRead(photo[i]);
}

int i= 0;
while( i < 8){
 
//Serial.println("val");
int value = ADDRESS[i];
Wire.beginTransmission(value);
//Serial.println(i);
if( val >= val2){
Wire.send(val);
}
else{
  Wire.send(val2);
}
Wire.endTransmission();
i++;
}


if (noise >= 10){
 
  int delayTime = 50; //the time (in milliseconds) to pause between LEDs
                       //make smaller for quicker switching and larger for slower
 
  for(int i = 0; i <= 12; i++){
    int offLED = i - 1;  //Calculate which LED was turned on last time through
    if(i == 0) {         //for i = 1 to 7 this is i minus 1 (i.e. if i = 2 we will
      offLED = 12;        //turn on LED 2 and off LED 1)
    }                    //however if i = 0 we don't want to turn of led -1 (doesn't exist)
                         //instead we turn off LED 7, (looping around)
    digitalWrite(led[i], HIGH);     //turn on LED #i
    digitalWrite(led[offLED], LOW); //turn off the LED we turned on last time
    delay(delayTime);
  }
 
  int i = 0;
  while (i< 8){
  Wire.beginTransmission(ADDRESS[i]);
  int number = 111;
  Wire.send(number);
  Wire.endTransmission();
  delay(150);
  i++;
  }

}


if( val != 0 || val2 != 0){
// for the control of leds----------------------------------
for(int i = 0; i< 12; i++){
 
   if (light[i] > compare + 10){
      digitalWrite(led[i], HIGH);
   }
  
   else {
   digitalWrite(led[i], LOW);
   }
  
}
}

else if (val == 0 && val2 == 0){
  for(int i = 0; i<12; i++){
    digitalWrite(led[i], LOW);
  }
}
}

Friday, November 26, 2010

electromagnets...

So far, the only successful electromagnets that we managed to make were out of transformer coils. Unfortunately we only have enough supplies to make ten for the final project so we spent the majority of the week experimenting with different forms of electromagnets. We finally acquired some enameled wire which greatly helped the process along. Ekta managed to wrap a magnet that caused the ferrofluid to spike:



 

I also tried to make electromagnets that used the ferrofluid as a core so we wouldn't have to worry about sealing the box they are in. These magnets, as seen below, do not spike but form a small bump of ferrofluid. 





The final form of our project will contain magnets which spike (made the same way Ekta made her's). We found a better way to seal the magnets into the acrylic using epoxy clay which passed both water and ferrofluid leak tests which we ran for several consecutive days.

3 boxes

We decided that our final project would be composed of three modules; each responding to either light, sound, or touch. The form was three meter wide vertical boxes, with a viewing window 54" off the ground and extending 18 inches up. One of the boxes was presented in class and was not well received, causing us to reconsider the final form of our project. I wrote and tested programs for all three responses so if we proceed with any of them the coding will be at least partially done.

working module


The requirement for this week was to have a working module of our final project to present. Since we switched our project the previous week we had to come up with a project and get it working in a relatively short amount of time. We presented an array of extended core electromagnets which were turned on in response to changes in light. The magnets were made with lag bolts and the enameled wire coils that were taken out of transformers. Each magnet was paired with a photoresistor and turned on when a shadow was over it. This is a view from the bottom of our module showing the electromagnets and relays:

This is a side view of the fully assembled module with the ferrofluid in it. The spikes are the threads of the lag bolts which were used as the core of the electromagnets.


A spiral of ferrofluid formed by turning on one of the electromagnets:


We had a small problem with leaking ferrofluid since the heat produced by the electromagnet heated the silicone seals we used. We plan on finding a more reliable sealant for the final and using drip pans as backup.


Saturday, November 6, 2010

Movement mechanisms and a new project

It was decided that we needed to further explore movement mechanisms so for the weekend we split up into pairs and each prototyped mechanisms that seemed viable on paper. Unfortunately, paper doesn't always translate well into real life if you don't take the time to work out the mechanics of the system. Here is what resulted (plus one more gear mechanism which is not shown):




Since none of these worked very well, the majority of the group wanted to give up on this project and pursue something which is mechanistically easier and has a higher chance of working well. Now we are making a table which contains ferrofluid which is activated by electromagnets.

Week 6

We received our final 6 week project and were required to make a biomimetic smart surface. The assignment is very open ended which made it difficult to come up with a project as we could take the assignment and our three thousand dollars and go in whichever direction we choose. Our group had several meetings where we each presented our ideas of what direction the project could take. As a result, we came up with a list:

  • sphere that responds to stimuli
  • sea cucumber inspired surface
  • boxes that for furniture
  • collection of surfaces that mimic a shoal of fish
  • blimps that hover by a light 
  • spider web of fiber-optics
  • device that moves on the ground and interacts with people
  • surface that falls apart and rebuilds
  • plants that move toward water
  • fancy coffee maker
  • seeded paper
  • wall of stacked shapes that makes sound
  • anemone surface
  • wall covering that shrinks and expands
Through a series of long discussions it was narrowed down to the collection of surfaces that mimics a shoal of fish and the wall of stacked shapes that make sound. We discussed each project further, took a break for the night, and resumed the next day to make a decision. After much compromise in the form, it was decided that we would go with the collection of surfaces that moved similar to a shoal of fish on a window. There was the possibility of them being autonomous so we decided to explore mechanisms for movement on a track and independently on a grid or mesh which would be placed over the window. Unfortunately, the majority of the mechanisms were never prototyped and we just discussed them on paper resulting in the presentation of only one (wheels on a pipe) presented in class.