Hey guys, here’s a link of an analog sensor average code from ITP’s PhyComp website
[One Sensor Avg]
Updates from October, 2008 Toggle Comment Threads | Keyboard Shortcuts
Hey guys, here’s a link of an analog sensor average code from ITP’s PhyComp website
I tried Matt’s code and it worked well, but what you see in the video is my less sophisticated code at work which you can see here:
int irPin = 3; // IR sensor is read from pin 3
int irVal = 0; // hold the values read from the IR sensor
int orngPin = 9; // Orange LED, connected to digital pin 9
int bluPin = 10; // Blue LED, connected to digital pin 10
int grnPin = 11; // Green LED, connected to digital pin 11
pinMode(orngPin, OUTPUT); // sets the pins as output
Serial.begin(9600); //see what the heck my IR sensor is reading
// Main program
irVal = analogRead(irPin);
if (irVal>=200) //when you’re closest to the sensor
else if (irVal>= 75 && irVal<=200) //middle range of sensor
else if (irVal<75) //when you’re the furthest away
I didn’t use the average code, actually I didn’t know there’s an average code until Yury mentioned about it.
Somehow my LEDs wouldn’t flicker a lot.
So here is my code. It is quite simple.
Basically I just change the on and off status of each LED in different ranges.
*New Arduino hooked-up to 3 different Super-Bright LEDs.
*Program the 3 LEDs to turn on/off individually depending on distance of hand.
*Tzumei M. Hsiao
// Analog pin settings
int irIn = 3; // the IR sensor connected to the analog pin 3
// Digital pin settings
int redLED = 9; // LEDs connected to digital pins 9, 10 and 11
int blueLED = 10; // (Connect cathodes to digital ground)
int greenLED = 11;
int irVal = 0; // the variable to store the input from the IR sensor
int redVal = 0; // the variable to store the value of red LED
int greenVal = 0; // the variable to store the value of green LED
int blueVal = 0; // the variable to store the value of blue LED
// Variables for comparing values between loops
int i = 0; // Loop counter
int wait = (1000); // Delay between most recent pot adjustment and output
int sens = 3; // Sensitivity threshold, to prevent small changes in
// IR sensor values from triggering false reporting
int PRINT = 1; // Set to 1 to output values
pinMode(redLED, OUTPUT); // sets the digital pins as output
Serial.begin(9600); // Open serial communication for reporting
i += 1; // Count loop
irVal = analogRead(irIn); // read input pins, convert to 0-255 scale
if (irVal < 300)//if (irVal<341)
}//end of if
else if (irVal< 600)//else if (irVal< 682)
}//end of else if
}//end of else
analogWrite(redLED, redVal); // Send the new value to LEDs
if (i % wait == 0) // If enough time has passed…
if ( irVal > sens ) // If old and new values differ
// above sensitivity threshold
if (PRINT) // …and if the PRINT flag is set…
Serial.print("The value of IR sensor: "); // …then print the values.
PRINT = 0;
PRINT = 1; // Re-set the flag
Here’s the fine video of my IR sensor actually working!!
I had some wacky issues connecting my IR sensor, but found a useful diagram, also including here:
I ended up adapting Matt’s code also. My original code made the lights flicker a lot, but Matt averaged out the IR signal quite effectively. Kudos to you, sir. Matt’s code is also after the jump.
For my thesis, I am looking at urban spaces and researching on how people navigate through the space and communicate within that space.
For my midterm, I would like to make a toy which will communicate whether you are intruding its space by sound and light feedback. The data will be collected from surveying 3 different cities, New York, Madras and Amsterdam. There will be three robots made with different IR ranges depending on the results of the survey.
This will act as a tool that expresses how physical contact, personal space and such differs according to the geographic location and culture.
I had some problems earlier with light flickering, but I solved this by averaging the input from the IR sensor and smoothing out the results. Works great now.
I set three ranges of distance for each led.http://vimeo.com/moogaloop.swf?clip_id=2060055&server=vimeo.com&show_title=1&show_byline=1&show_portrait=0&color=&fullscreen=1
IR sensor + RGB led from Hsiang Ju Hung on Vimeo.
Here is the code: Download IR_RGB
And I did a test for floating duck.
I made a plastic base installed IR sensor for duck. And put it into a container (6"*6"*6").
Then kept adding water into it.
Here is the height of the water V.S. analogRead
1 inch : -255
2 inch : -65
3 inch : -170
4 inch : -240
Yeah~ it works in water!!! The voltage changes with the height.
But even I tried many times to modify the proper range for each led, I still cannot make leds switch with the value. Um… maybe it is because it is always negative value and it changes non-linearly….. have no idea yet.
UPDATE: I tried to do it without water in the same distance but still failed. It only turned on one led. I found that it might because it is below 10 cm which is out of Sharp sensor range(10-80cm). So I think I need to measure the proper height of water in tub to see if the sensor is suitable for it first. 10/28
I would like to make a bunch of antisocial animal plush toys. They are antisocial and they have antisocial behaviors, but they do cute things.
Ideas of toy function so far:
1. stick out tongue
2. crossed arms
3. yell "shut up" when it detects words it doesn’t like
4. puff out cheeks
5. never be face to face with you
6. air guitar
7. it will roll its eyes and say "what ever"
8. when holding the toy, it would say "leave me alone"
They all have the same characteristic: they’ll feel embarrassed after doing "bad things".
At this time in the semester, I can’t stop thinking about my thesis, so I’d like to make something related.
For my thesis, I’m exploring simple games that are fun and effective for neuro-rehabilitation. I’ve come up with several simple games that I’m hoping to develop further, both conceptually and technically.
Each game focuses on a particular function of disability. For the first one, I’d like to focus on proprioception (one’s sense of position in space). A person with a proprioception problems often have difficulty sensing where their arms/legs are in space. For this reason, it’s importan to exercise and train the person by making connections between distance, proximity and posiiton. One of the games that I have been playtesting is similar to "Pin the Tail." Using sensors can possibly help the patient in getting closer to the "target".
Another game that I’m looking into is called Blinded Samurai. There are two main players, who have to find each other, as they listen to their personal guides.
As money gets more, the piggy’s cheek becomes redder/ piggy sounds more pleased.
While you are taking a bath, the duck will change color with the wave. Or the duck will inform you once the water arrives certain height while you are away and keep storing hot water in the tub to avoid wasting time or water.
1) Omnipod Installation — I have type 1 diabetes, on an insulin pump, etc. Recently I have been looking into this newer pump called the ‘Omnipod.’ Basically each pod is a microcontroller, a couple gears, batteries, a needle, plastic catheter, and reservoir of insulin. You get 10 of them a month, they are controlled wirelessly by a PDM device that tells the pod how many times to move its gear to get insulin out, basically. So I was thinking of hacking into a couple pods. I was given some free ones by the sales-rep…and have already taken one apart. I’m so geeky. Anyway, I was thinking of trying to re-control it, without the PDM. Perhaps making the gear move/some kind of liquid coming out. I think I could also attach a speaker to it and make it say things like "0.5 units" or whatever. I want to bring it alive! Maybe there could be three or four on a wall, with proximity sensors, lit up by LEDS, and when someone gets close they will drip liquid.
See my other project ideas at the following link
This concept involves two pandas, which both detect presence. One panda, when detecting someone near by, sends a message to the second panda, which sneezes, alerting the second person of the first person’s presence. Naturally this concept makes the most sense when the two pandas are in different places.
The tenatively named Time Bird monitors the amount of time someone spends in front the computer. The bird will chirp every hour, counting the number of hours that pass, and when someone gets up from the computer the bird will reset.
Ambient Sound Frame
This photo frame would play ambient sound from the day the photograph was taken, or a recorded message related to the photograph when someone picks up the frame or gets close to it.
I thought about this the other day while setting up a photo studio in my apartment. I came close to falling over the lights and cords several times and could have used a little extra help steering clear of all the obstacles.
Magic Music Box
The music box would play a short tune, much like a traditional music box (or snow globe), but it would mysteriously sense your presence and begin to play! Like Magic!!
04 Recorder from Hsiang Ju Hung on Vimeo.
order of the buttons from left to right is: Erase, Forward, Rec, Play, FT, Vol. There are only three white push buttons that have graphic. The speak is at the left bottom. I recorded four sounds, tried to turn up and down the volume, and pressed Forward and Play to play next sound.
ChatBot Voice-Replacement Surgery
I got this robot a few months ago because I thought he was cool. He is named ChatBot, except his chat functionality doesn’t work. You are supposed to be able to record on his little tape face and he’ll play it back to you. Instead he just goes forward and turns (He can’t go backwards. Poor chatbot). This project would help give ChatBot back his voice, and also, as a bonus, it will let him warn you about his proximity to objects that might hurt him (like walls).
Taunting Cat Toy
My cats like cat toys. They are also feisty and tend to think they are (every pun intended) the cat’s pajamas. I propose a cat toy that will a) entertain them and b) put them in their place. I like the idea of the cat toy sensing motion, and, if nothing has come close to it recently, it will go through one of its 10 pre-recorded taunts. Only after the cat approaches it will it tone down the insults. I could also include a motion sensor that could do something when it was rolled. Fun!
Are you tired of being tied to Facebook? Well how’s about a little sensor that pulls data from your facebook account and tells you "There’s no need to check your account now," whenever you get close to your computer? Could be useful.