LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

HC-SR04 with Arduino and NI-USB

Hello,

 

I am trying to measure water level in a tank using HC-SR04. First, I tried using Arduino UNO but it always showed a constant value (48). After that, I tried NI-USB 6009 and NI-DAQmx. It also showed error. I have attached both VI here. Would any one help me to solve the problem, please?

 

Thanks in advance.

Message 1 of 13
(4,518 Views)

I'm not familiar with your NI product nor your ultrasonic sensor. Your vi is in error because you are selecting a analog input terminal 0 (Dev3/ai0) to perform counter measurements and generation. If you right click the input to the create channel vi's (after deleting your present input terminals) and create a constant it will have a drop down that will be specific to the task you are trying to perform. A quick look at the specifications shows that you only have 1 counter available for that 6009. Help>>example finder can be your best friend. 

 If it were me I would not even worry about LabVIEW at the moment. If you google HC-SR04 with Arduino there are plenty of examples. I would get that to work first.

Now Using LabVIEW 2019SP1 and TestStand 2019
Message 2 of 13
(4,480 Views)

Hello GovBob,

Thanks for your reply. I already tried and attached a VI which is coded using Arduino. But that code always showed a constant output (48). I can't understand why?

Would you take a look?

0 Kudos
Message 3 of 13
(4,467 Views)

I don't have the LIFA toolkit for LabVIEW 2014 nor do I have the sensor you are using. I would first verify that you have a working sensor properly connected to the Arduino. You could just copy this person's .ino code to your Arduino IDE and upload it to your arduino device. Open the Arduino's IDE serial monitor and confirm that you have a working sensor. 

Now Using LabVIEW 2019SP1 and TestStand 2019
Message 4 of 13
(4,458 Views)

Hello, Mr. GovBob,

 

Thanks for your reply. I tried your suggested Arduino code and it really works well. But the problem is, I am looking for a LabView code and I will use that in another LabView coding (My main LabView Code) as a sub code/sub VI. My sensors are working sensor. So if you have any other idea, that will be appreciatable...

 

Thanks in advance.

0 Kudos
Message 5 of 13
(4,454 Views)

OK now go to Help>>Find examples and type in 'serial' in the search tab. Find the "Simple Serial.vi". You are going to change it so save it under a different name. Since you only need to read from the arduino, open the block diagram and delete the flat sequence structure and control with the timer in it. Delete the visa write and it's associated constant. Delete the instrument property node with the bytes at port in it and its indicator. Use Ctrl B to remove broken wires. Drag the Visa read over so you can put a while loop around it and its associated indicator. Nothing else but the Visa read and the Response indicator should be in the loop. Right click the loop condition (stop sign) input and create control. Wire the Visa resource and error wire into the visa read vi. Right click the byte count input of the visa read and create a constant with a large value. Let's say 500. On the Visa Configure serial port vi right click on the enable termination character, create a constant and set it to true. Go to the front panel and use the same settings that the Arduino IDE serial monitor was using including the same Visa resource name as was listed. (guessing 9600, 8, none, 1, none). MAKE SURE you close the Arduino IDE serial monitor. Run this new vi and see what happens. 

Now Using LabVIEW 2019SP1 and TestStand 2019
Message 6 of 13
(4,451 Views)

Hello, Mr. GovBob,

Thanks for your continuous support and suggestion. I made a VI according to your above guidelines. I attached the VI here. Sorry to say, it does not work. Would you take a look, please?

Download All
0 Kudos
Message 7 of 13
(4,437 Views)

The vi you saved and posted has the communications port set to com1. Is this the same com port that is listed when using the arduino IDE serial monitor? You need to make sure that you select the com port where the arduino is. I would need to see the full description of the error. 

What version of LabVIEW? 2014?

What version of Arduino IDE?

Which Arduino are you using? (Uno R3, Mega, Nano etc.)

Which version of NI VISA are you using. (Open Measurement and Automation Explorer MAX and click on software to check)

 

So the code on the arduino works. The communication between the arduino and LabVIEW does not work. LabVIEW errors out at the configure serial port vi. There is some setting that is wrong there. 

Now Using LabVIEW 2019SP1 and TestStand 2019
Message 8 of 13
(4,432 Views)

Quick research during lunch I found that the LINX toolkit already has support for the HC-SR04. Go through their tutorials especially paying attention to the beginning tutorials to make sure you get their software toolkit loaded correctly. This toolkit was made as a replacement for LIFA toolkit by the same developer. 

Now Using LabVIEW 2019SP1 and TestStand 2019
Message 9 of 13
(4,426 Views)

Hello, Mr. GovBob,

Thanks for your continuous help and guidelines. Yes, last time I have some communication problem with Arduino and LabView. I have attached a new picture of Error.

Answer of your questions:

1. I use LabView 2014

2. Arduino IDE 1.8.3

3. Arduino UNO

4. NI VISA Runtime 5.1.2

0 Kudos
Message 10 of 13
(4,416 Views)