Wednesday, July 20, 2011

Stupid Pet Trick

So, I finished my midterm, the "stupid pet trick", and well before 2 am to boot! With the exception of the LED face not working 100% like I wanted it to, it all came together relatively easily.

The "sleepy robot" is now the "peaceful robot", it just seems more fitting. The robot basically just displays a peaceful, happy face when left undisturbed, but when a light is shined in its face or the surface it is on is disturbed, its face changes to a slightly alarmed look and it shakes its head repeatedly. Then after a few seconds of inactivity it shuts off.

Note: the adjectives peaceful, happy and alarmed are used loosely. Its just a few LEDs for eyes and a mouth so Im not exactly on the cutting edge of artificial emotion.





The code for the robot is below. The alarmed look and head shake routine was really simple so I didnt even bother using any for loops to create the motion. I am, however, kind of proud of the initial calibration feature you can see it the void setup area. After you turn it on, the program waits for 3 seconds for you to close the back of the robot and step away so it can take a baseline reading of the ambient light without casting your own shadow over it, then it uses a specified value as a threshold to determine what constitutes "light in my face". I didnt put in a calibration step for the piezo because it wasnt as sensitive as the photoresistor so it wouldnt have been worth it. One cool feature to add later: an analog input to increase or decrease sensitivity of the robot on the fly.



#include //loads servo library

Servo neck; //creates servo object to control a servo

int onLedPin = 2;
int happyLedPin = 3;
int sadLedPin = 4;
int ldrPin = 0;
int ldrBaseline = 0; //sets ambient ldr value
int ldrThreshold = 100; //sets threshold for activation
int piezoPin = 1;
int piezo = 0; //stores piezo value
int inactivity = 5000; //time inactive before going to sleep
int neckDelay = 300; //delay between neck movements
int neckNeutral = 90; //sets neutral position for neck servo
int neckLeft = 45;
int neckRight = 135;


void setup() {
neck.attach(9); //attaches servo to pin 9
pinMode(onLedPin, OUTPUT);
pinMode(happyLedPin, OUTPUT);
pinMode(sadLedPin, OUTPUT);
delay(3000);
ldrBaseline = analogRead(ldrPin); //sets ambient ldr value
neck.write(neckNeutral); //sets head to neutral position

}

void loop() {
digitalWrite(sadLedPin, LOW); //makes sure sad face is off
digitalWrite(onLedPin, HIGH); //Sets sleepy state
digitalWrite(happyLedPin, HIGH);
piezo = analogRead(piezoPin); //reads piezo and assigns value to variable

Serial.println(piezo);

if((piezo > 100) || (analogRead(ldrPin) > ldrBaseline + ldrThreshold)){ //if ldr or piezo are activated, activate wake up sequence
delay(500);
digitalWrite(happyLedPin, LOW); //turns off happy face, sets neutral face
digitalWrite(sadLedPin, HIGH); //turns on sad face
neck.write(neckRight); //begins shaking of head to one direction
delay(neckDelay);
neck.write(neckLeft); //moves head to other direction
delay(neckDelay);
neck.write(neckRight);
delay(neckDelay);
neck.write(neckLeft);
delay(neckDelay);
neck.write(neckRight);
delay(neckDelay);
neck.write(neckLeft);
delay(neckDelay);
neck.write(neckRight);
delay(neckDelay);
neck.write(neckLeft);
delay(neckDelay);
neck.write(neckNeutral); //returns head to neutral position
delay(500);
delay(inactivity); //waits predetermined amount of time
} //returns to begining to fall asleep
}

Thursday, July 14, 2011

Calibration! Of course!

So, I was just rooting around the arduino website looking for ideas and cool new commands when I found this page: http://arduino.cc/en/Tutorial/Calibration


I totally could've used this in the last assignment with the glove. The flex sensor was a little tough to get consistent results because changing the bend slightly drastically affects the values it sends out. What I couldve done was calibrate the sensor when the sketch runs initially (or after a button press) then map those calibrated values to the sensor.

Now I know...

Tuesday, July 12, 2011

Homework for Class #2

Here it is, I wired together a circle of LEDs and had them illuminate in sequence to make it look like the light was travelling around the circle. Then I wired some analog inputs (one flex sensor and two pressure sensors) into a glove and had them control certain features of the lights. See below




With regards to me "dream project"... I dont know if it counts as a dream project since Im actually in the process of making it, but the project has been in my head for over a year now so Im gonna go ahead and say that it counts. By the way, major nerdiness is about to ensue, so try not to judge and if you must, save the wedgies till after class.

Last year I was inspired by my brother a big comic book nerd (and coincidentally a comic book artist) and was thinking of one of my favorite comic book characters and wondered why no one had attempted to make a realistic costume of Archangel, the big metal winged version of the X-man. So, I took it upon my self to be the first one to do it. However, the more I thought of it the more I wanted to trick out these 6-8 foot metal wings. I've started cutting the aluminum that they will be made out of but havent quite gotten to the fun stuff, the stuff that is actually making me list this project here as my ITP assignment: sensors and actuation.

