View previous topic :: View next topic |
Author |
Message |
bhas_r
Joined: 19 May 2009 Posts: 18
|
Waterproof Ultrasonic Module JSN-SR04T unstable values |
Posted: Sat Aug 17, 2019 2:35 pm |
|
|
Hi all,
i am using Waterproof Ultrasonic Module JSN-SR04T sensor, which gives random values for same position. even its fixed stable, the output is varying.
looking for any correction.
i am using the same program which is used to interface HC-SR04 sensor, this sensor gives stable value. i need to use waterproof sensor for my project
Code: |
#include <16F877A.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock = 8000000)
#use i2c(Master,Fast,sda=PIN_C4,scl=PIN_C3,restart_wdt)
#include <i2c_Flex_LCD.h> // LCD driver file
#use fast_io(B)
int8 check;
unsigned int16 i, distance;
void main(){
output_b(0);
set_tris_b(2); // Configure RB1 as input
lcd_init(); // Initialize LCD module
setup_timer_1 (T1_INTERNAL | T1_DIV_BY_2); // Configure Timer1 module
set_timer1(0); // Reset Timer1
lcd_putc('\f'); // LCD Clear
lcd_gotoxy(4, 1); // Go to column 4 row 1
lcd_putc("Distance:");
while(TRUE){
check = 0;
i = 0;
output_low(PIN_B0);
delay_us(2);
output_high(PIN_B0);
delay_us(10);
output_low(PIN_B0);
set_timer1(0); // Reset Timer1
while(!input(PIN_B1) && (get_timer1() < 1000));
if(get_timer1() > 990)
check = 1; // Timeout error
set_timer1(0); // Reset Timer1
while(input(PIN_B1) && (i < 25000))
i = get_timer1(); // Store Timer1 value in i
if(i > 24990) // Out of range error
check = 2;
if(check == 1){
lcd_gotoxy(3, 2); // Go to column 3 row 2
lcd_putc(" Time Out ");
}
if(check == 2){
lcd_gotoxy(3, 2); // Go to column 3 row 2
lcd_putc("Out Of Range");
}
else{
distance = i/58; // Calculate the distance
lcd_gotoxy(3, 2); // Go to column 3 row 2
lcd_putc(" cm ");
lcd_gotoxy(6, 2); // Go to column 6 row 2
printf(lcd_putc,"%3Lu",distance);
}
delay_ms(1000);
}
}
|
_________________ Thanks and Regards
R.Bhaaskar |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9229 Location: Greensville,Ontario
|
|
Posted: Sat Aug 17, 2019 4:04 pm |
|
|
I was curious, googled the module and one hit says to increase the trigger from 10us to 20us for more stable readings. While written for another micro, it'd be easy yo test.
I cannot confirm/deny that will help as I do not have that module though.
I'm assuming you use PIN_B0 for the 'trigger' ? IF so, change the delay value and see what happens. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19520
|
|
Posted: Sun Aug 18, 2019 12:04 am |
|
|
Do you have the version 1, or 2 module. If the latter, this YouTube link
suggests this is a inherent problem with these modules:
<https://www.youtube.com/watch?v=N42Y-QOqwtA>
Also:
<https://forum.arduino.cc/index.php?topic=544339.0>
It looks as if the later version, may have an issue.... |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Aug 18, 2019 12:41 am |
|
|
Right, but the comments have tons of suggestions to make it work. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19520
|
|
Posted: Sun Aug 18, 2019 1:36 am |
|
|
Yes, though they all seem to think the V2 is less stable than the V1 was...
Even with the fixes in place they are recording continuous small variations.
Obviously depends just how bad the fluctuation actually 'is'... |
|
|
bhas_r
Joined: 19 May 2009 Posts: 18
|
Thank you all |
Posted: Sun Aug 18, 2019 1:45 am |
|
|
temtronic wrote: | I was curious, googled the module and one hit says to increase the trigger from 10us to 20us for more stable readings. While written for another micro, it'd be easy yo test.
I cannot confirm/deny that will help as I do not have that module though.
I'm assuming you use PIN_B0 for the 'trigger' ? IF so, change the delay value and see what happens. |
I changed the delay from 10 to 20 us.
It looks good, value is looks stable too.
I will check fully then reply as soon as possible. _________________ Thanks and Regards
R.Bhaaskar |
|
|
|