Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 4 of 4

Thread: Ultrasonic Sensor HC-SR04, Teensy 3.6 and NewPing library ?

  1. #1
    Junior Member
    Join Date
    Aug 2018

    Ultrasonic Sensor HC-SR04, Teensy 3.6 and NewPing library ?

    Have anyone successfully tried to connect the HC-SR04 sensor to a teensy 3.6 using NewPing library or the library is incompatible? In the library website it is mentioned that is compatible with Teensy family (including Teensy 3.2) but it says nothing about teensy 3.6 I used the code below but I always get "0" distance.

    #include <NewPing.h>
    #define TRIGGER_PIN  11
    #define ECHO_PIN     10 
    #define MAX_DISTANCE 400 
    NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.
    int distance;
    void setup() {
      Serial.begin(115200); // Open serial monitor at 115200 baud to see ping results.
    void loop() {
      unsigned int uS =; // Send ping, get ping time in microseconds (uS).
      Serial.print("Ping: ");
      distance= uS / US_ROUNDTRIP_CM;
      Serial.print(uS / US_ROUNDTRIP_CM); // Convert ping time to distance in cm and print result (0 = outside set distance range)

  2. #2
    Senior Member+ manitou's Avatar
    Join Date
    Jan 2013
    Careful, datasheet says sensor wants 5v, BUT Teensy 3.6 is NOT 5v tolerant, so you may smoke your ECHO_PIN.

    you could try the non-library sketch as described on sparkfun site

    EDIT: Your sketch with NewPing library worked fine on T3.5 (it's 5v tolerant) with my HC-SR04.
    Last edited by manitou; 08-23-2018 at 09:41 PM.

  3. #3
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    NewPing should work on Teensy 3.6.

    Hardware-wise, it uses only IntervalTimer and standard Arduino functions. Those work great on Teensy 3.6.

    Maybe something is wrong with your wiring? If you show us photos of how you actually connected the hardware, maybe will be able to see something you've overlooked? Simple misunderstandings are a very common cause of these sorts of issues. If you look over other threads on this forum, we're pretty good at spotting these sorts of issues when we can actually see photos. So don't be shy... take some photos and post them here so we can help you.

  4. #4
    Junior Member
    Join Date
    Aug 2018
    Thank you both for your responses, I will take some photos tomorrow (I don't have it here with me at the moment) and I will also try with a logic level converter , I have one from adarfuit (

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts