Making Things Interactive

March 27, 2008

digital book machine

Filed under: 8: State Machine, Assignments, Nadeem Haidary — nhaidary @ 5:00 pm

Was working better earlier but the tilt switch sometimes refuses to work without me flicking it angrily. This is a concept for a digital book that powers an electronic paper screen with each turn of the page (in this case an LED). Pages are refreshed with a combination of a tilt switch and motor input. The Processing display has been edited out of the video because of inconsistencies. Arduino:

/*
 *   Digital Book Reader
 *   State Machine
 *   Spring 2008
 *
 *   Nadeem Haidary
 */

//LIBRARIES

//GLOBAL VARIABLES
//pins
int motorPin = 0;                   // motor is connected to pin 0
int LEDPin = 9;                     // LED is connected to pin 9
int tiltPin = 8;                    // tilt switch is connected to pin 8

int motorValue;                     // the value read from the motor
int tiltValue;                      // the value read from the tilt switch
int currentTilt;                    // the current tilt value
int previousTilt;                   // the state of the tilt switch
int x = 0;

//---SETUP-------------------------------------------------------------->

void setup() {
  pinMode(motorPin, INPUT);         // Set the motor pin as an input
  pinMode(LEDPin, OUTPUT);          // Set the LED pin as an output
  pinMode(tiltPin, INPUT);          // Set the tilt pin as an input

  //currentTilt = digitalRead(tiltPin);
  previousTilt = digitalRead(tiltPin);

  Serial.begin(9600);               // Start serial communications
}

//---LOOP--------------------------------------------------------------->

void loop(){
  motorValue = analogRead(motorPin);      // Read the motor pin as an analog input
  //Serial.println(motorValue);
  analogWrite(LEDPin, motorValue);

  currentTilt = digitalRead(tiltPin);
  //Serial.println(currentTilt);
  //delay(100);
  //Serial.println(0);

  if (motorValue > 30) {
    Serial.println ("Page" + x);
    //Serial.print(1, BYTE);                   // send 1 to Processing
    previousTilt = currentTilt;
    x++;
  }

  else {                                     // If the switch is not ON,
    //Serial.print(0, BYTE);                   // send 0 to Processing
  }

}

Processing:

/*
 *   Digital Book Reader
 *   State Machine
 *   Spring 2008
 *
 *   Nadeem Haidary
 */

import processing.serial.*;

PFont font;
Serial port;                  // Create object from Serial class
int val;                      // Data received from the serial port
int x = 0;

void setup() {

  size (400, 600);
  background (200);
  fill (0);
  frameRate(10);
  println(Serial.list());                           // Set up the serial communication
  port = new Serial(this, Serial.list()[1], 9600);  // Open the port that the board is connected to (in this case COM4 = [1])
  // and use the same speed (9600 bps)
  font = loadFont("BookAntiqua-BoldItalic-48.vlw");

}
void draw() {
  textFont(font, 48);
  text(x, 100, 100);

  if (0 < port.available()) {                       // If data is available,
    val = port.read();                              // read it and store it in val
  }

  if (val == 1) {
    x++;
    background (200);
  }
}

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");

  }
}

PhotoSensor State Machine

Filed under: Will Not Count Towards Your Grade — bkish @ 1:43 pm

State machine

Filed under: 8: State Machine, Lea — tovelet @ 1:42 pm

I am not very good at this game, actually.

/*
A blinky light game.  Once a player has decided to "participate,"
the LED's blink in turn.  If a player hits the button that corresponds
to the currently lit LED, they gain a point, and the lights cycle slightly
faster.  They can exit the game at any time, and the score and speed
reset for the next player.
*/

int ledOne = 4;
int ledTwo = 7;
int buttonOne = 2;
int buttonTwo = 8;
int participate = 9;
int delayTime = 200;
int answer = 0;      //"right" or "wrong" for any given round
int score = 0;       //score tally, reset at the beginning of the game
int playPrint = 1;   //should it print "Will you play?"

const int sAttract = 0;
const int sQuestion = 1;
const int sIncorrect = 2;
const int sCorrect = 3;

int state = 0;

void setup ()
  {
  pinMode(ledOne, OUTPUT);
  pinMode(ledTwo, OUTPUT);
  pinMode(buttonOne, INPUT);
  pinMode(buttonTwo, INPUT);
  pinMode(participate, INPUT);
  Serial.begin(9600);
  }

