In this blog, we will walk you through how to create a simple project using an Arduino and an Ultrasonic Sensor (HC-SR04) to trigger a voice playback on an ISD1820 Voice Recording Module when a person or object comes within a specific range. The voice message is recorded manually on the ISD1820, and the Arduino will handle triggering the playback based on proximity detected by the ultrasonic sensor.
Components Required:
- Arduino (e.g., Arduino Uno, Nano)
- HC-SR04 Ultrasonic Sensor
- ISD1820 Voice Recording Module
- Speaker (usually comes with the ISD1820 module)
- Jumper Wires
- Breadboard (optional, for organizing connections)
Wiring the Components:
- Wiring the ISD1820 Voice Recording Module:
- VCC: Connect to 5V on Arduino.
- GND: Connect to GND on Arduino.
- PLAYE: Connect to Pin 6 on Arduino (controls playback).
- Wiring the HC-SR04 Ultrasonic Sensor:
- VCC: Connect to 5V on Arduino.
- GND: Connect to GND on Arduino.
- Trig: Connect to Pin 9 on Arduino.
- Echo: Connect to Pin 10 on Arduino.
Arduino Code:
// Pin Definitions
const int playPin = 6; // Pin to control playback on ISD1820
const int trigPin = 9; // Pin for Trigger on HC-SR04
const int echoPin = 10; // Pin for Echo on HC-SR04
long duration; // Duration for the sound wave to return
int distance; // Calculated distance
void setup() {
// Set the play pin as OUTPUT
pinMode(playPin, OUTPUT);
// Set the HC-SR04 pins
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
// Start with playback turned off
digitalWrite(playPin, LOW);
Serial.begin(9600); // Initialize serial communication for debugging
}
void loop() {
// Send a pulse to the ultrasonic sensor to trigger the measurement
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Measure the time it takes for the pulse to return
duration = pulseIn(echoPin, HIGH);
// Calculate the distance (in cm)
distance = duration * 0.0343 / 2;
// Print the distance to the Serial Monitor (for debugging)
Serial.print("Distance: ");
Serial.println(distance);
// Check if the distance is less than a threshold (e.g., 10 cm)
if (distance < 10) {
// Trigger playback if the object is within 10 cm
digitalWrite(playPin, HIGH);
// Wait for playback to finish (5 seconds in this case)
delay(5000);
// Stop playback
digitalWrite(playPin, LOW);
// Wait a little to avoid multiple triggers quickly
delay(2000);
}
// Short delay before the next reading
delay(100);
}
Code Explanation:
1. Pin Initialization:
We initialize the pins for both the ultrasonic sensor and the ISD1820. The ultrasonic sensor’s Trigger and Echo pins are used to send and receive signals. The PLAYE pin is connected to the ISD1820 module and controls playback.
2. Ultrasonic Sensor Logic:
The ultrasonic sensor works by sending a pulse through the Trig pin. The sensor measures how long it takes for the pulse to bounce back to the Echo pin. Using this time, the Arduino calculates the distance.
3. Playback Trigger:
If the calculated distance is below a certain threshold (e.g., 10 cm), the Arduino triggers the ISD1820 to start playback. The playback will run for a set period (e.g., 5 seconds) before it stops.
How to Record Voice on the ISD1820:
- Press and hold the Record button on the ISD1820 module.
- Speak into the microphone.
- Release the button to stop the recording.
- The sound is now stored in the ISD1820 memory and ready to be played back.
Testing the Project:
- Upload the code to your Arduino.
- Open the Serial Monitor in the Arduino IDE to observe the distance readings from the ultrasonic sensor.
- Move an object or person within 10 cm of the sensor. Once the distance is below 10 cm, the ISD1820 will automatically start playing the recorded sound.
Conclusion:
By following this guide, you’ve successfully built a project that uses an ultrasonic sensor and an Arduino to trigger a voice playback on the ISD1820 Voice Recording Module. This setup can be used for various applications like sound alerts, greeting messages, or interactive exhibits. You can even modify the code and hardware to customize the functionality further!
Additional Ideas:
- Multiple Sounds: Use different thresholds to trigger different sounds.
- Sensor Alternatives: Replace the ultrasonic sensor with a PIR motion sensor for more human interaction.
- Voice Message Duration: Adjust the playback duration based on how long you want the message to be played.