Actions, Events, and Filtering
Pinch
This is very simple with a force sensing resistor.
I was going to try tracking motion with IR however, after trying to make the ir sensor work for remote control, I couldn’t look at it anymore.
I uploaded Firmata on Arduino. You can control Arduino through Processing with Firmata. You get values from the sensor when it is squeezed or pinched. There is a threshold for pain.
Here’s the code:
/**
* Graph sensor values with text output ***IMPORT FONT
*/
import processing.serial.*;
import cc.arduino.*;
int[] xvals;
int val;
int arrayindex = 0;
Arduino arduino;
int ledPin=9;
int potPin=0;
void setup()
{
size(500, 500);
xvals = new int[width];
arduino = new Arduino(this, Arduino.list()[1], 57600);
arduino.pinMode(ledPin, Arduino.OUTPUT);
PFont font;
font = loadFont(”ACaslonPro-Bold-48.vlw”);
textFont(font);
}
void draw()
{
background(0);
// shift array left by one
for(int i=1; i<width; i++) {
xvals[i-1] = xvals[i];
}
// add the new values to the end of the array
// read potentiometer (0..1024), divide by four (0..255)
// to stay within canvas drawing limits
val = arduino.analogRead(potPin);
xvals[width-1] = val/4;
// draw the array
for(int i=1; i<width; i++) {
stroke(255);
point(i, 255-xvals[i]); //flip y coordinate so 0 is at bottom
}
textAlign(RIGHT);
text(val, 200, 30);
text(5.0*(xvals[width-1]/255.0)+”V”,200,60);
if (val >= 700) {
text(”OW!!”, 350, 200);
}
}
Sensor Report
IR Receiver Breakout - This is a very small IR receiver based on the TSOP85 receiver from Vishay.
The TSOP852.. series
is for standard IR remote control applications,
supporting all major transmission codes.
The demodulated output signal can be directly
decoded by a microprocessor.
Schematic of breakout board
• Photo detectors and Preamplifier in one
package
• Output active low
• Low power consumption
• Supply voltage: 2.7 V to 5.5V
Breakout Board TSOP851
The TSOP851.. series is optimised for short burst
transmission codes and high data rates.
The AGC (automatic gain control) circuit keeps the receiver in its linear operating range by detecting the overall strength of the signal and automatically adjusting the gain of the receiver to maintain an approximately constant average output level.
A band-pass filter is a device that passes frequencies within a certain range and rejects frequencies outside that range. The TSOP851 is designed in such a way that spurious output pulses due to noise or disturbance signals are suppressed. The distinguishing characteristics between data and disturbance signals are carrier frequency, burst length and envelope duty cycle. Optimally, the data signal should be close to the band-pass center frequency (e.g. 38 kHz).
Finally, it demodulates a previously modulated signal by removing all high frequency components of the signal.
So…. Remotes and protocols.
They are all different.
Sony:
Hitachi:
Code for Sony
I found this code in the Arduino site- in a forum I believe…can’t find it now. It returns an integer for each button of the remote. For example, when I press 1 on the remote, I get a value of 128 on the serial screen of Arduino. I can then tell Arduino to assign the number ‘1′ to 128, so that when I press one, it prints 1 on the serial screen.
int ir_pin = 2; //Sensor pin 1 wired through a 220 ohm resistor
int led_pin = 13; //”Ready to Recieve” flag, not needed but nice
int debug = 0; //Serial connection must be started to debug
int start_bit = 2000; //Start bit threshold (Microseconds)
int bin_1 = 1000; //Binary 1 threshold (Microseconds)
int bin_0 = 400; //Binary 0 threshold (Microseconds)
int val;
void setup() {
pinMode(led_pin, OUTPUT); //This shows when we’re ready to recieve
pinMode(ir_pin, INPUT);
digitalWrite(led_pin, LOW); //not ready yet
Serial.begin(9600);
}
void loop() {
int val = getIRKey(); //Fetch the key
// Serial.print(”Key Received:”);
// Serial.println(val);
int getIRKey() {
int data[12];
digitalWrite(led_pin, HIGH); //Ok, i’m ready to recieve
while(pulseIn(ir_pin, LOW) < 2200) { //Wait for a start bit
}
data[0] = pulseIn(ir_pin, LOW); //Start measuring bits, I only want low pulses
data[1] = pulseIn(ir_pin, LOW);
data[2] = pulseIn(ir_pin, LOW);
data[3] = pulseIn(ir_pin, LOW);
data[4] = pulseIn(ir_pin, LOW);
data[5] = pulseIn(ir_pin, LOW);
data[6] = pulseIn(ir_pin, LOW);
data[7] = pulseIn(ir_pin, LOW);
data[8] = pulseIn(ir_pin, LOW);
data[9] = pulseIn(ir_pin, LOW);
data[10] = pulseIn(ir_pin, LOW);
data[11] = pulseIn(ir_pin, LOW);
digitalWrite(led_pin, LOW);
if(debug == 1) {
Serial.println(”—–”);
}
for(int i=0;i<11;i++) { //Parse them
if (debug == 1) {
Serial.println(data[i]);
}
if(data[i] > bin_1) { //is it a 1?
data[i] = 1;
} else {
if(data[i] > bin_0) { //is it a 0?
data[i] = 0;
} else {
data[i] = 2; //Flag the data as invalid; I don’t know what it is!
}
}
}
for(int i=0;i<11;i++) { //Pre-check data for errors
if(data[i] > 1) {
return -1; //Return -1 on invalid data
}
}
int result = 0;
int seed = 1;
for(int i=0;i<11;i++) { //Convert bits to integer
if(data[i] == 1) {
result += seed;
}
seed = seed * 2;
}
return result; //Return key number
}
Sensors and Time
For this exercise I took data from three photo sensors about an inch apart from each other.
First I tried Tom Igoe’s sensor graphing with three lines of code. This method required that you send the data from Arduino to Terminal. Getting this to work took quite a while, as the instructions were not completely clear- especially to work with Terminal (how to stop it and getting a screenlog file on the desktop). Once you get your values in Terminal, and get it to stop, you have to convert the screenlog file to a text file. Tom says to convert it to a .csv file, but this didn’t work for me. I just converted into a .txt file and that worked. I imported my values into Grapher, and chose the Log-Log format
because it displays the data clearly.
Grapher also displays data in 3D. Here’s a screen shot of my data flying around in 3D space.
Then I tried the code for Three Sensors and One Threshold, and this is a screen shot of my Processing applet.
It is interesting that when I was getting values in Arduino, all three were within the same range. However, when I mapped out the data, it shows that one of my sensors is in a different range altogether.
Sensor Walk
These are from my room to the subway.
-card reader for the front door of the building (RFID)
-photosensor for alarm clock- the numbers dim with light in the room and get brighter as it gets darker
-wifi on the laptop
-smoke detector
-car alarm triggered by motion
-card reader for the subway metrocard
-touch screen to buy metrocard