Page 1 of 2

Distance Sensors HC-SR04, JSN-SR04T and more

Posted: 12 Aug 2017, 15:24
by LisaM
I'm going to revamp PO13 to include a whole new set of distance sensors using this library: https://bitbucket.org/teckel12/arduino- ... /wiki/Home
This should make maintaining the plugin a lot easier, since most functions are now part of the library.
I have an HC-SR04 and a JSN-SR04T, the others i cannot test...
Alternative to revamping P013 is to build a new plugin, but that wouldn't make much sense.

Re: Distance Sensors HC-SR04, JSN-SR04T and more

Posted: 13 Aug 2017, 10:01
by rol-rider
Great !
I ordered this sensor.(JSN-SR04T)
thank you for your work.

Re: Distance Sensors HC-SR04, JSN-SR04T and more

Posted: 13 Aug 2017, 11:59
by Shardan
That's good, thanks for the info.

I'll put revamping the HC-SR04 Wiki on hold until the new plugin is merged.


Regards
Shardan

Re: Distance Sensors HC-SR04, JSN-SR04T and more

Posted: 13 Aug 2017, 23:26
by LisaM
Please let me know if anyone is using the STATE mode, state mode means that the distance is below the threshold set in the form earlier. When state mode is reached, distance below threshold, then a sensor switch event is send.

If nobody is using it, i can as well take it out...

Re: Distance Sensors HC-SR04, JSN-SR04T and more

Posted: 13 Aug 2017, 23:44
by Domosapiens
Lisa,
it is my intention to use State mode with the HC-SR04.
To check if my garage doors are fully opened.
So please don't remove this functionality.

Re: Distance Sensors HC-SR04, JSN-SR04T and more

Posted: 14 Aug 2017, 12:45
by Shardan
I'm using state mode with a HC_SR04
just for light switching in the basement.
It's far mor precise as PIR's

Re: Distance Sensors HC-SR04, JSN-SR04T and more

Posted: 14 Aug 2017, 12:56
by LisaM
Ok, i'll leave it in there. State is actually a 10-times per second check if the distance value has fallen below the threshold set in the form. Strangely enough the measured values in a 10-times per second loop are not broadcasted to the HA server, probably to not overload the HA server with messages.

I'm also going to add a metric(cm) vs imperial(inch) switch for our UK/US friends over here. ;)

Re: Distance Sensors HC-SR04, JSN-SR04T and more

Posted: 14 Aug 2017, 13:34
by LisaM
Shardan wrote: 14 Aug 2017, 12:45 I'm using state mode with a HC_SR04
just for light switching in the basement.
It's far mor precise as PIR's
Did you try the new microwave radar (RCWL-0516) yet?

Re: Distance Sensors HC-SR04, JSN-SR04T and more

Posted: 14 Aug 2017, 13:42
by papperone
LisaM wrote: 14 Aug 2017, 13:34
Shardan wrote: 14 Aug 2017, 12:45 I'm using state mode with a HC_SR04
just for light switching in the basement.
It's far mor precise as PIR's
Did you try the new microwave radar (RCWL-0516) yet?
I tested and well, they looks great in the beginning but... they are too powerful and do activate even when the movements are behind brick walls, glass, and concrete (like pavement between 2 floors).
They can be great for probably some application but as I wanted to use to switch light as well, it was switching even when someone was walking the upper floor, or in the next room when the room with the sensor was even with closed door!
Unless we build some sort of "screen" to stop microwaves go 360° form the sensor IMHO they are not ok as a light switch actuator (unless you want exactly this, turn on the light if the sensor capture a movement no matter where it is in all directions!)

Re: Distance Sensors HC-SR04, JSN-SR04T and more

Posted: 14 Aug 2017, 15:31
by Shardan
I have 5 or 10 RCWL0516 microwave sensors in the shelf.
Nice for some purposes but for lights in the basemet it is cruel.
It switches lights on if a dog in the floor above moves around the sensor and such.

