Infrared distance sensor

Infrared distance sensor

This invention demonstrates how to connect an infrared distance sensor to your ThinkerShield. An infrared distance sensor sends out an infrared beam which bounces off objects and returns to the sensor to tell how far away any objects are. Most infrared distance sensors are useful to about 30cm.

 

 

Step 1

Step 1

Connect first alligator clip to GND (ground) on your ThinkerShield and to the negative (black) wire of your infrared distance sensor.

Step 2

Step 2

Connect second alligator clip to external pin VCC on your ThinkerShield and to the positive (red) wire of your infrared distance sensor.

Step 3

Step 3

Connect third alligator clip to external pin A0 on your ThinkerShield and to the signal (yellow) wire of your servo.

Step 4

// declare the sensor variable
int sensor = A0;

void setup() {
 // begin a serial connection
 Serial.begin (9600);

// set the sensor pin as an input 
 pinMode (sensor, INPUT);
}

void loop() {
 // store the reading from the sensor 
 // into the variable distance
 int distance = analogRead (sensor);

// print the distance to the serial monitor
 Serial.println (distance);
}

Add a comment