Hi everyone,
I'm quite new in the Arduino's World.
I have two ultrasonic sensors JSN-SR04T and I wonder whether it is possible to send a pulse from one of them to the second ?
Thanks
Try triggering both at the same time and only listening to the ECHO line of the "receiving" unit. The dead zone will be twice the advertised distance.
I tried something like that but when I open the Serial Monitor I only have "Distance = 0cm", where is the issue ?
/* Arduino example sketch to control a JSN-SR04T ultrasonic distance sensor */
// Define Trig and Echo pin:
#define trigPin1 2
#define echoPin1 3
#define trigPin2 4
#define echoPin2 5
// Define variables:
long duration;
int distance;
void setup() {
// Define inputs and outputs
pinMode(trigPin1, OUTPUT);
pinMode(echoPin1, INPUT);
pinMode(trigPin2, OUTPUT);
pinMode(echoPin2, INPUT);
// Begin Serial communication at a baudrate of 9600:
Serial.begin(9600);
}
void loop() {
// Clear the trigPin by setting it LOW:
digitalWrite(trigPin1, LOW);
delayMicroseconds(5);
// Trigger the sensor by setting the trigPin high for 10 microseconds:
digitalWrite(trigPin1, HIGH); // module 1
delayMicroseconds(10);
digitalWrite(trigPin1, LOW);
// Read the echoPin. pulseIn() returns the duration (length of the pulse) in microseconds:
duration = pulseIn(echoPin2, HIGH); // module 2
// Calculate the distance:
distance = duration*0.034/2;
// Print the distance on the Serial Monitor (Ctrl+Shift+M):
Serial.print("Distance = ");
Serial.print(distance);
Serial.println(" cm");
delay(500);
}
Test each sensor by itself so you know that they are not defective.
How are you triggering the second sensor? Your code has two trigger pins but you are doing nothing with the second one. You only need one trigger pin...wire it to both sensors. (And you're not using module 1 echo pin, so why pinMode it?)
Are the sensors far enough apart so that they are beyond the dead zone?
Are there any obstacles between the sensors that could cause reflections?
PS: Your distance calculation is wrong.