It is possible to reduce sensivity, i know - but if i put sensivity down to a level where the sensor
isn't triggered from floor above or other side of the wall, it does not work for lighting at all.

Besides that, microwave sensors are not allowed in all countries and even if allowed they might be
forbidden in specific areas like airports and radar stations.

The HC-SR04 runs with a focused direction so i can go along the basement shelves and the light is
wandering in parallel... better then any microwave or PIR.
Another thing i want to use HC-SR04 with threshold for in the future is a "small area presence".
If i'm at home at all is detected my bluetooth, FHEM has a nice function for it and the raspberry 3 has bluetooth.
But i want to detect if i'm sitting at my desktop (printer is on, and desktop lights at night) or not.
A SR-04 hidden under the desktop does this job, i've tested it.

Re: Distance Sensors HC-SR04, JSN-SR04T and more

Posted: 14 Aug 2017, 16:58
by LisaM
I've ordered some and are considering using it at ground floor directed downwards. That should eliminate the triggers from the next room.
I'm done rewriting it, test phase is next...

Re: Distance Sensors HC-SR04, JSN-SR04T and more

Posted: 14 Aug 2017, 17:29
by papperone
LisaM wrote: 14 Aug 2017, 16:58 I've ordered some and are considering using it at ground floor directed downwards. That should eliminate the triggers from the next room.
I'm done rewriting it, test phase is next...
Please let me know as per my test the micrwave irradiates from the modules in all directions no matter how I position it :(
I know there are similar modules with different chipset and some kind of shielding on one side of the board in order to "cut" waves to goin that direction (so they cover only 180°)

Re: Distance Sensors HC-SR04, JSN-SR04T and more

Posted: 14 Aug 2017, 19:49
by Shardan
papperone wrote: 14 Aug 2017, 17:29
LisaM wrote: 14 Aug 2017, 16:58 I've ordered some and are considering using it at ground floor directed downwards. That should eliminate the triggers from the next room.
I'm done rewriting it, test phase is next...
Please let me know as per my test the micrwave irradiates from the modules in all directions no matter how I position it :(
I know there are similar modules with different chipset and some kind of shielding on one side of the board in order to "cut" waves to goin that direction (so they cover only 180°)
Definitely. These sensors are omnidirectional.
I can make it work if i go to a wall made from ferroconcrete.
Anyways it should be possible to shield the antenna if you cover two or three sides
of a case with aluminium foil for example. But don't put the foil too near to the module,
keep some centimeters distance. Maybe use a plastic case, mount the module at the mid of the lid and cover bottom and sides for shielding...
I didn't test that yet.

Regards
Shardan

Re: Distance Sensors HC-SR04, JSN-SR04T and more

Posted: 15 Aug 2017, 13:39
by LisaM
Shardan wrote: 14 Aug 2017, 19:49 Definitely. These sensors are omnidirectional.
I can make it work if i go to a wall made from ferroconcrete.
Anyways it should be possible to shield the antenna if you cover two or three sides
of a case with aluminium foil for example. But don't put the foil too near to the module,
keep some centimeters distance. Maybe use a plastic case, mount the module at the mid of the lid and cover bottom and sides for shielding...
I didn't test that yet.

Regards
Shardan
How about using the same kind of shielding/focus as on a HC-SR04? Some kind of a thin metal tube glued over the sensor...

Re: Distance Sensors HC-SR04, JSN-SR04T and more

Posted: 15 Aug 2017, 15:41
by Shardan
LisaM wrote: 15 Aug 2017, 13:39
Shardan wrote: 14 Aug 2017, 19:49 Definitely. These sensors are omnidirectional.
I can make it work if i go to a wall made from ferroconcrete.
Anyways it should be possible to shield the antenna if you cover two or three sides
of a case with aluminium foil for example. But don't put the foil too near to the module,
keep some centimeters distance. Maybe use a plastic case, mount the module at the mid of the lid and cover bottom and sides for shielding...
I didn't test that yet.

Regards
Shardan
How about using the same kind of shielding/focus as on a HC-SR04? Some kind of a thin metal tube glued over the sensor...
Microwaves are electromagnetic waves of some cm wavelengt. A metal tube very near the sensor influences the antenna tuning.
So it is better to keep some cm distance to the microwave antenna - it wil still misstune it a bit but not too much i hope.
Another way might be to tune the shielding into resonance with the antenna so it works like a radar dish or a Yagi antenna.
Might work or not, i won't predict any result.

But that won't make the microwave sensor usable for my purposes as i need a distance + threshhold.....

Re: Distance Sensors HC-SR04, JSN-SR04T and more

Posted: 15 Aug 2017, 21:58
by toffel969
LisaM wrote: 13 Aug 2017, 23:26 Please let me know if anyone is using the STATE mode, state mode means that the distance is below the threshold set in the form earlier. When state mode is reached, distance below threshold, then a sensor switch event is send.

If nobody is using it, i can as well take it out...
Hi LisaM

Would it be possible to include median function of the New ping lib?(optional with parameter on device page). It can be done using a dummy device and rules, however it can b very handy when using t distance sensor a water level sensor.
Regards seb

Re: Distance Sensors HC-SR04, JSN-SR04T and more

Posted: 16 Aug 2017, 00:20
by LisaM
toffel969 wrote: 15 Aug 2017, 21:58 Would it be possible to include median function of the New ping lib?(optional with parameter on device page). It can be done using a dummy device and rules, however it can b very handy when using t distance sensor a water level sensor.
Regards seb
No problem, i'll add another pulldown (normal, median).

Re: Distance Sensors HC-SR04, JSN-SR04T and more

Posted: 16 Aug 2017, 15:53
by Shardan
Looking forward to it.....

Re: Distance Sensors HC-SR04, JSN-SR04T and more

Posted: 16 Aug 2017, 19:29
by toffel969
Thanks :)

Re: Distance Sensors HC-SR04, JSN-SR04T and more

Posted: 18 Aug 2017, 17:12
by LisaM
Volunteers wanted... ;)

