Arduino Line Follower Code problem

Hey guys!!!
I badly need your help asap hopefully because I'm chasing a deadline now. :sob:

I'm using Adruino UNO board, YL-70 4 channel IR sensor and L298N dual H bridge motor driver.

so the pins goes like this:

(from YL-70 sensor)

IN1 = (digiPin) 7
IN2 = (digiPin) 8
IN3 = (digiPin) 9
IN4 = (digiPin) 10

(L298N motor driver)

in1 = (digiPin) 1
in2 = (digiPin) 2
ENA = (digiPin) 3
in3 = (digiPin) 4
in4 = (digiPin) 5
ENB = (digiPin) 6

and my code is this:

//Define Pins
int ENA = 3; // "ENA" is pin of L298N motor driver; "3" is Arduino Digital PIN
int IN1 = 1;
int IN2 = 2;

int ENB = 6;
int IN3 = 4;
int IN4 = 5;

int IR1 = 7;
int IR2 = 8;
int IR3 = 9;
int IR4 = 1;

int leftvalue = 0;
int rightvalue = 0;

//Define Run variable
boolean run;
void setup() {

pinMode(ENA, OUTPUT);
pinMode(IN1, OUTPUT);
pinMode(IN2, OUTPUT);

pinMode(ENB, OUTPUT);
pinMode(IN3, OUTPUT);
pinMode(IN4, OUTPUT);

run = true;

}