void loop ()
  {
switch (state)
{
case sAttract:        //state is attract
  digitalWrite (ledOne, LOW);  //reset LEDs to off
  digitalWrite (ledTwo, LOW);
  if (playPrint == 1)
  {Serial.println("Will you play?");}
  score = 0;          //reset score
  delayTime = 200;    //reset delayTime
  if (digitalRead(participate)==HIGH)
    {state = sQuestion;}
  playPrint = 0;      //only print it once
  break;

case sQuestion:         //state is question:
  Serial.println("Push the lit button.");
  Serial.println();
  if (digitalRead(participate)==LOW)  //check if participate is off
    {
    state = sAttract;
    playPrint = 1;
    }
  answer = cycleLed();       //run the cycling lights, return correct or incorrect
  score = score + answer;    //tally score
  if (answer == 0)
    {state = sIncorrect;}
  if (answer == 1)
    {state = sCorrect;}
  break;

case sIncorrect:      //state is incorrect:
  Serial.println("Wrong.");
  Serial.println("Your score is:");
  Serial.println(score);      //print score
  Serial.println();
  delay (500);
  if (digitalRead(participate)==LOW) //check if participate is off
    {state = sAttract;
     playPrint = 1;}
  else
    {state = sQuestion;}    //return to question state
  break;

case sCorrect:      //state is correct:
  Serial.println("Correct!");
  Serial.println("Your score is:");
  Serial.println(score);
  Serial.println();
  delay (500);
  delayTime = (delayTime - (delayTime/(100-score))); //cycle lights faster next time
  if (delayTime <= 50) {delayTime = 50;}    //do not make it too hard
  if (digitalRead(participate)==LOW)
    {state = sAttract;
     playPrint = 1;}
  else
    {state = sQuestion;}
  break;

default:
  Serial.println ("error"); //this shouldn't happen
  state = sAttract;
  playPrint = 1;
  break;
}
}

int cycleLed ()
 {
    while (true)
    {
    for (int i=0; i<=delayTime; i++)
      {
      digitalWrite(ledOne, HIGH);    //ledOne is on
      digitalWrite(ledTwo, LOW);
      if (digitalRead(participate)==LOW)    //make sure participate is high
        {state = sAttract;
        playPrint = 1;
        return (0);}
      if (digitalRead(buttonOne)==HIGH)
        {return (1);}    //so if buttonOne is pressed, correct
      if (digitalRead(buttonTwo)==HIGH)
        {return (0);}    //and if button Two is pressed, incorrect
      delay(1);
      }
    for (int i=0; i<=delayTime; i++)
      {
      digitalWrite(ledOne, LOW);    //inverse of the other one
      digitalWrite(ledTwo, HIGH);
      if (digitalRead(participate)==LOW)
        {state = sAttract;
        playPrint = 1;
        return (0);}
      if (digitalRead(buttonOne)==HIGH)
        {return (0);}
      if (digitalRead(buttonTwo)==HIGH)
        {return (1);}
       delay(1);
       }
    }
}

State Machine: Light Motor

Filed under: 8: State Machine, Assignments, Thomas Hendrickson — tphendrickson @ 1:06 pm

I created a circuit with a motor that will turn on if the amount of light surrounding it increases. I calibrated a photosensor to accomplish this, which also will help in my final project.

State Diagram:

Circuit Photo:

Code:

 


int motorPin = 4;
int ledPin = 13;
int photoPin = 0;
int readIn = 0;
int initialRead = 0;
int activateVal = 0;

void setup()
{
  Serial.begin(9600);
  pinMode(ledPin, OUTPUT);
  pinMode(motorPin, OUTPUT);
  pinMode(photoPin, INPUT);

  blink();     //blinks the status LED
  initialRead = analogRead(photoPin); //gets initial reading for photosensor
  activateVal = initialRead * 2;      //the activation value will be double the initial
  blink();   

}

void loop()
{
    readIn = analogRead(photoPin);    //gets the current sensor reading

    while (readIn >= activateVal)     //while loop turns on motor and status LED if current reading
    {                                 //is greater than the activation value
      digitalWrite(ledPin, HIGH);
      digitalWrite(motorPin, HIGH);

      readIn = analogRead(photoPin);  //checks the current value
    }

    digitalWrite(ledPin, LOW);        //turns off motor and LED if current value is not great enough
    digitalWrite(motorPin, LOW);

}

void blink()
{
    digitalWrite(ledPin, HIGH);
    delay(1000);
    digitalWrite(ledPin, LOW);
    delay(1000);
}

State Machine Code – Night Table

Filed under: 8: State Machine, Assignments — tyang1 @ 8:02 am

This is the code to follow my state machine schematic.  The three states: off, bright, dim.  The only thing that physically changes is the LED so there was no point in taking a video.   Circuit of State Diagram Monitor outputs for state machine


 

const int sOff = 0;
const int sBright = 1;
const int sDim = 2; 

int photoPin = 1;
int light;
float sens = 0.85;
int val = 0;
int pirPin = 3;
int ledPin = 11;
int buttonPin = 7;

