Making Things Interactive

May 12, 2008

The Light-o-Stat

Filed under: Assignments,Brian Kish,Final Project,Term Paper — bkish @ 10:22 am

Hello All:

Please take a look at my final term paper for my Light-o-Stat Project by following the attached link.

final-paper1

The majority of my documentation can be seen in the paper, but here are some other things too.


 The Guts of the Project:                          The Mess that I made with an Arduino and Breadboard
The Guts of the ProjectThe Mess that I made with an Arduino and Breadboard
int servoPin = 2;     // Control pin for servo motor
int minPulse = 800;   // Minimum servo position
int maxPulse = 2300;  // Maximum servo position
int neutralPulse = 1500;  //neutral servo
int pulse = 0;        // Amount to pulse the servo
int prevPhotosensor;  //last reading of sensor-last state
int increment = 50;   //pwm changes
int goodLED= 6;
int darkLED= 7;
int brightLED = 5;

long lastPulse = 0;    // the time in milliseconds of the last pulse
int refreshTime = 20; // the time needed in between pulses

int photoSensor = 0;  // the value returned from the analog sensor
int sensorPin = 1;    // the analog pin that the sensor's on
int average = 10;      // reads per cycle
int potSwitch = 0;     //potentiometer switch
int potMin = 0;
int potMax = 0;
int potPin = 0;

void setup() {
  pinMode(servoPin, OUTPUT);  // Set servo pin as an output pin
  pinMode(potSwitch, INPUT);
  pinMode(goodLED, OUTPUT);
  pinMode(darkLED, OUTPUT);
  pinMode(brightLED, OUTPUT);
  pulse = neutralPulse;           // Set the motor position value to the minimum
  digitalWrite(goodLED, LOW);
  digitalWrite(darkLED, LOW);
  digitalWrite(brightLED, LOW);
  Serial.begin(9600);

}

void loop() {
  delay(100);
  int x;
  int photoTotal;
  photoTotal = 0;
  for (x = 0; x<average; x++) {
    photoSensor = analogRead(sensorPin);      // read the analog input
    potSwitch = analogRead(potPin);         //pulse = (photoSensor *19)/10 + minPulse;
    photoTotal = photoSensor + photoTotal;  // convert the analog value
  }
  photoSensor = photoTotal/average;   //average of photo sensor readings

  potMin = potSwitch-25;
  potMax = potSwitch+50;

  Serial.print("Amount of Light = ");
  Serial.println((int)photoSensor);
  Serial.print("Desired amount of light = ");
    Serial.println((int)potSwitch);        

  if (millis() - lastPulse >= refreshTime) {
    digitalWrite(servoPin, HIGH);   // Turn the motor on
    delayMicroseconds(pulse);       // Length of the pulse sets the motor position
    digitalWrite(servoPin, LOW);    // Turn the motor off
    lastPulse = millis();           // save the time of the last pulse
  }

  //good State
  if(photoSensor <= potMax && photoSensor >= potMin){  //if light value is in desired range, do the following
    digitalWrite(goodLED, HIGH);
    digitalWrite(darkLED, LOW);
    digitalWrite(brightLED,LOW);
    Serial.println("Light is good");
    //do nothing with pulse;
  }
  // bright State
  if(photoSensor < potMin){   // if the actual light is greater than desired, do this...remember that the values are reversed, larger number=darker and smaller number = brighter
    digitalWrite(goodLED, LOW);
    digitalWrite(darkLED, LOW);
    digitalWrite(brightLED,HIGH);
    Serial.println("Too Bright");

    //pulse clockwise
    if(prevPhotosensor > photoSensor) {  // if moving the shades makes it darker, it i doing the right thing, continue in this direction
      prevPhotosensor = photoSensor;
      pulse = pulse - increment;
      if (pulse < minPulse)
        pulse = minPulse;
    }

  }

  // dark State
  if(photoSensor > potMax){              // if level of light is below the minimum desired, it is too dark
    digitalWrite(goodLED, LOW);
    digitalWrite(darkLED, HIGH);
    digitalWrite(brightLED,LOW);
    Serial.println("Too Dark");
    //pulse counter-clockwise
    if(prevPhotosensor < photoSensor) {   //if moving the shades makes it lighter, it is doin the right thing
      prevPhotosensor = photoSensor;
      pulse = pulse + increment;
      if (pulse > maxPulse)
        pulse = maxPulse;
    }

  }
}

<pre>

