Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Interfacing HC-SRo4 Ultrasonic Sensor to PC via PIC18F2550

Status
Not open for further replies.

Ajith Thampi Joseph

Newbie level 1
Newbie level 1
Joined
Mar 31, 2014
Messages
0
Helped
0
Reputation
0
Reaction score
0
Trophy points
0
Activity points
23
I am totally new to interfacing PIC to USB devices, i have worked on LCD interfacing, but not on real time PC interfacing. I need to know how can I trigger the Ultrasonic Sensor and read the distance and all to be done from the PC.. It's terribly important. SOmeone, please provide a help
 

There a better Ultra Sonic sensors which provide distance data directly in cms (string format) and with TTL UART output. They measure upto 750 cms. Use them.
 

If you want to use HC-SRo4 you have to know timers in PIC.
HC-SRo4 works on same principle same as old days sonar. To use it you have to send a 5ms pulse to its ping(trigger) pin. As soon as you make the pin high ultrasonic sensor send a wave. When the echo of this wave is received it makes its ECHO pin high.

To measure distance you have to use timer along with hardware interrupt, ie when interrupt is received you should stop the timer and calculate how much time has elapsed. This how you can measure the distance.
 

Pinging the sensor and measuring the distance can be done as 91divine explined . To interface it with PC, the easiest option would be to use uart communication(RS232) for which PC softwares can be written without much effort in VB.
 

Hello, I have the program for HC-SR04, which I had written to display the distance in a LCD display, for other project, that is why, i selected this sensor first place. I need to know how to make the output to USB control, i.e receiving the distance to PC via USB, so that I can use it in other project, which I am working on now..
 

Dear Ajith,
As i said, the easiest option i know is to use uart. You can use any uart port in you controller (Obviously, it should be present), use a usb to RS232 converter cable( Or you can add this circuit into your board if you donot want to use a converter cable).
On the PC side, the UART communication can be done easily through VB (I have used only VB6 and not any newer VB versions but the technique remains the same.)

Google 'RS232 comport in VB' and you can find a lot of stuff.

Or if you just want to see the data and nothing else, you can use hyperterminal which simply shows the RS232 data in PC
 
Last edited:

Dear Ajith,
As i said, the easiest option i know is to use uart. You can use any uart port in you controller (Obviously, it should be present), use a usb to RS232 converter cable( Or you can add this circuit into your board if you donot want to use a converter cable).
On the PC side, the UART communication can be done easily through VB (I have used only VB6 and not any newer VB versions but the technique remains the same.)

Google 'RS232 comport in VB' and you can find a lot of stuff.

Or if you just want to see the data and nothing else, you can use hyperterminal which simply shows the RS232 data in PC

Sir,
As i said, I donno USB interfacing.. So if u can provide me with the code
 

Dear Ajith,
You don't have to know the usb interfacing for this. And i dont have any sample codes. Btw which controller are you using?
What we should actually do in the controller here is uart communication. You can search google for the sample codes for uart interface for your controller.
Then to display this uart data in PC, we are using a usb to uart cable.

As you have already written code for HC-SR04 and LCD interface , i hope uart interface will be much simpler for you.!
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top