- This topic has 1 reply, 2 voices, and was last updated 10 years, 10 months ago by .
Viewing 2 posts - 1 through 2 (of 2 total)
Viewing 2 posts - 1 through 2 (of 2 total)
- You must be logged in to reply to this topic.
|
Microcontroller › Arduino › Line follower robot
line follower robot using ir sensor, my value on white is less than black. what should i do?
after burning code to arduino it is not working.
when i am try to open serial port ,this also not showing any value
my code is below ..
int leftPins[] = {5,7,4}; //On the for PWM , two pins for motor direction;
int rightPins[] = {6,3,2};
const int MIN_PWM = 64; //this can range from 0 to MAX_PWM;
const int MAX_PWM = 128; //this can range from around 50 to 255;
const int leftSensorPin = 0;
const int rightSensorPin = 1;
int sensorThreshold = 0;
void setup()
{
for(int i=1; i<3; i++)
{
pinMode(leftPins, OUTPUT);
pinMode(rightPins, OUTPUT);
}
}
void loop()
{
int leftVal = analogRead(leftSensorPin);
int rightVal = analogRead(rightSensorPin);
if(sensorThreshold == 0){ //have the sensor been calibrated ?
// if not, calibrate sensor to somethingabpve the ambient average
sensorThreshold = ((leftVal + rightVal) / 2) + 100 ;
}
if( leftVal > sensorThreshold || rightVal > sensorThreshold)
{
// if there is adeqate light to move ahead
setSpeed(rightPins, map(rightVal,0,1023, MIN_PWM, MAX_PWM));
setSpeed(leftPins, map(leftVal,0,1023, MIN_PWM, MAX_PWM));
}
}
void setSpeed(int pins[], int speed )
{
if(speed < 0)
{
digitalWrite(pins[1],HIGH);
digitalWrite(pins[2],LOW);
speed = -speed;
}
else
{
digitalWrite(pins[1],LOW);
digitalWrite(pins[2],HIGH);
}
analogWrite(pins[0],speed);
}
Hi Aquib,
“if( leftVal > sensorThreshold || rightVal > sensorThreshold)”
You are checking for a high threshold, right?
Why dont you set a low threshold value, which is graeter than zero and check for it?
“if( leftVal < sensorThreshold || rightVal < sensorThreshold)”