Exercise 02 – R.L.D.M.D.

Real Life Dramatic Moment Device

Abstract: This device dramatizes the everyday life with your own choice of soundtrack!

Why: Why not? We deserve to live life in silver-screen quotations.

Use: Whenever and wherever appropriate and inappropriate.


Schematic:

untitled-2

Arduino code:

————————————————————————————–

int sensor = 0; //IR read-in pin :: analogue
int pinOut = 7; //relay-control pin  :: digital
int counter = 0;
int play_time = 1500;
int add_num_reading = 14;
int delay_rate = 300; //1/3 of a second :: 10/30 frames

int lowEnd = 280; //the low end of the proximity reading
int highEnd = 1100; //the high end of the proximity reading

void setup()
{
pinMode(pinOut, OUTPUT);
}

void loop()
{
int val = 0;

val = readVal(sensor);

//the following condition forces the target to be in porximity for a set amount of time
if(isValid(val))
{
counter++;
}
else
{
if(counter>0)
{
counter–;
}
}
delay(300); //wait 1/3 of a second :: 10/30 frames to initialize another sampling

if(counter>6) //make sure the object is in proximity for some duration; avoid passing objects
{
digitalWrite(pinOut, HIGH); //turn on iPod
delay(play_time); //leave the iPod on for the durration of play_time
if(!isValid(readVal(sensor)))
{
counter = 0; //reset counter
digitalWrite(pinOut, LOW);//turn off iPod
}
}
}

int readVal(int sensorNum) //mass sampling function
{
int readVal;
readVal = analogRead(sensorNum); //initial reading

for(int i=0;i<add_num_reading;i++) //addtional number of samplings
{
readVal += analogRead(sensorNum);
}

return (readVal/add_num_reading+1); //return the average of (the initial readi + additiona; readings) :: smooth out noise
}

boolean isValid(int input) //this function verifies whether of not an object is in proximity
{
if(input>lowEnd && input<highEnd)
{
return true;
}
else
{
return false;
}
}

Advertisements

Sock Puppet

For this project I used a bend sensor to read the state of a sock puppet’s “mouth” and turn a motor accordingly to produce an acoustic noise to act as it’s voice.


/*
* Flex Sensor Puppet
*
* based on:
* AnalogInput by DojoDave
*
*
* http://www.arduino.cc/en/Tutorial/AnalogInput
*/

#define NUM_FLEX_READINGS 15

int flexPin = 2; // the analog input pin for the flex sensor
int gLEDPin = 3; // the pin for the green LED
int yLEDPin = 5; // the pin for the yellow LED

int motorPin = 6; // the pin for the transistor that activates the motor

int flexReadings[NUM_FLEX_READINGS];
int currentReadingIndex = 0;
int flexReadingsSum = 0;

int flexVal = 0; // variable to store the value coming from the flex sensor
int flexMin = 1019; // minimum flex sensor value
int flexMax = 1022; // maximum flex sensor value

void setup(){
pinMode(gLEDPin, OUTPUT); // declare the gLEDPin as an OUTPUT
pinMode(yLEDPin, OUTPUT); // declare the yLEDPin as an OUTPUT
pinMode(motorPin, OUTPUT); // declare the motorPin as an OUTPUT

for(int k=0; k< NUM_FLEX_READINGS; k++){
flexReadings[k] = 0; // init the flexReadings to 0;
}

digitalWrite(motorPin, LOW); // set the motor to off

//Serial.begin(9600); // begin serial communication via port 9600;
}

