The AJSR04 is an ultrasonic distance sensor designed to measure distances by emitting ultrasonic waves and calculating the time it takes for the echo to return. This sensor is widely used in robotics, automation, and IoT applications for tasks such as obstacle detection, distance measurement, and object tracking. Its compact design and reliable performance make it a popular choice for both hobbyists and professionals.
The AJSR04 sensor operates by sending ultrasonic pulses at a frequency of 40 kHz and measuring the time it takes for the echo to return. Below are the key technical details:
Parameter | Value |
---|---|
Operating Voltage | 5V DC |
Operating Current | 15 mA (typical) |
Measuring Range | 2 cm to 400 cm |
Accuracy | ±3 mm |
Operating Frequency | 40 kHz |
Trigger Input Signal | 10 µs TTL pulse |
Echo Output Signal | TTL pulse proportional to distance |
Dimensions | 45 mm x 20 mm x 15 mm |
The AJSR04 has four pins, as described in the table below:
Pin | Name | Description |
---|---|---|
1 | VCC | Power supply pin (5V DC) |
2 | Trig | Trigger pin: Input a 10 µs TTL pulse to initiate measurement |
3 | Echo | Echo pin: Outputs a TTL pulse proportional to the distance |
4 | GND | Ground connection |
The distance can be calculated using the formula: [ \text{Distance (cm)} = \frac{\text{Pulse Duration (µs)}}{58} ] This formula accounts for the speed of sound in air (approximately 343 m/s).
Below is an example Arduino sketch to measure distance using the AJSR04:
// Define pins for the AJSR04 sensor
const int trigPin = 9; // Trigger pin connected to digital pin 9
const int echoPin = 10; // Echo pin connected to digital pin 10
void setup() {
pinMode(trigPin, OUTPUT); // Set the trigger pin as an output
pinMode(echoPin, INPUT); // Set the echo pin as an input
Serial.begin(9600); // Initialize serial communication at 9600 baud
}
void loop() {
// Send a 10 µs pulse to the Trig pin
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Measure the duration of the pulse on the Echo pin
long duration = pulseIn(echoPin, HIGH);
// Calculate the distance in cm
float distance = duration / 58.0;
// Print the distance to the Serial Monitor
Serial.print("Distance: ");
Serial.print(distance);
Serial.println(" cm");
delay(500); // Wait for 500 ms before the next measurement
}
No Output from Echo Pin
Inaccurate Distance Measurements
Sensor Not Responding
Q: Can the AJSR04 detect transparent objects?
A: The AJSR04 may struggle to detect transparent objects like glass due to poor ultrasonic wave reflection.
Q: What is the maximum range of the AJSR04?
A: The maximum range is 400 cm (4 meters), but accuracy may decrease at longer distances.
Q: Can I use the AJSR04 with a 3.3V microcontroller?
A: The AJSR04 requires a 5V power supply, but the Trig and Echo pins can often be interfaced with 3.3V logic using a level shifter.
By following this documentation, users can effectively integrate the AJSR04 ultrasonic sensor into their projects for reliable distance measurement and obstacle detection.