int currentState = sOff;
int nextState = sBright;

void setup() {

  pinMode(photoPin, INPUT);
  pinMode(pirPin, INPUT);
  digitalWrite(pirPin, LOW);
  pinMode(ledPin, OUTPUT);
  pinMode(buttonPin, INPUT);
  Serial.begin(9600);
  val = analogRead(photoPin);
}

void loop() {

  switch (currentState) {
  case sOff:
    Serial.println("off");
    analogWrite(ledPin, 0);
    light = analogRead(photoPin);
    if (light  val*sens) {                        // if ambient light is on...
      currentState = sOff;
    }
    else if (digitalRead(pirPin) == LOW) {
      currentState = sOff;
    }
    else if (digitalRead(pirPin) == HIGH) {
      currentState = sDim;
    }
    break;

  case sDim:
    Serial.println("dim");
    analogWrite(ledPin, 100);
    if (light > val*sens) {
      currentState = sOff;
    }
    else if (digitalRead(buttonPin) == HIGH) {
      currentState = sBright;
    }
    break;

  default:
    currentState = sOff;
    nextState = sBright;
    break;
  }
}

Boomboxes: State Machine

Filed under: 8: State Machine, Assignments, Jesse Chorng — Jesse @ 5:24 am
Tags:

For assignment 8b, I created a state machine that I will work on for the next two weeks to improve for the final project. In this one, there are three states: Listening, Audio Detected, and Party (or dancing lights).  Using a stereo input, the Arduino waits for an incoming signal. Once an audio source is connected and playing music, the Arduino detects it and changes states. Here’s the code:

/*
Boomboxes - Social Interaction Through Music
Small Undergraduate Research Grant

Jesse Chorng

*/

const int sListening = 0;          // The system is waiting for audio to be plugged in. Speakers/Lights are off
const int sAudioDetected = 1;      // The system detects audio being played. Speakers/Lights are on
const int sParty = 3;              // If there's enough people around, party time! Lights dance to music

int currentState = sListening;
int nextState = sAudioDetected;

int audioPin = 1;                  // Audio signal in from stereo jack
int partySwitch = 2;               // Push button to activate 'party' state

int listeningLed = 9;              // LED to signal 'listening' state
int detectedLed = 10;              // LED to signal audio signal detected; 'detected' state
int partyLed = 12;                 // LEDs start to pulse with music, 'party' state. IC3915 activated

int audioLevel = 0;                // Incoming audio level

void setup()  {

    pinMode(audioPin, INPUT);
    pinMode(partySwitch, INPUT);
    pinMode(listeningLed, OUTPUT);
    pinMode(detectedLed, OUTPUT);
    pinMode(partyLed, OUTPUT);
    Serial.begin(9600);

}

void loop()  {

    //digitalWrite(partyLed, HIGH);
    //AudioLevelCheck();
    //Serial.println(audioLevel);

    switch(currentState) {
       case sListening:                                // Listening State
           digitalWrite(listeningLed, HIGH);           // Listening LED on
           digitalWrite(detectedLed, LOW);
           digitalWrite(partyLed, LOW);
           AudioLevelCheck();                          // Check incoming audio level
           if (audioLevel > 1) {                       // If there is incoming audio, move to 'detected' state
             currentState = sAudioDetected;
           }
           break;

       case sAudioDetected:                            // Audio Detected State
           digitalWrite(detectedLed, HIGH);            // Audio Detected LED on
           digitalWrite(listeningLed, LOW);
           digitalWrite(partyLed, LOW);
           AudioLevelCheck();                          // Check incoming audio level
           if (audioLevel = 500) {       // If push button pressed, go to 'party' state
             currentState = sParty;
           }
           break;

       case sParty:                                    // Party State
           digitalWrite(partyLed, HIGH);               // Party LEDs (motion) on
           digitalWrite(listeningLed, LOW);
           digitalWrite(detectedLed, LOW);
           AudioLevelCheck();
           if (audioLevel < 1) {                       // Return to 'listening' state if no audio
             currentState = sListening;
           }
           if (analogRead(partySwitch) <= 500) {       // Return to 'detected' state if no pushbutton
             currentState = sAudioDetected;
           }
           break;

       default:                                        // Default Case aka Error Case
           Serial.println("ERROR: default state");
           currentState = sListening;                  // Reset back to 'listening' state
           nextState = sAudioDetected;
           break; 

    }
}

void AudioLevelCheck()  {                              // Checks incoming Audio Level by taking
    int count = 0;                                     // 5 input values in 1 second intervals
    for (int i = 0; i < 5; i++)  {                     // then takes the average.
         count += analogRead(audioPin);
         delay(1000);
    }
    audioLevel = count / 5;                            // Audio Level stores the average
}

 