Tested with HC-SR04 and JSN-SR04T...
_P013_HCSR04.zip
(1.97 KiB) Downloaded 635 times

Re: Distance Sensors HC-SR04, JSN-SR04T and more

Posted: 18 Aug 2017, 18:39
by Shardan
I'll test as soon as i have some spare time.... might take a while.

Regards
Shardan

Re: Distance Sensors HC-SR04, JSN-SR04T and more

Posted: 18 Aug 2017, 20:13
by toffel969
Shardan wrote: 18 Aug 2017, 18:39 I'll test as soon as i have some spare time.... might take a while.

Regards
Shardan
Same here... unfortunately

Re: Distance Sensors HC-SR04, JSN-SR04T and more

Posted: 24 Aug 2017, 20:22
by Shardan
Hello Lisa,

I've unpacked the plugin to my source folder and compiling with platformio failed.

Code: Select all

Compiling .pioenvs\normal_4096\FrameworkArduino\Updater.o
D:/ESP_MEGA_Clone/ESPEasy-mega_20170818 - HCSR04/src/_P013_HCSR04.ino:12:21: fatal error: NewPing.h: No such file or di
rectory
#include <NewPing.h>
^
compilation terminated.
Is there a library missing in the .zip-file?

Regards
Shardan

Re: Distance Sensors HC-SR04, JSN-SR04T and more

Posted: 24 Aug 2017, 20:42
by LisaM

Re: Distance Sensors HC-SR04, JSN-SR04T and more

Posted: 24 Aug 2017, 22:00
by Shardan
Quick breadboard setup, tested with the last Github version.
Distance - works
Threshhold - works
Free mem - 21624 constant.

