Go Down

Topic: JSN-SR04T long range ultrasonic wange finder Mininmum Range  (Read 33436 times) previous topic - next topic

thanhvdhn@gmail.com

Hello, Tim:
Can you tell the open angle of the ray, for avoid water float in the tank ?
Thank !

teckel

Hello, Tim:
Can you tell the open angle of the ray, for avoid water float in the tank ?
Thank !
You'd have to find the spec sheet for the sensor you are using.  But, it's sonar, so it's very wide.  Probably at least 45 degrees if not 90.

Tim
My hardware: Arduino, Teensy 2.0, Teensy 3.2 & custom ATmega328
My libraries: NewPing, LCDBitmap, toneAC, toneAC2, NewTone, TimerFreeTone
My Projects: https://dogblocker.com & https://baconorbeer.com
My beer: Great Lakes Brewing Co. Lake Erie Monster

scheng98

Hi Tim,

I used 3 JSN-SR04T sensors with newPing library on an Arduino UNO board. It worked fine except one big issue. Sometimes I got some floating readings such as 1.8, 1.56, 175m when there is nothing in front of the sensor, at least 5 meters. I used all default setting. I saw other folks ran into similar issue as well.

thanks for your help,

Steve

 // ---------------------------------------------------------
// ---------------------------------------------------------
#include <NewPing.h>
#define SONAR_NUM     3 // Number or sensors.
#define MAX_DISTANCE 200 // Max distance in cm.
#define PING_INTERVAL 33 // Milliseconds between pings.

unsigned long pingTimer[SONAR_NUM]; // When each pings.
unsigned int cm[SONAR_NUM]; // Store ping distances.
uint8_t currentSensor = 0; // Which sensor is active.

NewPing sonar[SONAR_NUM] = { // Sensor object array.
  NewPing(12, 11, MAX_DISTANCE),
  NewPing(10, 9, MAX_DISTANCE),
  NewPing(8, 7, MAX_DISTANCE)
};

void setup() {
  Serial.begin(115200);
  pingTimer[0] = millis() + 75; // First ping start in ms.
  for (uint8_t i = 1; i < SONAR_NUM; i++)
    pingTimer = pingTimer[i - 1] + PING_INTERVAL;
}

void loop() {
  for (uint8_t i = 0; i < SONAR_NUM; i++) {
    if (millis() >= pingTimer) {
      pingTimer += PING_INTERVAL * SONAR_NUM;
      if (i == 0 && currentSensor == SONAR_NUM - 1)
        oneSensorCycle(); // Do something with results.
      sonar[currentSensor].timer_stop();
      currentSensor = i;
      cm[currentSensor] = 0;
      sonar[currentSensor].ping_timer(echoCheck);
    }
  }
  // The rest of your code would go here.
}

void echoCheck() { // If ping echo, set distance to array.
  if (sonar[currentSensor].check_timer())
    cm[currentSensor] = sonar[currentSensor].ping_result / US_ROUNDTRIP_CM;
}

void oneSensorCycle() { // Do something with the results.
  for (uint8_t i = 0; i < SONAR_NUM; i++) {
    Serial.print(i);
    Serial.print("=");
    Serial.print(cm);
    Serial.print("cm ");
    Serial.print(sonar.ping_result);
    Serial.print(" pulse");
 
  }

  Serial.println();
}


teckel

Hi Tim,

I used 3 JSN-SR04T sensors with newPing library on an Arduino UNO board. It worked fine except one big issue. Sometimes I got some floating readings such as 1.8, 1.56, 175m when there is nothing in front of the sensor, at least 5 meters. I used all default setting. I saw other folks ran into similar issue as well.

thanks for your help,

Steve

 // ---------------------------------------------------------
// ---------------------------------------------------------
#include <NewPing.h>
#define SONAR_NUM     3 // Number or sensors.
#define MAX_DISTANCE 200 // Max distance in cm.
#define PING_INTERVAL 33 // Milliseconds between pings.

unsigned long pingTimer[SONAR_NUM]; // When each pings.
unsigned int cm[SONAR_NUM]; // Store ping distances.
uint8_t currentSensor = 0; // Which sensor is active.

NewPing sonar[SONAR_NUM] = { // Sensor object array.
  NewPing(12, 11, MAX_DISTANCE),
  NewPing(10, 9, MAX_DISTANCE),
  NewPing(8, 7, MAX_DISTANCE)
};

void setup() {
  Serial.begin(115200);
  pingTimer[0] = millis() + 75; // First ping start in ms.
  for (uint8_t i = 1; i < SONAR_NUM; i++)
    pingTimer = pingTimer[i - 1] + PING_INTERVAL;
}

void loop() {
  for (uint8_t i = 0; i < SONAR_NUM; i++) {
    if (millis() >= pingTimer) {
      pingTimer += PING_INTERVAL * SONAR_NUM;
      if (i == 0 && currentSensor == SONAR_NUM - 1)
        oneSensorCycle(); // Do something with results.
      sonar[currentSensor].timer_stop();
      currentSensor = i;
      cm[currentSensor] = 0;
      sonar[currentSensor].ping_timer(echoCheck);
    }
  }
  // The rest of your code would go here.
}

void echoCheck() { // If ping echo, set distance to array.
  if (sonar[currentSensor].check_timer())
    cm[currentSensor] = sonar[currentSensor].ping_result / US_ROUNDTRIP_CM;
}

void oneSensorCycle() { // Do something with the results.
  for (uint8_t i = 0; i < SONAR_NUM; i++) {
    Serial.print(i);
    Serial.print("=");
    Serial.print(cm);
    Serial.print("cm ");
    Serial.print(sonar.ping_result);
    Serial.print(" pulse");
 
  }

  Serial.println();
}


