problem with understanding the programme

hii..i m making line following robot bt now i want to add ultrasonic sensor and robotic arm into it then how should i programme my robot plz guide me..it is possible or not?? :(

Of course it's possible: if you have already designed, programmed and built a line follower it will be really easy for you.

problem with understanding the programme

What program? You have not posted any program.

...R

i have programme only of 3 sensors…bt i have no any idea about the programming of ultrasonic and robotic arm…and also dnt no how to add that programming in my 3 sensors programming…my programming of line follower is given below…

final_programming.ino (1.43 KB)

Use code tags to post your code. It is the left most formatting symbol </> .
Attached files is a hazzle. Hard to read on a mobile device, and not everyone want to fill up their pc with strangers code just to look at it.

nishalohar03: i have programme only of 3 sensors..bt i have no any idea about the programming of ultrasonic and robotic arm..

You wrote that line follower, I'm sure you can figure out how to add an ultrasonic sensor. There's tons of examples around.

bt it is difficult to understand the programming of ultrasonic sensor..

nishalohar03: bt it is difficult to understand the programming of ultrasonic sensor..

What don't you understand ? Have you looked at any example code ? What sensor do you have ?

nishalohar03: bt it is difficult to understand the programming of ultrasonic sensor..

No it's not it's dead easy if you use the NewPing library which has a really simple example.

tnx for telling about newping library..n i m using 3 IR sensors n HC-SR04 ultrasonic sensor

Hi, Why are you using 2 threads to find two different problems with the same project? In the other thread you state;

1st try after appling programme my robot follows the line properly bt after some days..he only rotates clockwise after appling the same programme now what should i do...?

Here you want to add ultrasonics!!!!!! Can I suggest you get your robot working properly before going off adding extra bits.

Tom..... :o :o :o

can some one tell me is it my programming for 3 sensors line follower is right or wrong...??? coz my robot doesn't following the line...

/------ Program for Line Follower Robot using Arduino----- */ /-------defining Inputs------*/

define LS 2 // left sensor

define RS 3 // right sensor

define MS 8 // right sensor

/-------defining Outputs------/

define LM1 4 // left motor

define LM2 5 // left motor

define RM1 6 // right motor

define RM2 7 // right motor

void setup() { pinMode(LS, INPUT); pinMode(RS, INPUT); pinMode(LM1, OUTPUT); pinMode(LM2, OUTPUT); pinMode(RM1, OUTPUT); pinMode(RM2, OUTPUT); } void loop() { if(digitalRead(LS) && !(digitalRead(MS)) && (digitalRead(RS))) // Move Forward { digitalWrite(LM1, HIGH); digitalWrite(LM2, LOW); digitalWrite(RM1, HIGH); digitalWrite(RM2, LOW); }

if(!(digitalRead(LS)) && !(digitalRead(MS)) && (digitalRead(RS))) // Turn right { digitalWrite(LM1, LOW); digitalWrite(LM2, LOW); digitalWrite(RM1, HIGH); digitalWrite(RM2, LOW); }

if (digitalRead(LS) && !(digitalRead(MS)) && !(digitalRead(RS))) // turn left { digitalWrite(LM1, HIGH); digitalWrite(LM2, LOW); digitalWrite(RM1, LOW); digitalWrite(RM2, LOW); }

if(!(digitalRead(LS)) && !(digitalRead(MS)) && !(digitalRead(RS))) // stop { digitalWrite(LM1, LOW); digitalWrite(LM2, LOW); digitalWrite(RM1, LOW); digitalWrite(RM2, LOW); } if((digitalRead(LS)) && (digitalRead(MS)) && (digitalRead(RS))) // stop { digitalWrite(LM1, HIGH); digitalWrite(LM2, LOW); digitalWrite(RM1, LOW); digitalWrite(RM2, HIGH); } }

can some one tell me is it my programming for 3 sensors line follower is right or wrong...??? coz my robot doesn't following the line...

Clearly, by your own definition, it's wrong. Also it's missing debug prints that would tell you why it is behaving as it is, and it is missing code tags, which means we can't trust what we can see.

Also false comments is a bad start to get help.

nishalohar03:

define LS 2 // left sensor

define RS 3 // right sensor

define MS 8 // right sensor

pinMode(LS, INPUT); pinMode(RS, INPUT);

2 left sensors and 1 right sensor? Could it be the last one is Middle Sensor? And where is the pinMode for it? It is not cruicial as pins default to inputs.

if(digitalRead(LS) && !(digitalRead(MS)) && (digitalRead(RS))) // Move Forward

if(!(digitalRead(LS)) && !(digitalRead(MS)) && (digitalRead(RS))) // Turn right

if (digitalRead(LS) && !(digitalRead(MS)) && !(digitalRead(RS))) // turn left

Does your sensors return true/high or false/low when the line is detected? It seems to be a little of both here.

Usually to turn left you run your right motor forward. You do the opposite. But it all depends on how you have everything connected.

What is your second stop? Left motor1 and right motor2?

Hi, It would make reading your code easier and more logical if at the top of the loop you read ALL your inputs and stored them in variables. Then used the variables in your IF statement.

At the moment if any of your sensors changes state halfway through the loop, then all sorts of things can happen. If you use the same data ALL the way through your IF statements, it will be more stable. Like this as example; I am assuming that LOW input from the sensors, means that the black line has been detected.

// Assuming LOW means blackline detected.
bool LS;
bool MS;
bool RS;
#define LeftSensorPin 2      // left sensor
#define RightSensorPin 3      // right sensor
#define MiddleSensorPin 8      // middle sensor


void setup() {
  // put your setup code here, to run once:

}

void loop() {

  LS = digitalRead(LeftSensorPin);
  MS = digitalRead(MiddleSensorPin);
  RS = digitalRead(RightSensorPin);

  if (LS &&  !MS && RS) //centred
  {
    //    forward
  }
  if (LS && !MS && !RS) //drifted left
  {
    // turn right
  }
  if (RS && !MS && !LS) //drifted right
  {
    //turn left
  }
  if (!LS && !MS && !RS) //lost
  {
    // stop
  }
  if (LS && MS && RS) //lost!!!
  {
    // stop
  }
}

Easier to read and debug. Tom... :)

ya..its too easy to understand now properly..tnx nisha... :)