Looks good so far. Can't test the JSN-SR04T, i don't have one yet.

Regards
Shardan

Re: Distance Sensors HC-SR04, JSN-SR04T and more

Posted: 24 Aug 2017, 23:17
by LisaM
Shardan wrote: 24 Aug 2017, 22:00 Quick breadboard setup, tested with the last Github version.
Distance - works
Threshhold - works
Free mem - 21624 constant.

Looks good so far. Can't test the JSN-SR04T, i don't have one yet.

Regards
Shardan
Great, thx for testing! :D
i have a JSN-SR04T running for week now, hopefully this can be confirmed by somebody else also. After confirmation, it's time to upload it into P013...

Re: Distance Sensors HC-SR04, JSN-SR04T and more

Posted: 25 Aug 2017, 10:28
by Shardan
Anytime :)

I'll let the breadboard run for a while and look if memory changes or such,
maybe combine it with a BME280 or such to see if anything interferes.

Regards
Shardan

Re: Distance Sensors HC-SR04, JSN-SR04T and more

Posted: 25 Aug 2017, 13:14
by LisaM
Shardan wrote: 25 Aug 2017, 10:28 Anytime :)

I'll let the breadboard run for a while and look if memory changes or such,
maybe combine it with a BME280 or such to see if anything interferes.

Regards
Shardan
sonic.JPG
sonic.JPG (158.63 KiB) Viewed 45017 times
sonic mem.JPG
sonic mem.JPG (59.22 KiB) Viewed 45016 times
:D

Re: Distance Sensors HC-SR04, JSN-SR04T and more

Posted: 05 Sep 2017, 01:32
by rol-rider
Hello,
I tested both sensors.
the hc-SR04 ------- distance = 180cm - ok ---- distance <to 20cm --- ok
the JSN-SR04T --- distance = 180cm - ok --- distance <to 20cm --- NOK

the JSN-SR04T looks less good for distances <20cm

excuse me for English .... google translate

Re: Distance Sensors HC-SR04, JSN-SR04T and more

Posted: 05 Sep 2017, 09:23
by LisaM
rol-rider wrote: 05 Sep 2017, 01:32 Hello,
I tested both sensors.
the hc-SR04 ------- distance = 180cm - ok ---- distance <to 20cm --- ok
the JSN-SR04T --- distance = 180cm - ok --- distance <to 20cm --- NOK

the JSN-SR04T looks less good for distances <20cm

excuse me for English .... google translate
That is true, the specs for the JSN-SR04T clearly indicate that the JSN-SR04T is not useable for distances less then 20cm:
Electrical parameters: JSN-SR04T

Working voltage: DC 3.0-5.5V
Working current: <8mA
Acoustic emission frequency: 40khz
Farthest distance: 600cm
Nearest distance: 20cm
Distance accuracy: ±1cm
Module size: 42mm*29mm*12mm
Resolution: about 1mm
Angle: 75 degrees
Working temperature: -20℃—+70℃

Re: Distance Sensors HC-SR04, JSN-SR04T and more

Posted: 05 Sep 2017, 19:37
by rol-rider
OK !
its good
and even with vcc 3.3V

Re: Distance Sensors HC-SR04, JSN-SR04T and more

Posted: 12 Dec 2017, 03:50
by sammyke007
So the waterproof JSN-SR04T version is not measuring closer than 20cm correctly?
HC-SR04 with some selfmade waterproofing it will be then :D

Re: Distance Sensors HC-SR04, JSN-SR04T and more

Posted: 28 Jan 2018, 13:48
by Domosapiens
It seems that this PLUGIN_13 from LisaM
//#######################################################################################################
//#################################### Plugin 013: Ultrasonic Sensors ###################################
//################ models: HC-SR04, SRF05, SRF06, DYP-ME007, JSN-SR04T & Parallax PING ##################
//#######################################################################################################
viewtopic.php?f=5&t=3432&hilit=HC+SR04+ ... =10#p18413
never was integrated in the Mega branch. The version in the Mega branch has a header like this
//#######################################################################################################
//#################################### Plugin 013: HC-SR04 ##############################################
//#######################################################################################################
For what reason, it was not integrated?