void loop(){
flexReadingsSum -= flexReadings[currentReadingIndex];
flexReadings[currentReadingIndex] = analogRead(flexPin); // read the value from the flex sensor
flexReadingsSum += flexReadings[currentReadingIndex];
currentReadingIndex++;

currentReadingIndex %= NUM_FLEX_READINGS;

flexVal = flexReadingsSum / NUM_FLEX_READINGS;

//Serial.println(flexVal); // print out the raw value of the flex sensor

flexVal = map(flexVal, flexMin, flexMax, 0, 255); // remap the flex value
flexVal = constrain(flexVal, 0, 255);

digitalWrite(gLEDPin, flexVal); // turn the gLEDPin on to represent the value
digitalWrite(yLEDPin, 255 - flexVal); // turn the yLEDPin on to represent the inverse

 

digitalWrite(motorPin, 255-flexVal); // turn on the motor proportional to the flex
}

Light sensitive bag

This is a light sensitive bag that beeps when the amount of light is higher than the declared threshold. If the light is closer to the sensor it displays a faster sound(beeps). If the light source is far from the sensor it displays a slower sequence of beeps.
This may be useful if you want to carry light sensitive stuff in your bag.

Basically I used a simple circuit with a Piezzo working as a beeper and a light sensor to measure the amount of light.

 

 

CODE

//Nuno Laginha
//MTI Fall 2008int switchPin = 2;          //switch connected on analog pin 2
int knockPin = 11;          //switch connected on analog pin 11
int val = 0;void setup()                    
{
    pinMode(knockPin, OUTPUT);
    Serial.begin(9600);       //set speed
}

void loop()                 //run over and over again
{
  
    
  val = analogRead(switchPin);//reads voltage value
  
  val = val / 4;
  
  if(val<80){              //if current value higher than 80 (threshold)

  analogWrite(knockPin, 0); //don’t beep
  }else{
  analogWrite(knockPin, val); //beep accordingly with the voltage
  delay(val); //set delay equal to actual voltage
  analogWrite(knockPin, 0);
  delay(val);
  analogWrite(knockPin, val);
  delay(val);
  analogWrite(knockPin, 0);
  delay(val);
  analogWrite(knockPin, val);
  delay(val);
  analogWrite(knockPin, 0);
  delay(val);
  }
    
  Serial.println(val);            //prints voltage value

}

Paparazzi Status-Quo

      

 

Idea: The idea here is to have a meter for how “hot” you are to all those photographers outside the club, the circuit I used was similar to the party underwear project, but the code is completely different. Ambient Light controls the speed of which the LED blinks, the dimmer the ambient light is, the faster it blinks. Also we keep a state record, if you get flashed by a camera your status-quo is increased and the intensity of the LED will become higher , Indicating everyone inside the club that you are tonights “hotshot”

 

Circuit:

 

Code:

 

 

 

int sensPin = 2;    // input pin for the LDR

int ledPin = 11;   // output pin for LEDs

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

int photos=0;

int lightPow=20;

void setup() {

  pinMode(ledPin, OUTPUT);  // declare the ledPin as an OUTPUT

  Serial.begin(9600);

}

 

void loop() {

  //delayTime=2000-(photos*100);

  

  ambientLight = analogRead(sensPin);    // //How bright is it outside

  Serial.println(ambientLight);

 if(ambientLight>600){                 // You got photographed

      lightPow=lightPow+10;

  }

  analogWrite(ledPin, lightPow);   

  delay( ambientLight*2 );   //Blink Blink

  analogWrite(ledPin, 0);

  delay( ambientLight*2 );

}

Sunburn warning indicator

As someone with fair skin who is prone to sunburns, I would benefit from an early warning system which reminded me when I had spent too much time in the sun. This prototype simply increments a counter at a rate proportional to the light level reported by the photo sensor, then triggers a warning when the counter exceeds a preset level. A two-color LED is used to display the current light level as a range of blue (low light) to red (bright light).

Planned improvements include:

  • light level floor (no exposure is registered when you are inside)
  • UV-only filter (more accurate measurement of sunlight)
  • adjustable sensitivity (for different skin types)
  • multi-level warning indicator (green/yellow/red)
  • sunscreen mode: sensitivity is divided by the SPF for a few hours
  • decrement the counter when user is out of the sun for a while
  • embed it in a wearable object, such as a pendant

