/* Clay trap transmitter Hardware: - Elechouse Voice Recognition Module V3 Arduino pin 2 -> VR module TX Arduino pin 3 -> VR module RX 5V -> VCC GND -> GND - 433 MHz transmitter, like the FS1000A Arduino pin 12 -> DATA 5V -> VCC GND -> GND Train the word "Pull" into records 0, 1, and 2 with the Elechouse vr_sample_train example first, then upload this sketch. */ #include #include #include #include const uint8_t VR_RX_PIN = 2; const uint8_t VR_TX_PIN = 3; const uint8_t RF_TX_PIN = 12; uint8_t PULL_RECORDS[] = {0, 1, 2}; const uint8_t PULL_RECORD_COUNT = sizeof(PULL_RECORDS) / sizeof(PULL_RECORDS[0]); const char PULL_MESSAGE[] = "1"; const unsigned long PULL_COOLDOWN_MS = 2000; VR voiceModule(VR_RX_PIN, VR_TX_PIN); RH_ASK rfDriver(2000, 11, RF_TX_PIN); uint8_t voiceBuffer[64]; unsigned long lastPullMs = 0; bool isPullRecord(uint8_t record) { for (uint8_t i = 0; i < PULL_RECORD_COUNT; i++) { if (record == PULL_RECORDS[i]) { return true; } } return false; } void sendPullSignal() { for (uint8_t i = 0; i < 5; i++) { rfDriver.send((uint8_t *)PULL_MESSAGE, strlen(PULL_MESSAGE)); rfDriver.waitPacketSent(); delay(60); } } void setup() { Serial.begin(115200); voiceModule.begin(9600); if (!rfDriver.init()) { Serial.println("RF transmitter failed to start."); while (1) { delay(1000); } } Serial.println("Clay trap voice transmitter starting..."); if (voiceModule.clear() != 0) { Serial.println("Voice module not found. Check TX/RX wiring and power."); while (1) { delay(1000); } } if (voiceModule.load(PULL_RECORDS, PULL_RECORD_COUNT) >= 0) { Serial.println("Loaded records 0, 1, and 2 for Pull."); } else { Serial.println("Could not load Pull records. Train Pull into records 0, 1, and 2 first."); while (1) { delay(1000); } } } void loop() { int recognized = voiceModule.recognize(voiceBuffer, 50); if (recognized > 0 && isPullRecord(voiceBuffer[1])) { unsigned long now = millis(); if (lastPullMs == 0 || now - lastPullMs >= PULL_COOLDOWN_MS) { Serial.println("Pull recognized. Sending RF signal."); sendPullSignal(); lastPullMs = now; } } }