The JSN-SR04T Ultrasonic Sensor is a versatile and waterproof distance measuring module that utilizes ultrasonic waves to determine the distance to an object. It is widely used in various applications such as robotics, automation, vehicle parking sensors, obstacle avoidance systems, and IoT projects. The sensor is designed to be robust and reliable, making it suitable for outdoor environments and harsh conditions.
Pin Number | Pin Name | Description |
---|---|---|
1 | VCC | Power supply (5V DC) |
2 | Trig | Trigger input (TTL pulse) |
3 | Echo | Echo output (TTL level signal) |
4 | GND | Ground |
#include <NewPing.h>
#define TRIGGER_PIN 12 // Arduino pin tied to trigger pin on the sensor.
#define ECHO_PIN 11 // Arduino pin tied to echo pin on the sensor.
#define MAX_DISTANCE 450 // Maximum distance we want to ping for (in centimeters).
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.
void setup() {
Serial.begin(9600); // Open serial monitor at 9600 baud to see ping results.
}
void loop() {
delay(50); // Wait 50ms between pings (about 20 pings/sec). 29ms should be the shortest delay between pings.
unsigned int uS = sonar.ping(); // Send ping, get ping time in microseconds (uS).
Serial.print("Ping: ");
Serial.print(uS / US_ROUNDTRIP_CM); // Convert time into distance and print result (in cm).
Serial.println("cm");
}
Q: Can the JSN-SR04T sensor be used underwater? A: No, the JSN-SR04T is waterproof but not designed for underwater use.
Q: What is the maximum reliable range of the sensor? A: The maximum reliable range is up to 4.5 meters, but optimal performance is achieved within 25cm to 4m.
Q: How can I extend the sensor's wires? A: You can extend the wires using shielded cables to minimize interference. Keep the extension as short as possible to maintain signal integrity.