Re: Distance Sensors HC-SR04, JSN-SR04T and more

Posted: 28 Jan 2018, 14:10
by Shardan
That's an interesting question.

I've been testing that plugin for a while, it worked nicely for me.

Re: Distance Sensors HC-SR04, JSN-SR04T and more

Posted: 28 Jan 2018, 20:10
by TD-er
Could you please add an issue here: https://github.com/letscontrolit/ESPEasy/issues ?
It keeps merging/fixing things a lot easier.

Re: Distance Sensors HC-SR04, JSN-SR04T and more

Posted: 28 Jan 2018, 23:04
by Domosapiens
Sherdan and TD-er ... thanks for your acknowledge.
Opened issue: https://github.com/letscontrolit/ESPEasy/issues/782

Re: Distance Sensors HC-SR04, JSN-SR04T and more

Posted: 01 Feb 2018, 22:33
by bogas
Shardan wrote: 28 Jan 2018, 14:10 That's an interesting question.

I've been testing that plugin for a while, it worked nicely for me.
Hi.
Which last version supports these sensors? Added to "mega"?

Re: Distance Sensors HC-SR04, JSN-SR04T and more

Posted: 02 Feb 2018, 12:30
by bogas
Please share firmware (bin) 4096kB and / or 1024 with support JSN-SR04T.

Re: Distance Sensors HC-SR04, JSN-SR04T and more

Posted: 02 Feb 2018, 17:45
by Shardan
So, now i'm at home and can check:
I've compiled the plugin with ESP-Mega with Sources from Aug. 18. 2017.

I've a compiled version for 4096KB on my HDD, it is attached.
Please remember that this is not an officially supported version.

Regards
Shardan
firmware4096-hcsr04.zip
(361.68 KiB) Downloaded 457 times

Re: Distance Sensors HC-SR04, JSN-SR04T and more

Posted: 04 Oct 2018, 15:18
by JojoS
Hi,
there is an update for the US plugin. I have fixed some errors, now multiple sensors are possible. The plugin supports the median filter from the NewPing class, output as cm or inch (although this was possible with a formula expression already). I have changed also the calculation from integer to float so that you will see fractions of cm or inches.
For better troubleshooting, some more detailed errors will be shown in the log.

Re: Distance Sensors HC-SR04, JSN-SR04T and more

Posted: 04 Oct 2018, 16:16
by HomeJCL
Hi

Read it this morning, was nearly to jump ship for that measurement, you make my day, will test tonight 👍

Re: Distance Sensors HC-SR04, JSN-SR04T and more

Posted: 04 Oct 2018, 17:04
by grovkillen
JojoS wrote: 04 Oct 2018, 15:18 Hi,
there is an update for the US plugin. I have fixed some errors, now multiple sensors are possible. The plugin supports the median filter from the NewPing class, output as cm or inch (although this was possible with a formula expression already). I have changed also the calculation from integer to float so that you will see fractions of cm or inches.
For better troubleshooting, some more detailed errors will be shown in the log.
Great job JoJoS!

Re: Distance Sensors HC-SR04, JSN-SR04T and more

Posted: 10 Apr 2020, 16:26
by tparvais
Hello

I've tested my JSN-SR04T (not version 02) , never used with last Mega build 20200328. It does not work. Measure = 0
I i use my HC-SR04, it works fine.

should it work for both with same plugin ?

Im' a bit los of what I shall do. I don't have a scope to idetnify the problem

Any idea ?

Thank you

Thomas

Re: Distance Sensors HC-SR04, JSN-SR04T and more