March 27, 2008

Related Projects

Filed under: Brian Kish — bkish @ 1:53 pm

These are some projects that make use of ‘smart walls’ to modulate light.

final-project-proposal2.pdf

PhotoSensor State Machine

Filed under: 8: State Machine,Brian Kish — bkish @ 1:49 pm

state-diagram.jpg

state-diagram.jpgThis a state machine that will be the basis for my final project of automated louvers. This uses 3 LEDs, a photoresistor, a potentiometer, and aservo to communicate. The user is able to set the light levels that they desire by turning a potentiometer. The machine then tells the person one of three things: Light is good, Its too Dark!, or Its too Bright. It glows 3 different LEDs to express which state it is in. There will be pictures and video to follow, once I find my camera :)

const int sGood= 0;
const int sBright = 1;
const int sDark = 2;

int servoPin = 2;     // Control pin for servo motor
int minPulse = 500;   // Minimum servo position
int maxPulse = 2500;  // Maximum servo position
int pulse = 0;        // Amount to pulse the servo
int goodLED= 6;
int darkLED= 7;
int brightLED = 5;

long lastPulse = 0;    // the time in milliseconds of the last pulse
int refreshTime = 20; // the time needed in between pulses

int photoSensor = 0;  // the value returned from the analog sensor
int sensorPin = 1;    // the analog pin that the sensor's on
int potSwitch = 0;
int potMin = 0;
int potMax = 0;
int potPin = 0;

void setup() {
  pinMode(servoPin, OUTPUT);  // Set servo pin as an output pin
  pinMode(potSwitch, INPUT);
  pinMode(goodLED, OUTPUT);
  pinMode(darkLED, OUTPUT);
  pinMode(brightLED, OUTPUT);
  pulse = minPulse;           // Set the motor position value to the minimum
  digitalWrite(goodLED, LOW);
  digitalWrite(darkLED, LOW);
  digitalWrite(brightLED, LOW);
  Serial.begin(9600);

}

void loop() {
  photoSensor = analogRead(sensorPin);      // read the analog input
  potSwitch = analogRead(potPin);
  pulse = (photoSensor *19)/10 + minPulse;    // convert the analog value
  // to a range between minPulse
  // and maxPulse. 

  potMin = potSwitch-25;
  potMax = potSwitch+50;

  Serial.println((int)photoSensor);
  Serial.println((int)potSwitch);  // pulse the servo again if rhe refresh time (20 ms) have passed:

  if (millis() - lastPulse >= refreshTime) {
    digitalWrite(servoPin, HIGH);   // Turn the motor on
    delayMicroseconds(pulse);       // Length of the pulse sets the motor position
    digitalWrite(servoPin, LOW);    // Turn the motor off
    lastPulse = millis();           // save the time of the last pulse
  }

  //good State
  if(photoSensor <= potMax && photoSensor >= potMin){
    digitalWrite(goodLED, HIGH);
    digitalWrite(darkLED, LOW);
    digitalWrite(brightLED,LOW);
    Serial.println("Light is good");
  }
  // bright State
  if(photoSensor < potMin){
    digitalWrite(goodLED, LOW);
    digitalWrite(darkLED, LOW);
    digitalWrite(brightLED,HIGH);
    Serial.println("Too Bright");
  }

  // dark State
  if(photoSensor > potMax){
    digitalWrite(goodLED, LOW);
    digitalWrite(darkLED, HIGH);
    digitalWrite(brightLED,LOW);
    Serial.println("Too Dark");

  }
}

March 25, 2008

Final Project Proposal

Filed under: Brian Kish — bkish @ 1:43 pm

This is an updated and adapted version of the project that I presented at the midterm.  I hope to continue with my orignal intentions of creating a

‘smart wall’ that is able to change and adapt to its context and provide a better living situation for the occupants.

final-project-proposal.pdf

March 20, 2008

Making Louvers smart!

Filed under: 8: State Machine,Brian Kish — bkish @ 1:31 pm

Please check out the PDF for my State Machine :)

Smart Louver Diagram

March 7, 2008

Automated Window Opener

Filed under: 7: Mid-Term Project,Brian Kish — bkish @ 1:54 am

http://www.youtube.com/watch?v=C_Zslar5zkg

My goal is to created a completely automated wall system that helps to control the temperature in the space. In the long term, I hope also have automated louvers that will be controlled by both light and temperature. Unfortunately, I burned out one of my servos and got a couple from the robotics club. However, I guess they modified them by taking out the potentiometer and restricting pins so the they can continually rotate. It took me a long time to try and get them to move back and forth before I figured out that you couldn’t!

For this portion, I am using a linear actuator to open and close a window (the window is still imaginary). It is controlled by the indoor and outdoor temperature. It three conditions and 2 states:

if ((tempOUT >= 65) && (tempIN >=65)) THEN WINDOW OPEN!! (RED LED)

else if ((tempOUT < 65) && (tempIN < 80)) THEN WINDOW CLOSE!! (BLUE LED)

else if ((tempOUT < 65) && (tempIN >=80)) THEN WINDOW OPEN!! (RED LED)

I used an ice-pack to change the temperature in the sensors to verify that the system worked. It works.

Circuit Diagram:

Circuit Diagram

All the Components:
Components of Project

THE LM35 TEMPERATURE SENSOR:

LM35 Temperature Sensor

/*
Temp sensor code for automated window opener. The sensor used is an amplified LM35.
*/
int tempoutPin = 0; //input read pin for LM35 is Analog Pin 0
int tempinPin = 1; //input read pin for LM35 is Analog Pin 1
float tempIN = 0; //variable which will be calculated in process
float tempOUT = 0; //variable which will be calculated in process
int redLED=5; //Pin5 = Red LED
int blueLED=7; //Pin7 = Blue LED
int greenLED=6; //Pin6 = Green LED
long val=0; //variable to store the value coming from the sensor
int openWINpin = 3; // H-bridge leg 1 set to open window
int closeWINpin = 4; // H-bridge leg 2 set to close window
int speedPin = 9; // H-bridge enable pin

void setup()
{
pinMode(redLED, OUTPUT); //redLED set to output
pinMode(greenLED, OUTPUT); //greenLED set to output
pinMode(blueLED, OUTPUT); //blueLED set to output
pinMode(openWINpin, OUTPUT); //openWINpin set to output
pinMode(closeWINpin, OUTPUT); //closeWINpin set to output
pinMode(speedPin, OUTPUT); //speedPin set to output
pinMode(tempoutPin, INPUT); //tempoutPin set to input
pinMode(tempinPin, INPUT); //tempinPin set to output
Serial.begin(9600); // Stars Serial Communication
digitalWrite(speedPin, HIGH); // sets speed to on for Actuator
}

void loop () //loop below process
{

Serial.println(“Outdoor Temperature is “); //Print “Outdoor Temperature is” every loop
val = analogRead(tempoutPin); //read the value of sensor
tempOUT = (32+9*val*10/1024); //convert voltage to temperature (farenheit)
Serial.println ((long)tempOUT); //print temperature value on serial screen
Serial.println (“Degrees Farenheit”); //Print “Degrees Farenheit” every loop

Serial.println(“Indoor Temperature is “); //Print “Indoor Temperature is” every loop
val = analogRead(tempinPin); //read the value of sensor
tempIN = (32+9*val*10/1024); //convert voltage to temperature
Serial.println ((long)tempIN); //print temperature value on serial screen
Serial.println (“Degrees Farenheit”); //Print “Degrees Farenheit” every loop

if ((tempOUT >= 65) && (tempIN >=65)) //Check if temp over x degrees C.
{
digitalWrite (redLED, HIGH); //If so… turn LED on
digitalWrite (blueLED, LOW); //and this LED off
digitalWrite (greenLED, LOW); //and this LED off
digitalWrite(openWINpin, HIGH); // set leg 1 of the H-bridge low
digitalWrite(closeWINpin, LOW); // set leg 2 of the H-bridge high

}
else if ((tempOUT < 65) && (tempIN >=80)) //if temperature does not meet above requirement but is between Y and Z… do below
{
digitalWrite (redLED, LOW); //turn LED off
digitalWrite (blueLED, HIGH); //turn LED on
digitalWrite (greenLED, LOW); //turn LED off
digitalWrite(openWINpin, HIGH); // set leg 1 of the H-bridge low
digitalWrite(closeWINpin, LOW); // set leg 2 of the H-bridge high
}
else if ((tempOUT < 65) && (tempIN < 80)) //if temperature does not meet above requirement but is between Y and Z... do below { digitalWrite (redLED, LOW); //turn LED off digitalWrite (blueLED, LOW); //turn LED off digitalWrite (greenLED, HIGH); //turn LED on digitalWrite(openWINpin, LOW); // set leg 1 of the H-bridge low digitalWrite(closeWINpin, HIGH); //set leg 2 of the H-bridge high } delay(5000); //wait for 5 seconds } //End of process, go back to start of loop - ie check temp...[/sourcecode]

February 28, 2008

Smart Louvers Proposal

Filed under: 7: Mid-Term Project,Assignments,Brian Kish — bkish @ 2:36 pm

Follow the link to my project :)

