For my Sensors and Time lab I decided to use something I had picked up last semester and never used: the Matched Infrared Emitter and Detector from Radioshack (276-0142). The whole process would have been a little easier if there was some kind of datasheet with it. Luckily I was able to use Google to find someone who had successfully set it up and I used their notes as a guide: http://www.oscarcontrols.com/coinswitch/.
Once I verified through serial communicator that the sensor duo was working, I was ready to move on to sending the on/off state (1 or 0) to processing. I used the code written by Tom Igoe in both instances, with only minor adjustments. Both are listed below.
My pictures show the data being logged over time. The blue lines indicate successful infrared detection while the white spaces in between are where I blocked the path from emitter to detector.
![]() | ![]() |
| Blocking the path with my hand. | Succesful transmission. |
![]() | |
| A close view of the infrared detection (blue) and the times when the path was blocked (white). | |
![]() | |
| When I was testing I have the word "Transmitting!" when transmitting successfully and "Doh!" when blocked. | |
Pic 18F452
' call and response serial example for picBasic Pro.
' By Tom Igoe, 2003, small adjustments by Joey Guerrero
' This example waits for a byte on the incoming serial connection,
' and checks to see that the byte equals 65.
' It then sends the values of a sensor on pin RD2.
' this example uses two arrays to hold the ADC values,
' and the byte values that they're converted to for sending.
' serial RX is on pin RC7
' serial TX is on pin RC6
' constant to set the baud rate:
inv9600 con 16468
' define variables:
'adcVar var word(3)
byteVar var byte(3)
channel con 2
inByte var byte
' main:
IF portd.2 then
byteVar(channel) = 1 ' Ascii 1 serout2 portc.6, inv9600, [byteVar(2)]
' serout2 portc.6, inv9600, ["Transmitting!", 13,10] ELSE
byteVar(channel) = 0 ' Ascii 0 serout2 portc.6, inv9600, [byteVar(2)]
' SEROUT2 portc.6, 16468, ["Doh!", 13,10] endif
Processing
Datalogger
by Tom Igoe This program takes raw bytes from the serial port at 9600 baud and graphs them. To start/stop the graph, click the mouse. No graphing is done when the incoming value is below a constant threshold. You can only change the threshold in code. I haven't made a UI for that. Created 20 April 2005 Updated 5 July 2005
import processing.serial.*;
Serial myPort; // The serial port
// initial variables: int i = 1; // counter int inByte = -1; // data from serial port
void setup () {
size(400, 300); // window size // List all the available serial ports println(Serial.list()); // I know that the third port in the serial list on my mac // is always my Keyspan adaptor, so I open Serial.list()[2]. // Open whatever port is the one you're using. myPort = new Serial(this, Serial.list()[1], 9600); // set inital background: background(255);
} void draw () {
if (myPort.available() > 0) {
inByte = myPort.read();
serialEvent();
}
}
void serialEvent () {
// draw the line:
println(inByte);
stroke(0,51,153);
line(i, height, i, height - (inByte*(height/2)));
// at the edge of the screen, go back to the beginning:
if (i >= width) {
i = 0;
background(255);
}
else {
i++;
}
}



