IR emitter and receiver problem


so here goes 1st post :)
i thought of building line following robot using arduino uno rev 3 (on windows 7 laptop, incase necessary) following tutorial.so gathered required parts , theres ir emitter/detector (which both of them on single pack) gives me problem.
i thought of testing on breadboard before actualy beginning build it. connected ir sensor instructed in tutorial, long leads +5 of arduino , gnd gnd of arduino through resistor. wire inbetween gnd of detector , resistor analog pin of arduino.

update : gives me 0 or 1 , when cover finger, increases upto 25. tried other ir sensors of same type, nothing changes. same.
note - can use analog pins since have use motorshield.

heres code : (very sorry, putting whole code)
code: [select]
// linus line-bot
// follows black line on white surface (poster-board , electrical tape).
// code jdw 2010 – feel free modify.
#include <afmotor.h> // includes afmotor library motor-controller
af_dcmotor motor_left(1); // attach motor_left adafruit motorshield m1
af_dcmotor motor_right(3); // attach motor_right adafruit motorshield m3
// create variables sensor readings
int sensor1 = 0;
int sensor2 = 0;
int sensor3 = 0;
int sensor4 = 0;
int sensor5 = 0;
// create variables adjusted readings
int adj_1 = 0;
int adj_2 = 0;
int adj_3 = 0;
int adj_4 = 0;
int adj_5 = 0;
// can change min/max values below fine tune each sensor on bot
int s1_min = 200;
int s1_max = 950;
int s2_min = 200;
int s2_max = 950;
int s3_min = 200;
int s3_max = 950;
int s4_min = 200;
int s4_max = 950;
int s5_min = 200;
int s5_max = 950;

// threshold defines when sensor reading black line
int lower_threshold = 20;
// value define middle threshold (half of total 255 value range)
int threshold = 128;
// threshold defines when sensor reading white poster board
int upper_threshold = 230;
// value sets maximum speed of linus (255 = max).
// using speed potentiometer over-ride setting.
int speed_value = 255;
// end of changeable variables
void setup()
{
serial.begin(9600); // start serial monitor see sensor readings
// declare left motor
motor_left.setspeed(255);
motor_left.run(release);
// declare right motor
motor_right.setspeed(255);
motor_right.run(release);
}
void update_sensors(){
// read sensor 1
sensor1 = analogread(a0);
adj_1 = map(sensor1, s1_min, s1_max, 0, 255);
adj_1 = constrain(adj_1, 0, 255);
// read sensor 2
sensor2 = analogread(a1); // sensor 2 = left-center
adj_2 = map(sensor2, s2_min, s2_max, 0, 255);
adj_2 = constrain(adj_2, 0, 255);
// read sensor 3
sensor3 = analogread(a2); // sensor 3 = center
adj_3 = map(sensor3, s3_min, s3_max, 0, 255);
adj_3 = constrain(adj_3, 0, 255);
// read sensor 4
sensor4 = analogread(a3); // sensor 4 = right-center
adj_4 = map(sensor4, s4_min, s4_max, 0, 255);
adj_4 = constrain(adj_4, 0, 255);

// read sensor 5
sensor5 = analogread(a4); // sensor 5 = right
adj_5 = map(sensor5, s5_min, s5_max, 0, 255);
adj_5 = constrain(adj_5, 0, 255);
// check value speed potentiometer if present (to read pot, uncomment line below)
//speed_pot = analogread(5) / 4;
}
void loop(){
update_sensors(); // update sensors
//speed_value = speed_pot; // leave commented out, unless using potentiometer
// first, check value of center sensor
if (adj_3 < lower_threshold){
// if center sensor value below threshold, check surrounding sensors
if (adj_2 > threshold && adj_4 > threshold){
// if sensors check out, drive forward
motor_left.run(forward);
motor_left.setspeed(speed_value);
motor_right.run(forward);
motor_right.setspeed(speed_value);
}
// want bot stop when reaches black box.
else if (adj_1 < 1){
if (adj_2 < 1){
if (adj_3 < 1){
if (adj_4 < 1){
if (adj_5 < 1){
// if sensors reading black, stop linus.
motor_left.run(release);
motor_right.run(release);
}
}
}
}
}
}
// otherwise, center sensor above threshold
// need check sensor above black line
else {
// first check sensors 1
if (adj_1 < upper_threshold && adj_5 > upper_threshold){
motor_left.run(release);
motor_left.setspeed(0);
motor_right.run(forward);
motor_right.setspeed(speed_value);
}
// check sensor 5
else if (adj_1 > upper_threshold && adj_5 < upper_threshold){
motor_left.run(forward);
motor_left.setspeed(speed_value);
motor_right.run(release);
motor_right.setspeed(0);
}
// if not sensor 1 or 5, check sensor 2
else if (adj_2 < upper_threshold && adj_4 > upper_threshold){
motor_left.run(release);
motor_left.setspeed(0);
motor_right.run(forward);
motor_right.setspeed(speed_value);
}
// if not sensor 2, check sensor 4
else if (adj_2 > upper_threshold && adj_4 < upper_threshold){
motor_left.run(forward);
motor_left.setspeed(speed_value);
motor_right.run(release);
motor_right.setspeed(0);
}
}
///// print values each sensor
/////sensor 1 values
serial.print("sensor 1: ");
serial.print(sensor1);
serial.print(" - ");
serial.print("adj 1: ");
serial.print(adj_1);
serial.print(" - ");
/////sensor 2 values
serial.print("sensor 2: ");
serial.print(sensor2);
serial.print(" - ");
serial.print("adj 2: ");
serial.print(adj_2);
serial.print(" - ");
/////sensor 3 values
serial.print("sensor 3: ");
serial.print(sensor3);
serial.print(" - ");
serial.print("adj 3: ");
serial.print(adj_3);
serial.print(" - ");
/////sensor 4 values
serial.print("sensor 4: ");
serial.print(sensor4);
serial.print(" - ");
serial.print("adj 4: ");
serial.print(adj_4);
serial.print(" - ");
/////sensor 5 values
serial.print("sensor 5: ");
serial.print(sensor5);
serial.print(" - ");
serial.print("adj 5: ");
serial.print(adj_5);
serial.print(" ");
serial.print("speed: ");
//serial.print(speed_pot);
serial.println(" ");
}
// end of code


sesnor :


datasheet : http://www.vishay.com/docs/83760/tcrt5000.pdf

setup:




it great if can me out here. first robotic project , total beginner field eventhough have knowledge on programming stuff :)
i searched everywhere on internet couldn't find solution.
thanks alot :)

need datasheet sensor , photo of hand drawn schematic of breadboarded circuit.


Arduino Forum > Using Arduino > Sensors > IR emitter and receiver problem


arduino

Comments

Popular posts from this blog

opencv3, tbb and rasp pi 2 - Raspberry Pi Forums

small ethernet problem - Raspberry Pi Forums

Multithumb configuration params not working? - Joomla! Forum - community, help and support