Mid-Semester Proposal

~brian

February 26, 2008

Finally got the H-Bridge Working!

Filed under: 6: More Motion,Brian Kish — bkish @ 10:56 am

I have been messing around with a H-bridge to control my linear actuator. The H-bridge switches the negative and positive flows of electricity to be able to change the direction of the actuator. For example, the H-bridge allows me to spin a DC motor in forward and reverse or make the actuator move in or out. Cool stuff.

My initial problem was one of 2 things: 1) There was not a common ground between the arduino and external power source 2) I did not have the correct size capacitor. After I did both of these it worked! Unfortunately, after much excitement, I fried my H-bridge. I accidently let go of the ‘switch wire’ I was using to control it and it contacted the H-Bridge and a lot of smoking and nasty smell ensued. I need to get a new H-bridge ASAP. (the joys of working with 24V DC power!)

I used the ITP tutorial to get this to work:

http://itp.nyu.edu/physcomp/Labs/DCMotorControl

(The schematic and code that I used can be found on in this tutorial)

I also used an old architectural Roboctic handout from Mark:

http://www.architecturalrobotics.org/archrobots_handout3.pdf

H-Bride Controller H-Bridge Schematic

February 12, 2008

Linear Actuator & Computer Fan

Filed under: 5: Making Motion,Brian Kish — bkish @ 2:50 pm

http://www.youtube.com/watch?v=fft-9HAuGLw

