Jump to content
Sign in to follow this  
cubeberg

HC-SR04 Ultrasonic interfacing

Recommended Posts

I'm working on a wall-following RC car (Inspiration - http://letsmakerobots.com/node/696) with a Launchpad. I've purchased some HC-SR04 Ultrasonic Sensors off of eBay for cheap (~$6 USD each). I have a 5v battery pack that is running the LP and device and input into the LP works great. I used code found here (http://letsmakerobots.com/node/22970) to get started.

 

So my question is - I need to add a resistor or something to prevent the 5v from damaging the device - right? Will something simple like a 1k resistor be sufficient on the 5v input? There's a lot of information on interfacing 3.3v devices to a 5v MC, but not a lot the other way around. The LP is dirt cheap - but I'd rather not fry it.

 

FYI - I'm planning on doing a detailed write-up when I'm done - I'll make sure to post the code here. I've also purchased one of those cheap bluetooth adapters as well - in the hopes of controlling the car from my phone and switching between standard RC mode and wall following.

 

Thanks!

Share this post


Link to post
Share on other sites

One possibility (depending on how good/stable the 5v signal is) would be to use/(cut to pieces) a usb lead and use the USB plug on the launchpad that is designed to receive 5v. I believe that the +ve and gnd signals are the two outer connections.. (Yup.. This says that 1 is Vcc and 4 is GND.

 

Ive never done this as I have a few 3.3v LDO regulators I slap in when something is powered via dubious methods (Solar Panels scavenged from garden solar lights for example)

 

Researching 3.3v Zenner diodes is another possibilty but I don't know how stable this setup is when using a higher load (such as motors in a wall following car etc).

 

So if this was me (with my limited analog knowledge) I would go with a 3.3v LDO regulator and have the circuit on breadboard, if that wasn't an option then Id use the USB connector on the launchpad, if that wasn't an option Id look at a zenner and prepare for much head scratching and hopefully a eureka moment or two along the way.

 

Hope this helps,

 

Dan

Share this post


Link to post
Share on other sites

Sorry - I should have been more specific about the setup I was using. The launchpad's supply voltage is 5v (standard USB) - the board regulates the power supply to something that the MSP430 can handle. The HC-SR04 runs on 5v straight from USB (I tapped into two points next to the USB connector (Looks like TP1 and TP3 based on an image online) - the MSP430 runs off of the provided voltage - I haven't modified that.

So I'm straight on voltage supply - no issues there.

 

The place where I'm concerned about - the HC-SR04 has an Echo pin (output) that provides a high of 5V. The MSP430 picks up the 5v as a High for an input pin, but I'm pretty sure passing 5v into an input pin will damage the chip over time - I'm pretty sure the 5v is too high for the clamping diodes.

 

Sparkfun has a pretty extensive tutorial on sensor interfacing http://www.sparkfun.com/tutorials/65 - but it's geared towards a 5v MCU -> 3.3v Peripheral.

Share this post


Link to post
Share on other sites

Ahh gotya..

 

So the signal is only one way? 5v into 3.6V.. For a one way signal a voltage divider would do the job nicely. Lets try a little ascii diagram here....

 

Echo (5v)->
         |
         R1 (10k)
         |
         +------> MSP430 (3.3v)
         |
         R2 (20K)
         |
Gnd ------>

 

(Yay.. preview says that looks good enough for me)

 

The signal at the pin on the 430 would be (20k /(10k + 20k)) * 5 = 3.333333v

 

I gather there are things to be wary of for high frequency signals (parasitic capacitance or something) but thats getting into areas I don't feel comfortable that my knowledge is upto.. A load on the output can make a difference but going to an input pin on the 430 the load is negligible.

 

If the signal is two way then I think you may have to look into level shifters etc. Not got any experience with those though so I can't help on that. A zener diode should also work but although I have some zeners in my box I haven't actually used one yet so can't comment on that.

 

Hopefully this fits a little better.

 

P.S. just done a little googling and it looks as though a single resistor CAN work. What it does is it limits the current to something that the clamping diodes can handle. The calculation and research is more involved than a divider but should work.. Basically you would need to look at the 430 device data sheet and find the specs for the clamping diodes. You would need to know rated current, voltage drop over the diode. You would then need to pick a resistor that would restrict the current to less than that rated current (after allowing a safety margin). Personally this feels wrong. It would probably work fine but I don't like the idea of relying on a protection device to do the voltage conversion.

 

This page has some information I found interesting while researching.

Share this post


Link to post
Share on other sites

Dan - I tried the voltage divider the way you suggested and it seems to be working. Unfortunately I'm working without a multimeter right now - but I did throw an LED in the mix and it's obvious that the voltage is much lower.

 

I actually have two units running through P2.0 on a 2553 and it's working great! Seems to be a functional alternative to much more expensive units (I picked another up off of eBay for 3.99 including shipping yesterday). It's fairly consistent as long as surfaces are solid. I had my jacket next to the sensor which was throwing it off - it scatters the sound. I'm pretty sure this is the same for ultrasonic sensors though.

post-6158-135135522091_thumb.jpg

Share this post


Link to post
Share on other sites
wow, I like the rubber band.. how come I never thought of it. haha.

Thanks! It actually works great. I've been breadboarding with my LP for a couple of months now and it donned on me yesterday. Takes up a bunch of space on the BB, but it's held on nice and snug.

Share this post


Link to post
Share on other sites
Dan - I tried the voltage divider the way you suggested and it seems to be working. Unfortunately I'm working without a multimeter right now - but I did throw an LED in the mix and it's obvious that the voltage is much lower.

 

Thanks for letting me know that my plans weren't massively off :) As I say Im still learning so it all helps. While looking at your BB/LP combo layout something occurred to me. (A couple actually.. I also like the Rubber Band idea.. nice one, though I tend to have the MCU inserted into the breadboard with leads to the LP for programming, I can then power from the LP or batteries then and the space taken up is minimal).

 

LEDs have a forward voltage drop. If you know the drop of your LEDs, they (or it depending on the drop they have) can be used in series between the ECHO output and the 430 input pin. As a side effect it would indicate the state of the pin (depending on period/duty cycle etc) Don't know how it would affect trigger times on fast signals, but another string to add to that bow.

 

Anyways, thanks again.. nice looking setup. You have just convinced me to add ultrasonics to the "how can I bump the W.A.F. on these devices and buy em" list

Share this post


Link to post
Share on other sites
Dan - I tried the voltage divider the way you suggested and it seems to be working. Unfortunately I'm working without a multimeter right now - but I did throw an LED in the mix and it's obvious that the voltage is much lower.

 

Thanks for letting me know that my plans weren't massively off :) As I say Im still learning so it all helps. While looking at your BB/LP combo layout something occurred to me. (A couple actually.. I also like the Rubber Band idea.. nice one, though I tend to have the MCU inserted into the breadboard with leads to the LP for programming, I can then power from the LP or batteries then and the space taken up is minimal).

 

LEDs have a forward voltage drop. If you know the drop of your LEDs, they (or it depending on the drop they have) can be used in series between the ECHO output and the 430 input pin. As a side effect it would indicate the state of the pin (depending on period/duty cycle etc) Don't know how it would affect trigger times on fast signals, but another string to add to that bow.

 

Anyways, thanks again.. nice looking setup. You have just convinced me to add ultrasonics to the "how can I bump the W.A.F. on these devices and buy em" list

 

The zener diodes I'm using have a voltage drop as well. They allow me to minimize the input pins. I can only trigger one device at a time, but with ~50ms between pings - it's more than quick enough.

 

I wanted to add a visual indicator to the car when the sensors are active - that might actually be a way to do it without needing extra pins. I'll have to give it a try!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×