If others are having a similar problem, it's with a similar hardware or logic issue, not the library. My guess is that either you need to change the time between pings to be longer (your right at the bare minimum and there's differences between sensors). Or, your gust getting the normal random results from echos that can happen with ultrasonic sensors.

Change the ping interval to 200 and see what happens. Take the system outside and point all sensors towards the sky and see what happens. I think you'll diagnose it from there.
My hardware: Arduino, Teensy 2.0, Teensy 3.2 & custom ATmega328
My libraries: NewPing, LCDBitmap, toneAC, toneAC2, NewTone, TimerFreeTone
My Projects: https://dogblocker.com & https://baconorbeer.com
My beer: Great Lakes Brewing Co. Lake Erie Monster

geologic

For whoever is interested.
This is a link to the datasheet of JSN-SR04T.
That's interesting... it seems that we can play with a resistor and change the working mode from trig/echo to serial output.
Has anybody tried this last mode? 

killeriq

Hi Tim,

I used 3 JSN-SR04T sensors with newPing library on an Arduino UNO board. It worked fine except one big issue. Sometimes I got some floating readings such as 1.8, 1.56, 175m when there is nothing in front of the sensor, at least 5 meters. I used all default setting. I saw other folks ran into similar issue as well.

thanks for your help,

Steve

I find out that when the "board" was too close to other parts/boards i was getting this issue so maybe some interference and also some PINs doesnt work with it...but they are fine for DHT22 for example

tesalov

If You mean the sensor JSN-SR04T-2.0, I think I found the cause of the unstable data from the sensor. The sensor HC-04, which worked for me perfectly, on the contact trigger in the absence of a signal from the Arduino, the voltage is zero, and the impulse to start the measurement process were positive (LOW - HIGH - LOW). But when I connected the newly purchased sensor "JSN-SR04T-2.0" to the same scheme, it became to unstable results. With an oscilloscope I saw that the contact "trigger" a potential positive and equal to the supply voltage. Not having the code written to the microcontroller on the Board sensor, I can only assume that the signal "Trigger" from the Arduino must have a negative polarity, i.e., (HIGH - LOW - HIGH). I did this by changing three lines in the text file library from Tim. For this I apologize to Tim! In the attachment three photos show the situation with the signals on terminal "trigger".

teckel

If You mean the sensor JSN-SR04T-2.0, I think I found the cause of the unstable data from the sensor. The sensor HC-04, which worked for me perfectly, on the contact trigger in the absence of a signal from the Arduino, the voltage is zero, and the impulse to start the measurement process were positive (LOW - HIGH - LOW). But when I connected the newly purchased sensor "JSN-SR04T-2.0" to the same scheme, it became to unstable results. With an oscilloscope I saw that the contact "trigger" a potential positive and equal to the supply voltage. Not having the code written to the microcontroller on the Board sensor, I can only assume that the signal "Trigger" from the Arduino must have a negative polarity, i.e., (HIGH - LOW - HIGH). I did this by changing three lines in the text file library from Tim. For this I apologize to Tim! In the attachment three photos show the situation with the signals on terminal "trigger".
Sounds like a Chinese knockoff whose hardware was written incorrectly.
My hardware: Arduino, Teensy 2.0, Teensy 3.2 & custom ATmega328
My libraries: NewPing, LCDBitmap, toneAC, toneAC2, NewTone, TimerFreeTone
My Projects: https://dogblocker.com & https://baconorbeer.com
My beer: Great Lakes Brewing Co. Lake Erie Monster

virtuvas

If You mean the sensor JSN-SR04T-2.0, I think I found the cause of the unstable data from the sensor. The sensor HC-04, which worked for me perfectly, on the contact trigger in the absence of a signal from the Arduino, the voltage is zero, and the impulse to start the measurement process were positive (LOW - HIGH - LOW). But when I connected the newly purchased sensor "JSN-SR04T-2.0" to the same scheme, it became to unstable results. With an oscilloscope I saw that the contact "trigger" a potential positive and equal to the supply voltage. Not having the code written to the microcontroller on the Board sensor, I can only assume that the signal "Trigger" from the Arduino must have a negative polarity, i.e., (HIGH - LOW - HIGH). I did this by changing three lines in the text file library from Tim. For this I apologize to Tim! In the attachment three photos show the situation with the signals on terminal "trigger".
Hello,

since I also have the same board and exhibit odd behaviour, would it be possible to explain what exactly you changed in Tim's lib so that I can check and confirm?
Then probably setup a fork specifically for the wrongly done JSN-SR04T (seems it's easier to get this than the other compatible boards on ebay...)

cheers

V.

tesalov

Sounds like a Chinese knockoff whose hardware was written incorrectly.
I agree with you. But the problem should be solved. By the way, can you tell me where to buy JSN_SR04T not made in China?

tesalov

Hello,

since I also have the same board and exhibit odd behaviour, would it be possible to explain what exactly you changed in Tim's lib so that I can check and confirm?
Then probably setup a fork specifically for the wrongly done JSN-SR04T (seems it's easier to get this than the other compatible boards on ebay...)

cheers

V.
Unfortunately, the changes in the library need to contact its author.

tesalov

Hi all

On the sr04t board there is a little thing that can be adjusted with a screwdriver. What is the use of this thing....what can be adjusted??

Chris

The detail that You're talking about the transformer for amplifying the trigger signal from the microcontroller on the Board JSN-SR04T. Screwdriver moves the core to enter the transformer in resonance with the frequency sent by the microcontroller signals to the emitter of ultrasonic waves (40 kHz).

Go Up