The wiring schematic is quite simple: the analog input is driven by a voltage divider using a 1kOhm resistor to +5V and a photo sensor to ground. Two PWM “analog” outputs power the 2-color LED (blue/red in this case). The red warning LED is powered by a digital output.

 

One red LED and one bi-color LED are used as indicators, while a photo-sensitive resistor is the input.

One red LED and one bi-color LED are used as indicators, while a photo-sensitive resistor provides input.

Arduino Code

The code is fairly straightforward: calculate the resistance of the photo resistor using the voltage measurement at the voltage divider, use that to scale the red/blue LED. Add the light level to the exposure counter and set off the warning light if exposure exceeds the threshold.

 

/*
sunburn warning
A photo-resistor is used to detect bright-light situations,
and a bi-color LED indicates the level of light detected.
Once the cumulative light exposure passes a set threshold,
a red warning LED is lit.

*/

int photoPin = 5; // the photo resistor
int ledPinRed = 5; // the red half of the LED
int ledPinBlue = 6; // the blue half of the LED
int ledPinWarn = 7; // the red warning LED
int lightLevel; // used to store the current level of light sensed
int lightAccum = 0; // the accumulated light counter
int maxLightAccum = 20000; // the warning threshold for the accumulated light counter
// note that to convert this number to a useful unit like lumen-seconds it is necessary to consider the delay (currently 0.01 sec)
int ledLevelRed; // level to set the red portion of the bi-color LED
int ledLevelBlue; // level to set the blue portion of the bi-color LED
int blinkRate; // not used; early concept was to communicate warning through speed of blinking
int vIn = 5; // voltage on V+ rail; used to scale the photo resistor reading
int rBridge = 10000; // rating of the voltage bridge resistor in Ohms
int rPhoto; // calculated resistance of the photo resistor at each cycle

void setup(){
pinMode(ledPinWarn, OUTPUT);
Serial.begin(9600);
}

void loop(){
/*
measure light level
*/
lightLevel = analogRead(photoPin); // get the current voltage at the voltage divider, over a range of 0-1023
rPhoto = rBridge * ((vIn / lightLevel) - 1); // calculated resistance of photo resistor
Serial.print("light level: ");
Serial.print(lightLevel);
// Serial.print(" = r of ");
// Serial.println(rPhoto);
/*
set bi-color LED levels
*/
ledLevelRed = map(lightLevel, 1023, 0, 0, 254); // red gets brighter as light level increases; note that resistance decreases as light level increases
ledLevelBlue = map(lightLevel, 1023, 0, 254, 0); // blue gets dimmer as light level increases; note that resistance decreases as light level increases
Serial.print(" led level Red: ");
Serial.print(ledLevelRed);
Serial.print(" led level Blue: ");
Serial.print(ledLevelBlue);
analogWrite(ledPinRed, ledLevelRed);
analogWrite(ledPinBlue, ledLevelBlue);
/*
update accumlated light exposure
*/
lightAccum = lightAccum + (ledLevelRed);
Serial.print(" light accum: ");
Serial.println(lightAccum);
/*
set off warning light if exposure level is exceeded
*/
if (lightAccum > maxLightAccum){
digitalWrite(ledPinWarn, HIGH);
}
delay(10);
}

Blinking Monkey

My project involved a monkey doll and detecting how close someone is. The biggest problem I had was getting the infrared proximity to get correct readings (which I couldn’t get working in time), and opted out to using a potentiameter as a replacement. Please assume I used a proximity sensor when reading the description below.

The monkey had a set of LED’s, three rows where each row had different color, in the front.

If someone is very far away, the LEDs would fade in and out. Once someone is closer, each row of LEDs would blink alternatively but at a faster rate as someone gets closer. Once someone is very close, all the LEDs would all blink together (at a faster rate as someone gets closer).