For the final, I hope to replace the pushbutton with sensors that will detect activity. The Arduino will then sense how many people are using Boomboxes and interact by dancing lights when more people are around and/or moving. 

light-aiming turret [related work]

Filed under: Final Project, Gaku Sato — ponkotsu @ 2:36 am

TECHNOLOGY

Light-Tracking Wheel
<http://www.youtube.com/watch?v=Y5qi711PRbI>
<http://www.physicsforums.com/showthread.php?p=1659156>
The basic control scheme for this device is the same as that intended for the turret control.  It rotates the wheel in the direction of the photosensor with the higher reading.  The movement is unfortunately very twitchy, and aside from the obvious reasons, it may be due to the large light source.

Sunlight-Tracking System
<http://www.wipo.int/pctdb/en/wo.jsp?wo=2006131028>
This system tracks sunlight in a similar fashion (by analyzing the difference between two separately located sensors).  It addresses the issue of having an incredibly large light source (the sun) is by filtering the light through a “microhole”.

Fuzzy Logic Light Tracker
<http://books.google.com/books?id=m8eVNWGnt5YC&pg=PA130&lpg=PA130&dq=light-tracker&source=web&ots=ItpZCLviYR&sig=L3CG8S0FvgupBvb0mkkeYz5FcXg&hl=en#PPA131,M1>
This is a device that accurately aims at light albeit in a narrow range with an ingenious light-blocking vane between the input sensors to exaggerate the light difference.

Optical Guidance System
<http://www.patentstorm.us/patents/6629028.html>
still decyphering…

Laserpointer-Tracking Program
<http://www.wipo.org/pctdb/en/wo.jsp?wo=2006085580>
still decyphering…
ENTERTAINMENT

Airsoft RC Tank
<http://www.hobbytron.com/AirsoftRCType90BattleTank.html>
320° turret (20° height) mounted on RC airsoft tank with 25m firing range and accurate 1/24-scale design!!

USB Missile Launcher
<http://www.thinkgeek.com/geektoys/warfare/8bc4/>
This is a stationary 180° turret (45° height) controlled by a computer via USB.

Filed under: Will Not Count Towards Your Grade — sbutalia @ 1:46 am

for my state machine, I created something which would help me in my final term project. It is very simple but i managed to take in 3 different inputs (light, temp & play) and then determine what they would output. There are 3 basic states visualized, Decreasing, Increasing and Equilibrium.


int Light = 0; //light intensity
int Temp = 0;  //temperature level
int Switch = 0;//current Switch state
int Switch2 = 0;// Previous switch state
int State = 0;  //Play or not Play
int PlayCount = 0; //Amount of Play
int LightCount = 0; //Amount of Light
int TempCount = 0; //Amount of Temperature
int Emotion = 0; //Current Amount of Emotion
int Emotion2 = 0;//Previous amount of Emotion

void setup() {

  pinMode(2, INPUT);
  pinMode(8, OUTPUT);
  pinMode(9,OUTPUT);
  pinMode(10, OUTPUT);

  Serial.begin(9600);          

 }

void loop(){

  Light = analogRead(5);
  Temp = analogRead(4);
  Switch2 = Switch;        //Assigning past value
  Switch = digitalRead(2); //Assigning new value

  if(Switch != Switch2 && Switch == HIGH){ //Determining & Assigning new switch state
   if(State == 1){
     State = 0;}
     else State = 1;
  } 

  if(State == 1){         //Accumulating Play
    digitalWrite(8,HIGH);
    PlayCount++;
  }
  else {PlayCount = PlayCount - 1; // Reducing Play
  digitalWrite(8,LOW);
  }

  if(Light > 512)  //Accumulating Light
  {
    LightCount++;
  }else LightCount = LightCount - 1; // Reducing Light

  if(Temp > 512) //Accumulating Temp
  {
    TempCount++;
  }
  else TempCount = TempCount - 1; //Reducing Temp

  Emotion2 = Emotion; //Previous emotion value
  Emotion = LightCount/2 + TempCount/2 + PlayCount; //Current Emotion value

  if(Emotion > Emotion2){
    digitalWrite(10,HIGH);
    digitalWrite(9,LOW);
    Serial.println("Increasing");
  }
  if(Emotion < Emotion2){
    digitalWrite(9,HIGH);
    digitalWrite(10,LOW);
    Serial.println("Decreasing");
  }
  if(Emotion == Emotion2){
    digitalWrite(9,HIGH);
    digitalWrite(10,HIGH);
    Serial.println("Equilibrium");
  }

  //Serial.print(LightCount/10);
  //Serial.print(":");
  //Serial.print(TempCount/10);
  //Serial.print(":");
  //Serial.println(PlayCount/10);

}
Next Page »

Blog at WordPress.com.