LabVIEW Interface for Arduino Discussions

Showing results for 
Search instead for 
Did you mean: 
Reply

!! Arduino Uno + HC-SR04 Ultrasonic sensor + labview Help!!

Solved!
Go to Solution

!! Arduino Uno + HC-SR04 Ultrasonic sensor + labview Help!!

Hi Everyone

I would like to make a simple distance/range finding program using Labview, the Arduino and the very popular HC-sr04 ultrasonic sensor.

The sensor has a built in control circuit that sends out 8 pulses at 40khz when a trig pin is momentarily high(Ideally there should be a 10us trigger

pulse followed by a 100ms(low) delay); the time taken for the pulse to return to the echo pin of the sensor is linearly proportional to the distance.

The value of time in (us) can then be converted to cm or inch using the following conversions uS / 58 = centimeters ; uS / 148 =inch.

I'm having some trouble programming the Arduino with Labview, I know the Arduino has 3 counter/timers however I'm not sure how to access them using Labview I would like to send out a TTL pulse as described above using one counter, and then use a second counter to count the TTL pulses back to the sensor.

also as I have the Arduino C program and library's for the ultra sensor, is it possible to use that code with Labview.

Any help with this would be great.

Thanks

sensor datasheet: http://elecfreaks.com/store/download/HC-SR04.pdf

0 Kudos
Message 1 of 61 (72,656 Views)
Reply
0 Kudos

Re: !! Arduino Uno + HC-SR04 Ultrasonic sensor + labview Help!!

Is there a way to include the arduino ultrasonic.h library in labview (call the C code from a text file using the read from file vi maybe ??) or add the library to the ( LVIFA_Base.pde) file. I'm really having problems using labview with this sensor, I also have a ni usb-6009 and couldn't get an accurate value (I used a modified version of the mydistance example for the myDAQ (https://decibel.ni.com/content/docs/DOC-17678)). The sensor is not the problem as I am getting very accurate values using C code.

0 Kudos
Message 2 of 61 (467 Views)
Reply
0 Kudos
Solution
‎05-09-2012 12:38 AM

Re: !! Arduino Uno + HC-SR04 Ultrasonic sensor + labview Help!!

I added to the LabviewInterface.pde the library of the Ultrasonic Sensor, and added a new case (0x34) to call the function and measure the distance, here is the link to download the edited labviewinterface:

http://dl.dropbox.com/u/8067369/LabVIEWInterface.pde

And here is the new LabView function block:

http://dl.dropbox.com/u/8067369/Ultrasonic%20Sensor.rar

Just open an example (Analog Read pin example could be), delete the digital read block, add the new ultrasonic Sensor block, create a control for the trigger, echo and output distance, add a time delay (1 second for each measure should be good) as shown in the picture:

Ultrasonic Sensor diagram.jpg

Things to keep in mind:

The ultrasonic library for that sensor only works with Arduino 0023, I have tried with 1.0 without success.

I couldnt find any button to upload files besides the image directly to the forum so I uploaded it to dropbox...

Message 3 of 61 (467 Views)

Re: !! Arduino Uno + HC-SR04 Ultrasonic sensor + labview Help!!

You have to click on "Use advanced editor" to upload files.  Also, use a .zip for archives so that it is accessible to everybody.

0 Kudos
Message 4 of 61 (467 Views)
Reply
0 Kudos

Re: !! Arduino Uno + HC-SR04 Ultrasonic sensor + labview Help!!

Hi egaruz89

Thank you for the reply and help, unfortunately I can't open the links you put up. If you could repost them using NathanB's method I would be very grateful.

Thanks again

0 Kudos
Message 5 of 61 (467 Views)
Reply
0 Kudos

Re: !! Arduino Uno + HC-SR04 Ultrasonic sensor + labview Help!!

Hi egaruz89

Thank you so much this works perfectly. The dropbox link has an extra prefix added to it, which was giving a broken link error.

also if you would like to use the ultrasonic library with arduino 1.0, you have to change the cpp file for the ultrasonic library from #include WProgram.h

to #include Arduino.h and it should compile then.

Thanks again for all you help, I'm sure this will be a very popular vi, it should be included in the next LIFA update.

0 Kudos
Message 6 of 61 (467 Views)
Reply
0 Kudos

Re: !! Arduino Uno + HC-SR04 Ultrasonic sensor + labview Help!!

I'm glad it helped you. I fixed the dropbox links.   And thanks for the advice with the ultrasonic library for Arduino 1.0, will be easier to do everything with only one compiler Smiley Tongue

0 Kudos
Message 7 of 61 (467 Views)
Reply
0 Kudos
Highlighted

Re: !! Arduino Uno + HC-SR04 Ultrasonic sensor + labview Help!!

Hello egaruz89 & Robwal

I'm trying to use that example but doesn't work :C in the case 0x34 show a error to compilated, I have the sensor HC-SR04 with arduino Mega and uno board, whatever that I tried fail, so I did everything you said.

this is my fail.

case 0x34: // Ultrasonic Sensor

     Serial.write(ultrasonic.ranging('CM'));

      break;

LabVIEWInterface:527: error: 'class Ultrasonic' has no member named 'ranging'

Pleaseee Help me :C

0 Kudos
Message 8 of 61 (467 Views)
Reply
0 Kudos

Re: !! Arduino Uno + HC-SR04 Ultrasonic sensor + labview Help!!

Hi egaruz89

Can you please post a labview10 version of the example?

We need to resend the Labviewinterface.pde to the arduino?

We can not use the arduino software 1.0 to resend this  Labviewinterface.pde to the board?

I am working with sharp IR sensor, do you know if this ultrasonic sensor is more accurate?

I have some problem with reflective surfaces...

best regards

cpalha

0 Kudos
Message 9 of 61 (467 Views)
Reply
0 Kudos

Re: !! Arduino Uno + HC-SR04 Ultrasonic sensor + labview Help!!

Hello,  

As I'm short on time, I will give you a Pdf with instructions on how to create the block yourself (so u can do it in your labview version). Sadly the instructions are in spanish, and I dont have time to translate it, but I suppose with an online translator will be enough in the case you don't know spanish. 

Yes, you need to resend the Labviewinterface.pde to the board, but if you are using a different sensor, then a different library will be needed, which means then that you will have to change a bit the code. Probably is not too complicated. Just try to understand how you sensors library deals with the timing and outputs.

You can use any arduino IDE to send the files to the board.

all the best,

egaruz89

Message 10 of 61 (467 Views)