Video demo

http://www.vimeo.com/1810723

Code

/*
* AnalogInput
* by DojoDave <http://www.0j0.org&gt;
*
* Turns on and off a light emitting diode(LED) connected to digital
* pin 13. The amount of time the LED will be on and off depends on
* the value obtained by analogRead(). In the easiest case we connect
* a potentiometer to analog pin 2.
*
* http://www.arduino.cc/en/Tutorial/AnalogInput
*/

int potPin = 2;    // select the input pin for the potentiometer
int ledPin = 9;   // select the pin for the LED
int ledPin2 = 10;   // select the pin for the LED
int ledPin3 = 11;   // select the pin for the LED

int val = 0;       // variable to store the value coming from the sensor
int value = 0;
void setup() {
Serial.begin(9600);
pinMode(ledPin, OUTPUT);  // declare the ledPin as an OUTPUT
pinMode(ledPin2, OUTPUT);  // declare the ledPin as an OUTPUT
pinMode(ledPin3, OUTPUT);  // declare the ledPin as an OUTPUT
}

void loop() {
val = analogRead(potPin);    // read the value from the sensor
Serial.print(val);
Serial.print(“\n”);

if (val > 500) {
for(value = 0 ; value <= 100; value+=5) // fade in (from min to max)
{
analogWrite(ledPin, value);           // sets the value (range from 0 to 255)
analogWrite(ledPin2, value);           // sets the value (range from 0 to 255)
analogWrite(ledPin3, value);           // sets the value (range from 0 to 255)
delay(50);                            // waits for 30 milli seconds to see the dimming effect
}
for(value = 100; value >=0; value-=5)   // fade out (from max to min)
{
analogWrite(ledPin, value);
analogWrite(ledPin2, value);
analogWrite(ledPin3, value);
delay(50);
}
}

else if (val < 200) {
digitalWrite(ledPin, HIGH);  // turn the ledPin on
digitalWrite(ledPin2, HIGH);  // turn the ledPin on
digitalWrite(ledPin3, HIGH);  // turn the ledPin on
delay(val);                  // stop the program for some time

digitalWrite(ledPin3, LOW);   // turn the ledPin off
digitalWrite(ledPin2, LOW);   // turn the ledPin off
digitalWrite(ledPin, LOW);   // turn the ledPin off
delay(val);                  // stop the program for some time

}
else {
digitalWrite(ledPin, HIGH);  // turn the ledPin on
delay(val);                  // stop the program for some time
digitalWrite(ledPin2, HIGH);  // turn the ledPin on
delay(val);                  // stop the program for some time
digitalWrite(ledPin3, HIGH);  // turn the ledPin on
delay(val);                  // stop the program for some time

digitalWrite(ledPin3, LOW);   // turn the ledPin off
delay(val);                  // stop the program for some time
digitalWrite(ledPin2, LOW);   // turn the ledPin off
delay(val);                  // stop the program for some time
digitalWrite(ledPin, LOW);   // turn the ledPin off
delay(val);                  // stop the program for some time
}
}

Handshake Gloves

I created a pair of gloves to help people keep their handshakes at a low enough pressure not to hurt people.  there is a small pressure sensor in the right glove between the thumb and forefinger.  The left glove has a dual color LED and a small motor which vibrates.  As the pressure increases on the right hand, the motor vibration increases on the left hand proportionally.  Once the pressure goes over the amount which is considered too high, the motor vibration hits the max.

The LED is used to show the state over time of the person’s handshakes.  It will be green if more than half of the last 6 handshakes have been “good” (not too strong).  It will be red if half or more of the last handshakes have been “bad” (too strong).

In making the pressure sensor, I ended up having to use a timer to delay measuring the pressure when the person started and stopped squeezing.  This was because the pressure sensor was noisy and would jump back and forth across the threshold I had setup, resulting in multiple “handshakes” being recorded even though only one had actually occurred.

code