arendst / Tasmota

Alternative firmware for ESP8266 and ESP32 based devices with easy configuration using webUI, OTA updates, automation using timers or rules, expandability and entirely local control over MQTT, HTTP, Serial or KNX. Full documentation at
https://tasmota.github.io/docs
GNU General Public License v3.0
21.71k stars 4.72k forks source link

SR04 Ultrasonic sensor support? #113

Closed Killobite closed 6 years ago

Killobite commented 7 years ago

First off, fantastic firmware! I have installed this firmware on more than 20 Sonoffs and am really appreciating the capabilities and attention to detail!

I do find that I would really like to add the use of a SR04 distance sensor for one of my implementation and am wondering if there may be any plan or ideas on how to do so?

Thanks!

arendst commented 7 years ago

The SR04 needs 5V. Sonoff can only supply 3V3. Do you expect the SR04 to work reliably on 3V3?

AlexTransit commented 7 years ago

Sonoff basic - use 2 power 5v - via trancformater (power relay) 3.3v - afrer stabiliser

Killobite commented 7 years ago

I will actually be using it with a Wemos D Mini and can take the 5V right off the VCC pin. I have a mock up working with 3.9.21 and just threw the sonar code in the void loop and sent the output to serial. I started to dig into an "easy" way to publish the distance into MQTT but that's when I thought I would reach out and see if anybody has any plan/code on it. I had to put a little millis delay in to get it to read correctly and only report out if the distant changes by more than 10 inches but it works reliably, I just have to figure out hot to make it pretty for the web interface and MQTT output.

My use case is a garage door control with open/closed (distance) indicator and a sump pump monitor/override with water level (distance) logging.

Here is my simple loop code in case you are interested: if (millis() >= lMillis + 250) {

  lMillis = millis();
  sDistNew = Ultrasonic.distanceRead(INC);

  if (sDistNew > sDist + 10 ){
    sDist = sDistNew;
    Serial.print("Distance in Inches: ");
    // Pass INC as a parameter to get the distance in inches
    Serial.println(sDist);
    //delay(1000);
  }
  else{
      if (sDistNew < sDist - 10 ){
      sDist = sDistNew;
      Serial.print("Distance in Inches: ");
      // Pass INC as a parameter to get the distance in inches
      Serial.println(sDist);
      //delay(1000);
  }
 }

}

f0m3 commented 7 years ago

Thats a cool idea. Id like to use the sonoff dual for my garage door control but id like to know if it is open or closed too...

hamwong commented 7 years ago

Wish SR04/05 will support in sonoff, power should not be the reason make SR04 not add as SR501 also use 5V

quadflight commented 7 years ago

Great idea. Did you get it to work?

BernardLaurenzo commented 6 years ago

The sonoff dev board has 5v Im currently running my SR04 and sonoff dev with ESP easy firmware

jetema commented 6 years ago

3inferior

Yes, 5 volts are available on D5 ( zenner diode in the middle of the pic ) terminals, you can get a few extra mA from this point to supply SR04

Gompka commented 6 years ago

You can also use this sensor https://www.bananarobotics.com/shop/US-100-Ultrasonic-Distance-Sensor-Module as it runs on 3.3v

nosaj66au commented 6 years ago

Hi Guys, has this gone any further I required it for rain water tank level

Jason

fragolinux commented 6 years ago

HC-SR04P can work at 3.3V, you can recognize it because usually is blue as the other model, but has NO crystal oscillator on the front panel, look at image s-l300

scottchristian commented 6 years ago

I'm going to throw my request for this as well. Would be very nifty

Frogmore42 commented 6 years ago

Well you are in luck. https://github.com/arendst/Sonoff-Tasmota/wiki/Wemos-D1-Mini-and-HC-SR04-Ultrasonic-Sensor

ascillato commented 6 years ago

Now it is implemented. Closing.

ascillato commented 6 years ago

?

rajil commented 5 years ago

@Gompka I found the manual for US-100 here. Does this device work with 3.3V?

Gompka commented 5 years ago

Yea it does, I have been using it for over a year.

rajil commented 5 years ago

@Gompka I tried to use PingSerial library with US-100 but that did not work. Do you have any example code which works on nodemcu?

Gompka commented 5 years ago

@rajil, did you make sure the jumper on the back of the us-100 is in the correct position? I do not have any code, but I am using the sensor with wemos d1 with opengarage. You can check the opengarage project for some code examples.

rajil commented 5 years ago

@Gompka I was able to get it working after taking off the jumper. Is it possible to hook two ultrasonic sensors on the same ESP8266. In Tasmota 'configure module' 73/74 device type is Trigger/Echo. I assigned these to two devices, but only one device showed up.

nikito7 commented 1 year ago

Can we change trigger time?