Robotic Car using Potentiometer PROGRAM?

Hey Arduino users! I am new to this forum so please be easy on me as I am also an amateur.

I have been working on this car robot for a while and Its almost complete except for my program. Basically its just suppose to control it self. When it hits a wall, it will back up and move a different direction.

So basically my robot car is basically 2 motors at the back with wheels attached to it. I got my breadboard and Aduino hooked up. I have a potentiometer up at the front. Basically what I am trying to do is

When the knob is set at the middle, both motors are moving forward. But once

i turn the knob left > Both motors go off except The right motor goes backward for 2 seconds and then both motors go on Forward.
i turn the knob right > Both motors go off except The left motor goes backward for 2 seconds and then both motors go on Forward.

How would I do this.

Much appreciated.

Hi,

I'm fairly new to this also but I'll do my best to help.

You don't say how the motors are connected but I'll assume you have some kind of motor shield.

Potentiometer - I'd imagine this can be read on an analog pin giving 0-255, this will help you determine left and right
Motors - Using the shield these will have a direction which can be set by HIGH, LOW when setting the pins up and a speed set by PWM 0-255, so by manipulating the two you will have full forward, reverse and speed on them
Bump detection - Might be easiest to use an IR sensor for this as you've not mentioned how you will do this, this can be read similar to the potentiometer, once you hit the desired distance to an object you kick in your reversing code.

The reversing can be done by switching either motor pin from its forward position to its reverse (ie. flipping its high/low setting), then setting its speed to 255, you can use the built in millis() function which will return the number of milliseconds the program has been running, simply store this value in a variable before you make the "turn" and then compare it on each loop until the difference is greater than 2000, then just flick the motor pins back to their forward setting and ramp them up to 255 speed.

If you're looking for code, I feel you will need to post schematics, I'd imagine others will ask too.

One quick thing, is this a 2 wheel drive car, if not you may have issues steering by just changing direction of the rear wheels.

Dave

Forgot to add, for now, maybe build things up slowly, forgot the potentiometer knob for now and just get it backing up in a predetermined way, then once you have that nailed, add the pot in to give you additional options.

Taking it further, you could use the pot to determine how far it backs up or what speed it backs up at, or maybe the speed of the car? Using it to determine which way it turns might be a waste of an analog input, you could achieve the direction of turn with a simple switch.

Hi,

I'm not sure from your description what the pot is used for:

When the knob is set at the middle, both motors are moving forward. But once

i turn the knob left > Both motors go off except The right motor goes backward for 2 seconds and then both motors go on Forward.
i turn the knob right > Both motors go off except The left motor goes backward for 2 seconds and then both motors go on Forward.

Is this set behavior, or do you intend for it to change as the vehicle drives itself?

You aren't suggesting that the pot is your sensor are you? How does the car sense the objects?