Electronics > Electronics

Sonar and programing selection?

<< < (2/2)

Brandon121233:
No, what you have is fine- because you are using an AVR Microcontroller, and the language is similar. I wouldnt have been able to help you as much if you had been using a Baisic Stamp or other kind of Microcontroller. Let me know when you get the sonar, and I can help guide you how to do it.

Admin:
I think in the future Ill write sonar code for the $50 robot.

Ill give you a quick rundown so you can start reading up on it . . .

Send a single pulse to the sonar like you would to a servo (code that you already have).

Then use a timer (a feature of the atmega8, just look up the manual for it) to measure the time it takes for the sonar to send a signal back to your microcontroller. You will need a second digital output pin set for input (servos use digital output pins set for output).

Knowing the speed of sound in air, and the time the sonar took to send the pulse, calculate the distance the object is away from the robot.

sorry for not being more help, Ill write some code when I have more time . . .

Brandon121233:
Admin- if NOOBinDistress is getting the LV-MaxSonar (which I highly reccomend for beginners) then he dosent need to do that because the sonar module itself does the calibration and calculating the distance, all that is necessary is to convert the voltage or ASCII signal into inches or feet.

Admin:
hmmmm interesting (very useful!) output options . . . i would perfer the analog for this sensor tho . . .

Three interfaces (active simultaneously):
Serial output: asynchronous, logic-level, inverted, 9600 bps
Analog output: 10 mV/inch
Pulse width output: 147 us/inch

Brandon121233:
Yeah thats what I'm saying, its very very easy for even a beginner to write 10 lines of code, and to have it work, as opposed to having to calculate the time pulses to run the emitter, and calculate the time between pulses to convert that into inches or feet. It's 10X as easy and frees up the MCU from having to pulse the emitter and calculate everything.

Navigation

[0] Message Index

[*] Previous page

Go to full version