This is a very simple project that controls a computer fan and a linear actuator. It is able to turn each device on and off. The linear actuator is supposed to use 24V DC and I do have a 24v Lambda power supply to power it. However, I still am not to good at this and the 24v kind of scares me :) I nearly welded the ground and positive wire together and fried an LED and I think possible one of the servos I borrowed :( Therefore, I am now powering it off of a 9V battery.

The next step I would like to take is to understand how to use an H-Chip or the DC Motor Controller that I borrowed so that I could use it to make the linear actuator go in and out (it only goes in right now). I also attempted to use a servo, but every time I connected, the Arduino just shut off.

/*  This is a simple system that is used to control a computer fan and a linear actuator. It currently is only able to make the actuator retract.
*/
int fanPin = 10;                      //  powers fan
int actuatorPin = 12;                 //  powers actuator
int statusPin = 13;                   //  flashing LED tells when the system is running
int highSpeed = 255;                  //  set the speed to 'maximum'
int lowSpeed = 0;                     //  set speed to 'off'
void setup()
{
pinMode(fanPin, OUTPUT);              //  sets the fanPin as an output
pinMode(statusPin, OUTPUT);           //  sets the status pin to output
pinMode(actuatorPin, OUTPUT);         //  sets the actuatorPin to output
}
void loop()
{
analogWrite(fanPin, highSpeed);      //  tells fan to spin at 'maximum' when on high
analogWrite(actuatorPin, highSpeed); //  telss actuator to move at 'maximum' when turned to high
digitalWrite(statusPin, HIGH);       //  turns status LED on
digitalWrite(actuatorPin, HIGH);     //  turns actuator on
digitalWrite(fanPin, HIGH);          //  turns fanPin on
delay(5000);                         //  waits 0.5 seconds
digitalWrite(statusPin, LOW);        //  turns status LED off
digitalWrite(actuatorPin, LOW);      //  turns actuator off
digitalWrite(fanPin, LOW);           //  turns Fan off
analogWrite(actuatorPin, lowSpeed);  //  tells fan to spin at 'off' when on Low
analogWrite(fanPin,lowSpeed);        //  tells actuator to move at 'off' when turned to low
delay(5000);
}

February 5, 2008

Save Energy: CLOSE THE DOOR ALREADY!

Filed under: 4: Counting Sensor Input,Brian Kish — bkish @ 10:02 pm
This is a project that utilizes a switch to tell whether a door is open or not.   It can be used on a refrigerator door or the exterior door  of your house to help  make sure that you are not wasting too much energy by leaving the door open.  When the switch is open  (meaning the door is open), the blue light starts to  flash faster and faster and it says "Door is open", as you wait longer the   green LED flashes and it says "You should close the door soon", finally the red light  flashes and tells you "CLOSE THE DOOR NOW!!  You are wasting energy".  IF the switch  is depressed (the door is closed), nothing happens and the energy fairy is happy.
Schematic of Wiring

http://www.youtube.com/watch?v=JIuhFRF08JY

/*
 *  Switch and LED test program
 */

int redLED = 9;                 // RedLED is connected to pin 9
int greenLED = 11;                // GreenLED is connected to pin 11
int blueLED = 13;                // BlueLED is connected to pin 13
int switchPin = 2;              // switch is connected to pin 2
int val;                        // variable for reading the pin status
int delayAmount = 1000;          // number of milliseconds to wait

void setup() {
  pinMode(redLED, OUTPUT);      // Set the redLED pin as output
  pinMode(greenLED, OUTPUT);    // Set the blueLED pin as output
  pinMode(blueLED, OUTPUT);     // Set the blueLED pin as output
  pinMode(switchPin, INPUT);    // Set the switch pin as input
}

void loop(){
  val = digitalRead(switchPin);    // read input value and store it in val
  if (val == HIGH) {               // check if the button is pressed
    Serial.begin(9600);
    Serial.println("The Door is Open");
    digitalWrite(blueLED, HIGH);   // turn blue LED on
    delay(1000);
    digitalWrite(blueLED, LOW);   // turn blue LED off
    delay(1000);
    digitalWrite(blueLED, HIGH);  // turn blue LED on
    delay(900);
    digitalWrite(blueLED, LOW);   // turn blue LED off
    delay(900);
    digitalWrite(blueLED, HIGH);  // turn blue LED on
    delay(600);
    digitalWrite(blueLED, LOW);   // turn blue LED off
    delay (600);
    digitalWrite(blueLED, HIGH);  // turn blue LED on
    delay (200);
    digitalWrite(blueLED, LOW);   // turn blue LED off
    delay (200);
    digitalWrite(blueLED, HIGH);  // turn blue LED on
    delay (200);
    digitalWrite(blueLED, LOW);   // turn blue LED off
    delay (200);
    Serial.begin(9600);
    Serial.println("You should close the door soon.");
    digitalWrite(greenLED, HIGH);   // turn green LED on
    delay(1000);
    digitalWrite(greenLED, LOW);   // turn green LED off
    delay(1000);
    digitalWrite(greenLED, HIGH);  // turn green LED on
    delay(900);
    digitalWrite(greenLED, LOW);   // turn green LED off
    delay(900);
    digitalWrite(greenLED, HIGH);  // turn green LED on
    delay(600);
    digitalWrite(greenLED, LOW);   // turn green LED off
    delay (600);
    digitalWrite(greenLED, HIGH);  // turn green LED on
    delay (200);
    digitalWrite(greenLED, LOW);   // turn green LED off
    delay (200);
    digitalWrite(greenLED, HIGH);  // turn green LED on
    delay (200);
    digitalWrite(greenLED, LOW);   // turn green LED off
    delay (200);
    Serial.begin(9600);
    Serial.println("CLOSE THE DOOR NOW!!! You are wasting energy!");
    digitalWrite(redLED, HIGH);   // turn red LED on
    delay(1000);
    digitalWrite(redLED, LOW);   // turn red LED off
    delay(1000);
    digitalWrite(redLED, HIGH);  // turn red LED on
    delay(900);
    digitalWrite(redLED, LOW);   // turn red LED off
    delay(900);
    digitalWrite(redLED, HIGH);  // turn red LED on
    delay(600);
    digitalWrite(redLED, LOW);   // turn red LED off
    delay (600);
    digitalWrite(redLED, HIGH);  // turn red LED on
    delay (200);
    digitalWrite(redLED, LOW);   // turn red LED off
    delay (200);
    digitalWrite(redLED, HIGH);  // turn red LED on
    delay (200);
    digitalWrite(redLED, LOW);   // turn red LED off
    delay (200);
  }
  else (val == LOW); {              // check if the button is not pressed
    digitalWrite(blueLED, LOW);    // turn blue LED off
    digitalWrite(greenLED, LOW);   // turn green LED off
    digitalWrite(redLED, LOW);     // turn red LED off
    Serial.begin(9600);
    Serial.println("The door is currently closed");
  }
  }
Next Page »

Blog at WordPress.com.