1

Here's the code:

void loop() {
  while (1 == 1) {
    ObsLeft();
    while (SeeLeft < 50 || SeeLeft == 50) {
      Urong();
      ObsLeft();
      if (SeeLeft > 50) {
        Hinto;
        break;
      }
    }
  }
}

ObsLeft() analogReads the Infrared sensor input and Serial.prints it

Urong() makes the sumobot go backward

Hinto() stops the robot

SeeLeft is the analog value given by the Line Sensor (in my experience, white is 42, black is 800+)

The Problem:

When I run the program with the sensor seeing White, it makes the robot go backward, but when I move the bot so that the sensor sees Black, it still keeps going.

When I run the program with the sensor seeing Black, it does nothing.

6
  • 1
    while (1==1) is redundant. the loop() loops
    – Juraj
    Mar 7 '20 at 11:23
  • 2
    Hinto; is the address of the function. Hinto(); calls the function.
    – Majenko
    Mar 7 '20 at 11:59
  • 1
    Please post a full functioning code. Also I think you have forgotten the parenthesizes after Hinto, since it is a function. Maybe a copy paste error. Is 50 really a good value to distinguish between black and white, when white is 42 and black is over 800? In such a situation the analog value might easily go over 50 due to noise. Have you tried a threshold value a bit higher, maybe 100?
    – chrisl
    Mar 7 '20 at 11:59
  • 2
    while (SeeLeft < 50 || SeeLeft == 50) { is same as while (SeeLeft <= 50) {
    – Juraj
    Mar 7 '20 at 12:41
  • Usually, in arduino programming while loops should rather be ifstatements and leave looping to the loop() function. This is a good example. As long as there's no definition of variables (SEELEFT) and no hint where, why and how they ever change, any more help is questionable. Mar 7 '20 at 15:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.