The JSN-SR04M-2 is an ultrasonic ranging module manufactured by SUNLEPHANT. This component is designed to measure distances by emitting ultrasonic waves and detecting the time it takes for the echoes to return. It is widely used in robotics, obstacle avoidance systems, distance measurement applications, and various automation projects.
Pin Number | Pin Name | Description |
---|---|---|
1 | VCC | Power supply (3.3V to 5V DC) |
2 | Trig | Trigger input (TTL pulse) |
3 | Echo | Echo output (TTL level signal) |
4 | GND | Ground |
// Define the connection pins
const int trigPin = 9;
const int echoPin = 10;
void setup() {
// Initialize serial communication
Serial.begin(9600);
// Define pin modes
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
}
void loop() {
// Clear the trigPin by setting it LOW
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
// Set the trigPin HIGH for 10 microseconds to send the ultrasonic pulse
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Read the echoPin; pulseIn returns the duration in microseconds
long duration = pulseIn(echoPin, HIGH);
// Calculate the distance in centimeters
long distance = duration * 0.034 / 2;
// Print the distance on the Serial Monitor
Serial.print("Distance: ");
Serial.print(distance);
Serial.println(" cm");
// Delay between measurements
delay(500);
}
Q: Can the JSN-SR04M-2 be used to detect non-solid objects, like liquids? A: The module is designed for solid objects. It may not give reliable readings for liquids due to their varying density and surface reflectivity.
Q: What is the maximum distance the JSN-SR04M-2 can measure? A: The maximum range is 4.5 meters under ideal conditions.
Q: Is it possible to use multiple JSN-SR04M-2 modules in one project? A: Yes, but ensure that the ultrasonic signals from one module do not interfere with another by staggering the trigger signals.
Q: How can I extend the range of the module? A: The range cannot be extended beyond the specified maximum range. However, ensuring a clear path and minimal interference can help achieve the best possible range within the specified limits.