Go Down

Topic: Trying to control motor with Ping ultrasonic sensor (Read 2 times) previous topic - next topic

Chritofa44

ok its working the only problem is that i cannot switch the direction of the continually spinning motor, which i need to in the if statement can you helpme with this?

wildbill

I'm sure someone could, but you'll need to provide some more detail about your hardware and how it's wired up. Your latest code, if you've changed it, would be needed too.

teckel


ok its working the only problem is that i cannot switch the direction of the continually spinning motor, which i need to in the if statement can you helpme with this?


You're going to have a really hard time controlling a bot using that sketch.  Using pulseIn is never a good idea.  You really need to move to an interrupt-driven paradigm to create projects that work in the real world.  It may take some getting used to, but it's the way to go long-term.  Instead of your current ultrasonic sensor code, you should use the NewPing library and the timer interrupt method.  There's an example sketch that shows how to use it.

Also, shift from using delay statements to timer-triggered events.  This will help you move from the "hello world" phase to a finished project.

Tim
Arduino - Teensy - Raspberry Pi
My libraries: NewPing - LCDBitmap - toneAC - NewTone - TimerFreeTone

Go Up