CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Waterproof Ultrasonic Module JSN-SR04T unstable values

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
bhas_r



Joined: 19 May 2009
Posts: 18

View user's profile Send private message Send e-mail

Waterproof Ultrasonic Module JSN-SR04T unstable values
PostPosted: Sat Aug 17, 2019 2:35 pm     Reply with quote

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: 9081
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sat Aug 17, 2019 4:04 pm     Reply with quote

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: 19195

View user's profile Send private message

PostPosted: Sun Aug 18, 2019 12:04 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sun Aug 18, 2019 12:41 am     Reply with quote

Right, but the comments have tons of suggestions to make it work.
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Sun Aug 18, 2019 1:36 am     Reply with quote

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

View user's profile Send private message Send e-mail

Thank you all
PostPosted: Sun Aug 18, 2019 1:45 am     Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group