Connecting IR line sensor to arduino

I am new to micro-controllers and need help connecting an OSEPP IR Line Sensor to my Arduino Uno. I am not sure how to go about doing this. Where do I start? For my project, I need to connect an LV-Max Sonar EZ1 rangefinder and a OSEPP IR Line Sensor to the Arduino. Thanks for the assistance.

The line sensor uses an I2C buss. Search and read how to use I2C on your Uno.

There is good documentation for the line sensor for the manufacture. Download and study.

I now think I know how to connect the sensor but have a problem.

To start, If I need to connect one end of the cable into either Molex connectors on the sensor and

connect the other end of the cable to the Arduino board:

RED: 5V

WHITE: I2C SDA (pin A4 on Uno)

BLACK: GND

GREY: I2C SCL (pin A5 on Uno)

how can I do this if the cable that came with the sensor to perform this action doesn’t have pins sticking out on the other end of the cable?

You will have to put on connectors, or mount them that’s best suits your project. ie, is it just a prototype, meaning you don’t want to mount the wires permanently, or is this project going into a final project that will never be taken out? If the later, you could take out the Arduino headers and solder them directly to the board.

It is just a prototype, not final. I am almost finished successfully connecting the sensor. I ended up using jumper wires and a breadboard but I have bigger problems now. How exactly do I set the DIP switch on the sensor to set the sensor address? By my understanding, I have to tell the Arduino that the sensor exists by using this address, right? How do I tell it to recognize the sensor? One other thing, how do I connect the rangefinder? Does it use the ICSP pins? I really need help to connect the rangefinder.

First hit on Google, http://playground.arduino.cc/Main/MaxSonar

The rest I will leave up to you to find.

I connected the rangefinder. Can you give me code that I can use to test the rangefinder and the IR Line sensor? Maybe something that when I wave my hand over the sensor, data is displayed on the screen and code that when I put a piece of black paper over the line sensor, it displays data? I just need code to test what I have connected.

Google

How come when I try to use this code, I get the message “Line_sensor.ino:1:2086: error: #include expects “FILENAME” or ”

Here is the code:

// This sketch demonstrates interactions with the IR Line Sensor

#include

// Possible sensor addresses (suffix correspond to DIP switch positions)

#define SENSOR_ADDR_OFF_OFF (0x4B)

#define SENSOR_ADDR_OFF_ON (0x4A)

#define SENSOR_ADDR_ON_OFF (0x49)

#define SENSOR_ADDR_ON_ON (0x48)

// Set the sensor address here

const uint8_t sensorAddr = SENSOR_ADDR_OFF_OFF;

// One-time setup void setup

void setup()

{

// Start the serial port for output Serial.begin(9600);

// Join the I2C bus as master Wire.begin();

// Set up the ADC on the sensor (reset everything) WriteByte(sensorAddr, 0x0, 0x0);

}

// Main program loop

void loop()

{

uint8_t left; uint8_t right;

// Get the value from the sensors; left sensor is at register 0, and the right

// sensor is at register 1

if ((ReadByte(sensorAddr, 0x0, &left) == 0) &&

(ReadByte(sensorAddr, 0x1, &right) == 0))

{

// Use a threshold (value from 0-255) to determine if sensor detected a dark

// or light surface; the threshold should be modified according to the

// environment on which the sensor will be used

if (left >= 200)

{

Serial.println(“L: DARK”);

}

else

{

Serial.println(“L: LIGHT”);

}

if (right >= 200)

{

Serial.println(“R: DARK”);

}

else

{

Serial.println(“R: LIGHT”);

}

}

else

{ Serial.println(“Failed to read from sensor”);

}

// Run again in 1 s (1000 ms)

delay(1000);

}

// Read a byte on the i2c interface

int ReadByte(uint8_t addr, uint8_t reg, uint8_t *data)

{

// Do an i2c write to set the register that we want to read from

Wire.beginTransmission(addr);

Wire.write(reg);

Wire.endTransmission();

// Read a byte from the device

Wire.requestFrom(addr, (uint8_t)1);

if (Wire.available())

{

*data = Wire.read();

}

else

{

// Read nothing back

return -1;

}

return 0;

}

// Write a byte on the i2c interface

void WriteByte(uint8_t addr, uint8_t reg, byte data)

{

// Begin the write sequence

Wire.beginTransmission(addr);

// First byte is to set the register pointer

Wire.write(reg);

// Write the data byte

Wire.write(data);

// End the write sequence; bytes are actually transmitted now

Wire.endTransmission();

}

Another question. How exactly is the rangefinder working? When I run this, a bunch of #s are displayed. It gives the inch value and sense a-d value. It does this consistently non stop with the numbers getting higher each time. What is it doing or measuring?

int configPin = 13;

void setup() {

Serial.begin(9600);

pinMode(configPin,OUTPUT);

}

void loop(){

digitalWrite(configPin,HIGH);

delay(120);

float sensorvalue = analogRead(0); // A 0 is used here but If I am using the analog 3 pin instead, I should change this right?

float inchvalue = (254.0/1024.0) 2.0 sensorvalue;

Serial.print(“Sensed a-d value:”);

Serial.println(sensorvalue);

Serial.print(“inch value=”);

Serial.println(inchvalue);

delay(1000);

digitalWrite(configPin,LOW);

delay(1000);

}