The wings are going to be powered by this really amazing material I found called shape memory alloy. Its a very thin wire made of nickel and titanium that will actually contract in length much like our muscles. All you have to do is heat them electrically and you have muscle wire! You can kind of see it here: http://www.youtube.com/watch?v=3-coGuDTb-Y

As for the sensor side I was always fascinated by the fact that the character had such a strong connection with his wings. They would even drive him to do things with a mind of their own. So, I'd like to hack into a heart rate monitor and use the beating of my own heart to trigger the electrical pulses that will cause the muscles wires to make the wings flap. Aside from getting a brainwave sensor, I think using my actual heart rate to trigger the wing flapping is about as strong as a human connection can get.

I might add even more sensory inputs, but my goal is to have them ready to present at World Maker Faire this september. I'll try to bring in a sample of the muscle wire and a scale model I made of what the wings will look like.

Sensor Walk

Just around my house there are a lot of different sensors, but most of them are the typical on/off or trim pots. Light switchers are a simple switch, but the dimmers are like the ones potentiometers we used in class except linear rather than rotational. My roommate's antique stereo is complete with giant volume knobs that are even more similar to the rotational potentiometers. I guess that same stereo has a magnetic sensor that allows it to read the magnetic tape from old cassettes. Come to think along those same lines, the DVD player has a light sensor that it uses to pick up the laser light that bounces off the DVD itself. The camera that connects to the PS3 is a type of light sensor as well, albeit a more sophisticated one.

Moving on to the kitchen there are pushbutton switches on the microwave and the dishwasher and a nice little temperature sensor inside the oven. I would imagine the fridge has a temperature sensor as well, not to mention that tricky little switch that always manages to keep us entertained by flipping the light on and off when we open and close the door. The reptile tank in the corner has a different kind of temperature sensor that uses infrared light rather than heat thats conducted directly onto it. The capacitive touch sensor on my phone is pretty swell.

Hmm, I think that might be all the interesting ones.

Wednesday, July 6, 2011

Homework Assignment #1

Pendulum Switch: every time the pendulum makes contact with the metal brush at the bottom it triggers the LEDs to switch from one side to the other.



Success!!!

I fixed the bouncing issue! I read a tutorial online that helped me figure it out, but I had to modify their method because theirs wasn't actually debouncing, though it the method seemed to make sense. I used the following code:

void loop() {
    switchState=digitalRead(switchPin);
    delay(10);
    switchState2=digitalRead(switchPin);
   
    if(switchState != switchState2){
        if(switchState==1){
        ledState = 1 - ledState;
        } 
           
        if(ledState==0){
            digitalWrite(yellowLed,HIGH);
            digitalWrite(redLed,LOW);
        }else{
            digitalWrite(yellowLed,LOW);
            digitalWrite(redLed,HIGH);
        }
    }

So there are two variables for the state of the switch: switchState and switchState2. By storing both of them 10 milliseconds apart and comparing them, you can kind of ignore those erratic few milliseconds where the current is bouncing around from 0 to 1. The tutorial I found suggested comparing them to make sure they were the same (i.e. if(switchState==switchstate2)...), but that really didnt work very well, so I altered the if statement to allow the rest of the LED switching code to run only if the two switchState values were different. This results in the LED state changing only when the program finds a 10 millisecond period where it starts as one switchState and ends as another. Functionally, this means that the led switches from red to yellow or yellow to red (and stays that way until the next button press) only when you release the button after pressing it.

Now that I've proved the concept using just the push button on the breadboard I can try incorporating the pendulum switch I was thinking about before. I'll post a pic if I get a chance.

P.S. I hope the stuff I wrote makes sense, its kind of hard to describe code verbally. I'm not even sure if I can explain things 100% correctly.

Debouncing.

Argh. So, I've run into debouncing problems before but this one just isnt going away. Debouncing happens when you flip a crappy mechanical switch. In the brief instant that you perceive as a single button press, the current jumps from high to low (or 1 to 0) a bunch of times confusing your program since it doesnt know if its on or off. This means that when you try to press a button to switch an LED on and make it stay on after you release the button, you only get that outcome by chance since the program sees the button as switching back and forth multiple times.

Im working on making a pendulum that will swing past a metal brush, thus closing the circuit. I want to design it so that just the single contact with the metal brush causes it to flip from one LED to another, but the bouncing issue doesnt allow it to switch consistently. I'm sure I'm just being impatient and that Scott will cover it in class, but I like trying to figure it out on my own. Back to work now.

Tuesday, July 5, 2011

First Blog Post. Ever.

Just started classes at ITP @ NYU. Not as a full time student, unfortunately, but as a casual summer student. One of the first assignments was to create a blog and distribute a link to said blog to the rest of the class. Not something I would normally do on my own, but its probably a good career move to make one, so here it is.

I'll be taking two classes this summer, "intro to physical computing" and "live image processing and performance", both of which sound thoroughly amazing if not slightly intimidating. Will be posting more of my work soon.