Bite Size Arduino – Sharp IR Sensor

I have received a few messages asking me to give a bit more detail into the individual bits of the robots I have built so far. Thus I am starting this series of posts in which I will cover a single sensor\actuator integration to an Arduino board per post.

Today we will have a look at how to use a Sharp IR Sensor.

The IR sensor has 3 pins – 2 pins used to power the sensor and a signal pin that is used to communicate its reading.

sharpIR_bb

As shown in the image above, connect the red pin to the 5V pin on the Arduino, the black to the GND pin and the yellow signal pin to any one of the analog pins, for the purpose of this example we will use A4.

Below is the code used to get a reading from the sensor and print it out using the Serial.println:

#define IR_PIN A4
int IRDist = 0; 

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

void loop()
{
pinMode(IR_PIN,INPUT);
IRDist = analogRead(IR_PIN);
Serial.println(IRDist);
delay(1000);
}

I suggest using this code to experiment and see what readings get generated by placing the sensor at different distances from an obstacle.

Bite Size Arduino – Sharp IR Sensor

3 thoughts on “Bite Size Arduino – Sharp IR Sensor

    1. JR says:

      That is correct, to convert to voltage can be done as follows:
      IRDistmm = ((67870.0 / (IRDist – 3.0)) – 40.0);

      I have however noticed that I need to manually adjust the constant values above for each sensor to get an accurate reading.

      Like

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