//command sequence
void loop() {

if (run){

rightvalue = digitalRead (IR2);
leftvalue = digitalRead (IR3);

if
( leftvalue < 80 && rightvalue < 80)
{
digitalWrite (ENA, HIGH);
digitalWrite (ENB, HIGH);

}
else
{

if
( leftvalue > 80 && rightvalue < 80)
{
digitalWrite (ENA, HIGH);
digitalWrite (ENB, LOW);

}
else {
if (leftvalue < 80 && rightvalue > 80)
{
digitalWrite (ENA, LOW);
digitalWrite (ENB, HIGH);
}
else
{
if (leftvalue > 80 && rightvalue > 80)
{
digitalWrite (ENA, LOW);
digitalWrite (ENB, LOW);

}
}
}
}
}

Please I badly need your help.

What are you expecting this code to do that it is not doing?

Also, you should put you code in code markers when you post.

Your equally badly posted duplicate of this thread has been deleted.

DO NOT CROSS-POST, CROSS-POSTING WASTES TIME.

I'm chasing a deadline now.

Your problem, not ours.

I'm chasing a deadline now

Not very effectively.

...R

  leftvalue = digitalRead (IR3);

if
   ( leftvalue < 80

pretty much a "given"

I'm very sorry for not being polite on posting this, I was just very frustrated last night. sorry.

I'm expecting to follow a black line, if the IR sensor detect black line, the two DC motor is on, else off.

I'm having a problem on my program because I'm not sure on it, I am new on Arduino IDE programming language and I'm not sure if the reserve word (code) I used is correct.

once again, I'm very sorry.

I'm expecting to follow a black line, if the IR sensor detect black line, the two DC motor is on, else off.

And what is it doing? Have you fixed the issues that have been pointed out?

kristiangooo:
I'm having a problem on my program because I'm not sure on it, I am new on Arduino IDE programming language and I'm not sure if the reserve word (code) I used is correct.

I'm sure we all figured you have a problem because if you didn't you would not have posted here.

The real problem is that you have not explained your problem.

What does your code actually do? And what different thing do you want it to do?

And can you edit your original post to put your code between code tags (the button like a scroll with <>)

so it looks like this and is easier to follow

.
...R

I'm very sorry Sir/ma'am,

well, for the mean time, the code didn't work, it just showing that the 4 sensor are working, but the two DC motors are not running (working), but I'm sure that all my components are in good condition (not defective).

In short, the code is not working,

is it about the how I write my code? or did I use those proper reserved words on Arduino IDE?

Thank You all for feedback and once again sorry for those people I've pissed off or misunderstood my first post, I'm very sorry.

As I mentioned earlier, it's pretty much a given that any value returned by digitalRead is going to be less than two, so testing to see if it's less than 80 is overkill.

For a start you shouldn't use digital pin 1 since it's best reserved for Serial, but apart from that you seem to have tried to connect 2 things to the same pin 1, see <<<<<<<<<<< below?

//Define Pins
int ENA = 3;  
int IN1 = 1;  //<<<<<<<<<<<<<<<<<<<<<<<<<<<<
int IN2 = 2;
 
int ENB = 6;
int IN3 = 4;
int IN4 = 5;

int IR1 = 7;
int IR2 = 8;
int IR3 = 9;
int IR4 = 1;  //<<<<<<<<<<<<<<<<<<<<<<<<<<<<

it just showing that the 4 sensor are working

How do you know that?

Thank you sir awol, what do you mean by less than 80 is overkill?

Thank you sor JimboZA, It's a typo, it is (IR4 = 10;), I'm sorry.

What AWOL means is that a digitalRead is either 0 or 1, so it will alwaysbe less than 80, so no point in checking that.

How do you know that your sensors are working?

thank you sir jimboZA, I also tried 0 and 1 on digital read, but still it doesn't work.

I know it's working because I can see from the port (board) of IR sensor I'm using the led lights are turning off and on when I test.

, but still it doesn't work.

I know it's working

OK.

Sir awol, please don't get me wrong, what I mean is that, I change the value from 80 to 1, and still nothing's change, and then I change the value again from 1 to 0 and it's just the same..

what I mean from "I know it's working" because sir jimboZA asked how did I know that the IR SENSORS are working. The IR sensor are working and not defective, that's what I mean. Thank You.

Have you caught the deadline you were chasing yet?

I change the value again from 1 to 0 and it's just the same..

Well, a reading from a digital sensor isn't likely to be less than zero, is it?

Why don't you try the sensors on the analogue pins?

not yet sir and I almost die. It was due this afternoon, but I didn't present something but fortunately my professor gave a 2nd chance and it is due tomorrow afternoon (3am here in my country now when I post this reply).

ok sir, I will try to put it on anal pins.

THANK YOU SO MUCH and sorry for my first post yesterday.

Your connections are wrong.
Your first post shows IN1-IN4 connected to your digital pins.
Should be OUT1-OUT4 connected to your digital inputs.
4 Tracking Sensor Module

someone gave me this code and said it's up to me what to add, and I didn't found something about the IR sensor. what should I add?

by the way,I'm using L298N motor driver.

__ NOTES __

To spin wheel A FORWARD:
ENA = HIGH
IN1 = HIGH
IN2 = LOW

To spin wheel A BACKWARD:
ENA = HIGH
IN1 = LOW
IN2 = HIGH

To spin wheel B FORWARD:
IN3 = HIGH
IN4 = LOW
ENB = HIGH

To spin wheel B BACKWARD:
IN3 = LOW
IN4 = HIGH
ENB = HIGH
***/


/*********************************************
if in WHITE line:
Infrared signal bounce and reflect
Red LED on the board is ON
Output Voltage is Zero (low)


if in BLACK line:
Infrared signal do not bounce and no signal
Red LED on the board is OFF
Output Voltage is 5v or Vcc (high)
*********************************************/



//See Low Level for Command Definitions

//Define Pins
int ENA = 3;        // "ENA" is pin of L298N motor driver; "3" is Arduino Digital PIN
int IN1 = 1;
int IN2 = 2;

int ENB = 6;
int IN3 = 4;
int IN4 = 5;

//Define Run variable
boolean run;
void setup() {

pinMode(ENA, OUTPUT);
pinMode(IN1, OUTPUT);
pinMode(IN2, OUTPUT);

pinMode(ENB, OUTPUT);
pinMode(IN3, OUTPUT);
pinMode(IN4, OUTPUT);

run = true;

}

//command sequence
void loop() {

if(run)                  // Set to Run the operation one time
{

delay(0);

enableMotors();          // Turn ON all the Gearbox DC motors

forward(1500);           // Move the Robot Car FORWARD                  
brake(0);

backward(1500);          // Move the Robot Car BACKWARD
brake(0);
 
turnLeft(0);           // Spin the Robot Car to the LEFT
brake(0);

turnRight(0);          // Spin the Robot Car to the RIGHT
brake(0);

disableMotors();         // Turn OFF all the Gearbox DC motors

run = true;             // Set to Run the operation one time by declaring Run as false
}

}

//Define Low Level H-Bridge Commands

//enable motors
void motorAOn()
{
digitalWrite(ENA, HIGH);
//analogWrite(ENA, 100);
}

void motorBOn()
{
digitalWrite(ENB, HIGH);
//analogWrite(ENB, 100);
}

//disable motors
void motorAOff()
{
digitalWrite(ENA, LOW);
}

void motorBOff()
{
digitalWrite(ENB, LOW);
}

//motor A controls
void motorAForward()
{
digitalWrite(IN1, HIGH);
digitalWrite(IN2, LOW);
}

void motorABackward()
{
digitalWrite(IN1, LOW);
digitalWrite(IN2, HIGH);
}

//motor B contorls
void motorBForward()
{
digitalWrite(IN3, HIGH);
digitalWrite(IN4, LOW);
}

void motorBBackward()
{
digitalWrite(IN3, LOW);
digitalWrite(IN4, HIGH);
}

//braking
void motorABrake()
{
digitalWrite(IN1, HIGH);
digitalWrite(IN2, HIGH);
}
 
void motorBBrake()
{
digitalWrite(IN3, HIGH);
digitalWrite(IN4, HIGH);
}

//Define High Level Commands

void enableMotors()
{
motorAOn();
motorBOn();
}

void disableMotors()
{
motorAOff();
motorBOff();
}

void forward(int time)
{
motorAForward();
motorBForward();
delay(time);
}

void backward(int time)
{
motorABackward();
motorBBackward();
delay(time);
}

void turnLeft(int time)
{
motorABackward();
motorBForward();
delay(time);
}

void turnRight(int time)
{
motorAForward();
motorBBackward();
delay(time);
}

void brake(int time)
{
motorABrake();
motorBBrake();
delay(time);
}