Posted: 10 Apr 2020, 19:21
by TD-er
This datasheet (https://www.makerguides.com/wp-content/ ... asheet.pdf ) does mention a resistor on R27 to switch between different modi.

Open = similar behavior to the well known other Ultrasonic sensors
47k = switch to serial mode continuously sending distance in mm
120k = serial mode starting in stand-by and you have to wake it.

Re: Distance Sensors HC-SR04, JSN-SR04T and more

Posted: 10 Apr 2020, 19:32
by tparvais
TD-er wrote: 10 Apr 2020, 19:21 This datasheet (https://www.makerguides.com/wp-content/ ... asheet.pdf ) does mention a resistor on R27 to switch between different modi.

Open = similar behavior to the well known other Ultrasonic sensors
47k = switch to serial mode continuously sending distance in mm
120k = serial mode starting in stand-by and you have to wake it.
thanks. I know the R27.
I don't have this resistor on my PCB :-(
still searching

thank you anyway
T.

Re: Distance Sensors HC-SR04, JSN-SR04T and more

Posted: 10 Apr 2020, 19:38
by TD-er
How is the board powered?
Can you measure the voltage you supply to the sensor?
Maybe switch to 5V for powering the sensor and then add a small voltage divider to make sure the output of the signal pin is not over 3v3?

Maybe the GPIO connected to the trigger pin should have its pull-up resistor enabled?

Re: Distance Sensors HC-SR04, JSN-SR04T and more

Posted: 10 Apr 2020, 21:17
by tparvais
TD-er wrote: 10 Apr 2020, 19:38 How is the board powered?
Can you measure the voltage you supply to the sensor?
Maybe switch to 5V for powering the sensor and then add a small voltage divider to make sure the output of the signal pin is not over 3v3?

Maybe the GPIO connected to the trigger pin should have its pull-up resistor enabled?
Wemos D1 mini, powered by USB. JST module powered by 5V. Echo output is connected to PIN5 via a zener+Resistor to decrease level (works for hc-sr04). I tried also without

I tried this very simple code without success (always 0 cm)

Code: Select all

#define ECHOPIN 5// Pin to receive echo pulse
#define TRIGPIN 4// Pin to send trigger pulse
void setup(){
  Serial.begin(9600);
  pinMode(ECHOPIN, INPUT_PULLUP);
  pinMode(TRIGPIN, OUTPUT);
  
  digitalWrite(ECHOPIN, HIGH);
}
void loop(){
  digitalWrite(TRIGPIN, LOW); // Set the trigger pin to low for 2uS
  delayMicroseconds(2);
  digitalWrite(TRIGPIN, HIGH); // Send a 10uS high to trigger ranging
  delayMicroseconds(15);
  digitalWrite(TRIGPIN, LOW); // Send pin low again
  int distance = pulseIn(ECHOPIN, HIGH,26000); // Read in times pulse
  distance= distance/58;
  Serial.print(distance);
  Serial.println("   cm");                  
  delay(50);// Wait 50mS before next ranging
}

Re: Distance Sensors HC-SR04, JSN-SR04T and more

Posted: 10 Apr 2020, 21:47
by TD-er
Maybe the trigger you try to send does not have the right voltage level?
Have you tried using a PNP transistor to increase the output level?

Re: Distance Sensors HC-SR04, JSN-SR04T and more

Posted: 11 Apr 2020, 12:23
by tparvais
TD-er wrote: 10 Apr 2020, 21:47 Maybe the trigger you try to send does not have the right voltage level?
Have you tried using a PNP transistor to increase the output level?
I'm now feeding with real 5V, not usb naymore. Power is ok on JSN module.

Re: Distance Sensors HC-SR04, JSN-SR04T and more

Posted: 11 Apr 2020, 15:33
by TD-er
I was talking about the trigger signal from the ESP to the ultra sonic sensor.
Maybe the logic level is too low for that sensor to act on it?