Arduino '{' Error Message

I wonder that, too. He seemed to want a function to do that. I don't know why. Maybe to add to it later.

Who is "he"?

Edit:Oops me.

It will "work" in the academic sense...but it accomplishes nothing.

@anon73444976 , Sorry, they (learning to mind the pronoun), the OP.

1 Like

I'm trying to make an obstacle avoiding robot with an Arduino Uno, a motor driver, an ultrasonic sensor, and 2 servo motors and I thought the NewPing code would work

It appears you are just shooting in the dark trying to develop this sketch. You need to understand the programming language C++ and have a good specification of what you want to accomplish.

Trust me I'm doing my best to understand as much as I can about coding. I just figured I might try something new since I was having trouble with another ultrasonic sensor code.

I get that it is overwhelming. But to develop a functional robot you are also going to have to eliminate the delays. Think about it this way, a delay() means just what it says. NOTHING happens which means you can't monitor the ultrasonic sensor during the delays or any section of code which has multiple delays. Like this section which has 1.6 seconds of delays:

      myservo1.write(90);
      delay(400);
      myservo1.write(100);
      delay(400);
      myservo2.write(90);
      delay(400);
      myservo2.write(100);
      delay(400);

You need to use millis() and a state machine to really make the code work correctly. Study the following tutorials:

State Machine

BlinkWithoutDelay

Arduino Multiple Things

Several Things at a Time

By coding it this way you can interrupt your movement sequences at any time if you detect an obstacle.

Thanks looks like I've got something to work on.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.