Sharp infrared sensor

I got the long-range infrared distance sensor to send data to my computer, using this bit of code here:

#define BAUDRATE 9600
#define IRPIN 0 //analog pin for reading the IR sensor
#define WAIT 300 //milliseconds to delay

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

void setup() {
Serial.begin(BAUDRATE);
}

void loop() {
val = analogRead(IRPIN); // read the value from the sensor
Serial.println(val); // print the raw analog value to serial port
delay(WAIT); // stop the program for some time
}

From what I gather, ultrasound sensors and IR sensors work in pretty similar ways, so it was not an entirely pointless exercise!

Advertisements

One Response to “Sharp infrared sensor”

  1. I loved reading your blog and I found it very interesting. I m really impressed with your work. I loved your idea about the whole thing. I am happy I went through your blog. It has helped me a lot….

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: