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

Not open for further replies.


New member
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 = sonar.ping(); // 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)
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:
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.
Not open for further replies.