This circuit is designed to interface an Arduino Nano with an IR sensor, a buzzer, a vibration motor, and an RF 433 MHz transmitter module. The purpose of the circuit is to detect an event via the IR sensor and respond by activating the buzzer and vibration motor, as well as transmitting an alert signal through the RF transmitter. The circuit is powered by a 5V battery.
#include <VirtualWire.h>
const int irSensorPin = 2;
const int buzzerPin = 3; // PWM-capable pin
const int vibratorPin = 4;
const int rfTxPin = 5;
void setup() {
pinMode(irSensorPin, INPUT);
pinMode(buzzerPin, OUTPUT);
pinMode(vibratorPin, OUTPUT);
// Initialize RF Transmitter
vw_set_tx_pin(rfTxPin);
vw_setup(2000); // Bits per second
Serial.begin(9600);
}
void loop() {
int irValue = digitalRead(irSensorPin);
if (irValue == LOW) { // Assuming LOW indicates eye closure or head movement
tone(buzzerPin, 1000); // Generate a 1kHz tone on the buzzer
digitalWrite(vibratorPin, HIGH); // Activate vibrator
// Send RF signal
const char *msg = "Alert";
vw_send((uint8_t *)msg, strlen(msg));
vw_wait_tx(); // Wait until the message is sent
delay(1000); // Keep buzzer and vibrator on for 1 second
noTone(buzzerPin); // Deactivate buzzer
digitalWrite(vibratorPin, LOW); // Deactivate vibrator
}
delay(100); // Small delay to avoid rapid triggering
}
The code is written for the Arduino Nano and utilizes the VirtualWire library for RF communication. The IR sensor is read on pin D2, and when a LOW signal is detected, indicating an event, the buzzer is activated on pin D3, the vibration motor on pin D4, and an "Alert" message is transmitted via the RF transmitter on pin D5. The buzzer and vibrator are activated for 1 second before being turned off. A short delay is included in the loop to prevent rapid re-triggering of the alert.