Monday, December 6, 2010

Wednesday 11/10 (22 days left)


          Our meeting Tuesday was only slightly effective, which left Wednesday to build our module. Simon went to stadium hardware in the morning to buy materials for our frame, and he and I built it together. It was slightly less sturdy than we had hoped, meaning the final modules should probably be smaller and more compact. The rest of the design used boards of MDF at the top and bottom to keep our metal rods in place. The rods were attached to gears that threaded with those on the stepper motors. The motion of each rod was actually quite smooth, as Simon was able to get ball bearings on which each rod could rotate. However, the motion of the panels was quite jerky and inconsistent when connected to the stepper motors, whose discrete angular intervals of rotation were amplified by the use of larger gears.
            I worked mostly on construction into the evening, but once the team was assembled in full I was able to help Chris with the Arduino aspect of the project. I was able to write the code that took in information from the PIR sensors and output a signal to the motors to make them rotate. This worked, although we had trouble getting the stepper motors themselves to rotate smoothly. It was definitely nice to do some work with the Arduino this week, as I had been unable to help out much in previous weeks. I’m normally not great at writing programs but this system of hacking and imitating really worked for me- I ran into few problems with the code (which was admittedly simple- here it is)
// Actuate stepper motors based on readings from PIR Sensors
// Dan Connors, Design Team 2
//

#include <Stepper.h>
#define STEPS 100

Stepper stepper1(STEPS, 0, 1, 2, 3);
Stepper stepper2(STEPS, 4, 5, 6, 7);  
Stepper stepper3(STEPS, 8, 9, 10, 11);

int  val1 = 0;                 // storage for analog output of PIR
int  val2 = 0;
int  val3 = 0;
int  pirSensor1 = 0;           // the passive infra red sensors will be plugged
int  pirSensor2 = 1;           // at analog pins 0, 1, 2
int  pirSensor3 = 2;
int THRESHOLD = 5;

void setup() {
  Serial.begin(9600);
 
  stepper1.setSpeed(100);       // motor speed = 30 RPM
  stepper2.setSpeed(100);
  stepper3.setSpeed(100);
}

void loop() {
 
  val1 = analogRead(pirSensor1);   //read values from PIR sensors
  val2 = analogRead(pirSensor2);
  val3 = analogRead(pirSensor3);
 
  while ((val1 >= THRESHOLD) && (val2 < THRESHOLD) && (val3 < THRESHOLD)) {
    stepper1.step(10);             //turn on motor 1 if PIR 1 senses motion
    stepper2.step(0);
    stepper3.step(0);
    val1 = analogRead(pirSensor1); //read values again- keeps motors going
    val2 = analogRead(pirSensor2); //if motion hasn't stopped
    val3 = analogRead(pirSensor3);
    delay(125);
  }
 
  //repeat for each possible scenario of PIR sensors
 
  while ((val1 >= THRESHOLD) && (val2 >= THRESHOLD) && (val3 < THRESHOLD)) {
    stepper1.step(10);
    stepper2.step(10);
    stepper3.step(0);
    val1 = analogRead(pirSensor1);
    val2 = analogRead(pirSensor2);
    val3 = analogRead(pirSensor3);
    delay(125);
  }
 
  while ((val1 >= THRESHOLD) && (val2 >= THRESHOLD) && (val3 >= THRESHOLD)) {
    stepper1.step(10);
    stepper2.step(10);
    stepper3.step(10);
    val1 = analogRead(pirSensor1);
    val2 = analogRead(pirSensor2);
    val3 = analogRead(pirSensor3);
    delay(125);
  }
 
  while ((val1 < THRESHOLD) && (val2 >= THRESHOLD) && (val3 >= THRESHOLD)) {
    stepper1.step(0);
    stepper2.step(10);
    stepper3.step(10);
    val1 = analogRead(pirSensor1);
    val2 = analogRead(pirSensor2);
    val3 = analogRead(pirSensor3);
    delay(125);
  }
 
  while ((val1 >= THRESHOLD) && (val2 < THRESHOLD) && (val3 >= THRESHOLD)) {
    stepper1.step(10);
    stepper2.step(0);
    stepper3.step(10);
    val1 = analogRead(pirSensor1);
    val2 = analogRead(pirSensor2);
    val3 = analogRead(pirSensor3);
    delay(125);
  }
 
  while ((val1 < THRESHOLD) && (val2 < THRESHOLD) && (val3 < THRESHOLD)) {
    stepper1.step(0);
    stepper2.step(0);
    stepper3.step(0);
    val1 = analogRead(pirSensor1);
    val2 = analogRead(pirSensor2);
    val3 = analogRead(pirSensor3);
    delay(125);
  }
 
  while ((val1 < THRESHOLD) && (val2 < THRESHOLD) && (val3 >= THRESHOLD)) {
    stepper1.step(0);
    stepper2.step(0);
    stepper3.step(10);
    val1 = analogRead(pirSensor1);
    val2 = analogRead(pirSensor2);
    val3 = analogRead(pirSensor3);
    delay(125);
  }
 
  while ((val1 < THRESHOLD) && (val2 >= THRESHOLD) && (val3 < THRESHOLD)) {
    stepper1.step(0);
    stepper2.step(10);
    stepper3.step(0);
    val1 = analogRead(pirSensor1);
    val2 = analogRead(pirSensor2);
    val3 = analogRead(pirSensor3);
    delay(125);
  }

 
The panels themselves were squares, but to make the module more visually interesting we rotated them 45 degrees in the plane of the surface so that they partially overlapped with those in the neighboring rows. We didn’t have enough acrylic to make the tiles as well as some of the mock-ups we had used, so we spray painted some chipboard. This was less effective, but served our purposes well enough.

No comments:

Post a Comment