Pages: [1]   Go Down
Author Topic: Infrared Reflectance Sensor  (Read 1287 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello I want to build a line follower so I bought one of this http://www.ebay.at/itm/270589619744?ssPageName=STRK:MEWNX:IT&_trksid=p3984.m1497.l2649#ht_3121wt_802

I have made some projects before, but this is the first time using a sensor... So I soldered it together an connected pin1 and pin2 to 5V and GND, pin3 to AnalogIn 0. I connected the other pins to digital. I tried around with pinOut to the digital pins and checked the LEDs with a camera. They all work. Now here comes the tricky part: I used analog read(A0) but it just gives me 843 or 842 on the Serial Monitor...? What am I doing wrong? Can somebody help me please?

Thanks a lot!
Logged

Offline Offline
Edison Member
*
Karma: 9
Posts: 1016
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You can test the IR leds (IR transmitters) with a webcam or normal photo camera.
If they work you can hold a paper in front of them, see if the value changes.

The value seems okay to me.
Logged

Dubuque, Iowa, USA
Offline Offline
Faraday Member
**
Karma: 49
Posts: 2544
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Reflectance sensors are finicky things. Try to bend the LEDs / phototransistors a bit so they point towards each other (imagine the light bouncing off the surface between the LED / phototransistor). Play around with the distance to your target and what you're using for a "line". Some things that are black to you and me turn out to be much more reflective to these phototransistors.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The problem is the value doesn't even change... I think my code might be wrong! I set all the digital pins to output. I check the LEDs they are a lit up. Then I analogRead Pin 0. Value stays 844, 844, sometimes 843. I can do anything I want, I used white paper, black paper, LCD screens (for reflecting) the value doesn't change.

I really want to get this to work!
Logged

Dubuque, Iowa, USA
Offline Offline
Faraday Member
**
Karma: 49
Posts: 2544
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Go ahead and post your code. Also explain how you have the Arduino pins connected to the pins on the board -- the diagram on the eBay page shows the pins numbered 1 through 10 on the board so using that nomenclature would be helpful.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
int aval1 =0;
int aval2 = 0;
int avalr = 0;
int refval = 0;
int pwm=0;
int bias=0;
int t=0;
char* str1[] = {"CHANNEL A", "CHANNEL B", "CHANNEL C"};
int lf = 0;
int rg = 0;
int st = 0;
void setup()
{
// Print a message to the LCD.
//lcd.print(str1[st]);
//lcd.print(analogRead(0));
pinMode(4,OUTPUT);
pinMode(5,OUTPUT);
pinMode(6,OUTPUT);
pinMode(7,OUTPUT);
pinMode(9,OUTPUT);
pinMode(10,OUTPUT);
digitalWrite(5,LOW);
digitalWrite(4,HIGH);
Serial.begin(9600);
bias = 40;
}
void loop()
{
st = 0;
aval1 = 0;
aval2 = 0;
digitalWrite(7,HIGH);
analogWrite(9,255);
analogWrite(10,255);
while (st < 10)
{
st++;
digitalWrite(7,HIGH);
delayMicroseconds(10);
aval1 = aval1+analogRead(0);
digitalWrite(7,LOW);
delayMicroseconds(10);
aval2 = aval2+analogRead(0);
}
//refval = analogRead(1);
refval = 20;
Serial.print(aval2-aval1);
avalr = aval2-aval1;
Serial.print("<");
Serial.print(avalr);
Serial.print(">");
if (abs(aval2-aval1)>refval)
{
digitalWrite(5,HIGH);
pwm = 50;
analogWrite(9,255);
analogWrite(10,pwm+bias);

}
else
{
digitalWrite(5,LOW);
pwm = 50;
analogWrite(9,pwm);
analogWrite(10,pwm+bias);
}
//lcd.clear();
//lcd.print(str1[0]);
//lcd.setCursor(1,1);
//lcd.print("Analog=");
//lcd.print(aval2-aval1);
//lcd.print(" : ");
//lcd.print(refval);
delay(500);
}

This is the code they sent me... It seems a little bit wrong because they defining 6 pins to output, but the schematic just shows 5 to connect to the digital ports... This code just gives me -2, -1, 0, 3... Whats wrong here? I can't figure out why this isn't working...

Then I coded this myself: (I think this is also wrong)

Code:
void setup() {
pinMode(5,OUTPUT);
pinMode(6,OUTPUT);
pinMode(7,OUTPUT);
pinMode(8,OUTPUT);
pinMode(9,OUTPUT);
Serial.begin(9600);
}

void loop() {
  int myInts[5];
  int pin = 5;
  for (int i = 0; i < 5; i++) {
    digitalWrite(pin, LOW);
    int var = analogRead(0);
    myInts[i]=var;
    pin++;
    delay(100);
  }
  int i;
  for (i = 0; i < 5; i = i + 1) {
  if(myInts[i] == 843){
    Serial.println("Weiss");
  } else {
    Serial.println("Schwarz");
}
  }
  Serial.println("---------------");
}
« Last Edit: January 18, 2013, 05:44:27 pm by m1s73r » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 34
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Being new to IR Led White is i think emmiter which gives signals and black is receiver which receives signals i think, after searching on net, i didn't got any good code to be used with arduino uno so that i can run my own codes for simple task like on and off or cut-off pulse detection etc.

1. Can anybody help me out for how to use IR Leds black and white without TSOP 17xx ?

2. if i connect TSOP (3 PIN 1: Ground, 2: 5V, 3: Output) it catches signals but when i give output pin to analogread to pin A0 or arduino, it is not reading anything !!!.



* 060213-2139.jpg (8.22 KB, 320x240 - viewed 36 times.)
Logged

Pages: [1]   Go Up
Jump to: