The circuit in question appears to be a multi-functional device that incorporates various LEDs, a microphone module (INMP441), a voltage regulator (7805), a toggle switch, and two ESP32 Wroom Dev Kits for processing and control. The circuit is powered by a 12V battery, and the 7805 voltage regulator steps down the voltage to 5V for certain components. The ESP32 microcontrollers are used to control the LEDs and handle audio input from the INMP441 microphone module. The toggle switch seems to be used for controlling the power supply to some parts of the circuit.
//////Running code with board manager version 1.0.6
#define led_1 15
#define led_2 4
#define button 32 // Button_Sensor
#define led_3 2
#define RXp2 16
#define TXp2 17
#include "Audio.h"
#include "CloudSpeechClient.h"
int i=0;
void setup() {
pinMode(button, INPUT);
pinMode(led_1, OUTPUT);
pinMode(led_2, OUTPUT);
pinMode(led_3, OUTPUT);
Serial.begin(115200);
Serial2.begin(115200, SERIAL_8N1, RXp2, TXp2);
// Serial.println(My_Data);
}
void loop() {
digitalWrite(led_1, 0);
digitalWrite(led_2, 0);
digitalWrite(led_3, 0);
if(i==0){
Serial.println("Press button");
i=1;
}
delay(500);
if(digitalRead(button)==0){
Serial2.println("\nPlease Ask!\n");
digitalWrite(led_1, 1);
digitalWrite(led_2, 0);
digitalWrite(led_3, 0);
delay(2100);
Serial.println("\r\nRecord start!\r\n");
Audio* audio = new Audio(ADMP441);
audio->Record();
Serial.println("Recording Completed Processing");
digitalWrite(led_1,0);
digitalWrite(led_3,0);
digitalWrite(led_2,1);
CloudSpeechClient* cloudSpeechClient = new CloudSpeechClient(USE_APIKEY);
cloudSpeechClient->Transcribe(audio);
delete cloudSpeechClient;
delete audio;
i=0;
}
if(digitalRead(button)==1){
delay(1000);
}
}
#define pin_1 2 // Pin for light one control
#define pin_2 22 // Pin for light two control
#define pin_3 19 // Pin for light three control
void setup() {
pinMode(pin_1, OUTPUT);
pinMode(pin_2, OUTPUT);
pinMode(pin_3, OUTPUT);
Serial.begin(115200);
Serial2.begin(115200);
}
void loop() {
if (Serial2.available()) {
String receivedText = Serial2.readString();
Serial.println("Received text: " + receivedText);
processCommand(receivedText);
}
delay(100);
}
void processCommand(String command) {
command.toLowerCase(); // Convert to lowercase for easier matching
// Light one control
if (command.indexOf("turn on light one") >= 0) {
digitalWrite(pin_1, HIGH); // Set pin_1 HIGH (1)
Serial.println("Pin 1 set HIGH");
} else if (command.indexOf("turn off light one") >= 0) {
digitalWrite(pin_1, LOW); // Set pin_1 LOW (0)
Serial.println("Pin 1 set LOW");
}
// Light two control
else if (command.indexOf("turn on light two") >= 0) {
digitalWrite(pin_2, HIGH); // Set pin_2 HIGH (1)
Serial.println("Pin 2 set HIGH");
} else if (command.indexOf("turn off light two") >= 0) {
digitalWrite(pin_2, LOW); // Set pin_2 LOW (0)
Serial.println("Pin 2 set LOW");
}
// Light three control
else if (command.indexOf("turn on light three") >= 0) {
digitalWrite(pin_3, HIGH); // Set pin_3 HIGH (1)
Serial.println("Pin 3 set HIGH");
} else if (command.indexOf("turn off light three") >= 0) {
digitalWrite(pin_3, LOW); // Set pin_3 LOW (0)
Serial.println("Pin 3 set LOW");
}
// All lights control
else if (command.indexOf("turn on all lights") >= 0) {
digitalWrite(pin_1, HIGH);
digitalWrite(pin_2, HIGH);
digitalWrite(pin_3, HIGH);
Serial.println("All pins set HIGH");
} else if (command.indexOf("turn off all lights") >= 0) {
digitalWrite(pin_1, LOW);
digitalWrite(pin_2, LOW);
digitalWrite(pin_3, LOW);
Serial.println("All pins set LOW");
}
else {
Serial.println("Command not recognized");
}
}
(Note: The code for the 7805 microcontroller instance is empty and thus not included in the documentation.)