Arduino UNO-Based Gesture and Voice-Controlled Servo with Security Keypad
View and Edit Project In Cirkit Designer
Circuit Documentation
Summary
This circuit is designed to interface with various components including an APDS9960 gesture sensor, an Arduino UNO microcontroller, a servo motor, a voice recognition module, a 4x4 membrane matrix keypad, and LEDs (red and blue). The Arduino UNO serves as the central processing unit, controlling the servo motor based on input from the keypad, voice commands, and gesture detection. The LEDs provide visual feedback, and the piezo buzzer can be used for audio signaling.
Component List
APDS9960 Gesture Sensor
- Description: A gesture detection sensor that can also detect ambient light and color.
- Pins: GND, INT, SDA, SCL, VCC
Arduino UNO
- Description: A microcontroller board based on the ATmega328P.
- Pins: UNUSED, IOREF, Reset, 3.3V, 5V, GND, Vin, A0-A5, SCL, SDA, AREF, D0-D13
Servo Motor
- Description: An actuator that can be precisely controlled for angular rotation.
- Pins: GND, VCC, PWM
Voice Recognition Module
- Description: A module capable of recognizing voice commands.
- Pins: GND, VCC, RDX, RTX
4x4 Membrane Matrix Keypad
- Description: An input device with 16 buttons arranged in a 4x4 grid.
- Pins: R1, R2, R3, R4, C1, C2, C3, C4
LED: Two Pin (Red)
- Description: A red light-emitting diode.
- Pins: Cathode, Anode
LED: Two Pin (Blue)
- Description: A blue light-emitting diode.
- Pins: Cathode, Anode
Piezo Buzzer
- Description: An electronic device that produces sound.
- Pins: Pin 1, Pin 2
Wiring Details
APDS9960 Gesture Sensor
- GND -> Arduino UNO GND
- SDA -> Arduino UNO A4
- SCL -> Arduino UNO A5
- VCC -> Arduino UNO 3.3V
Arduino UNO
- D13 -> Blue LED Anode
- A0 -> Red LED Anode, Piezo Buzzer Pin 1
- GND -> Red LED Cathode, Blue LED Cathode, Piezo Buzzer Pin 2, Voice Recognition Module GND, Servo GND, APDS9960 GND
- 5V -> Servo VCC, Voice Recognition Module VCC
- A4 -> APDS9960 SDA
- A5 -> APDS9960 SCL
- D12 -> Keypad C4
- D11 -> Keypad C3
- D10 -> Keypad C2
- D9 -> Servo PWM
- D8 -> Keypad C1
- D7 -> Keypad R4
- D6 -> Keypad R3
- D5 -> Keypad R2
- D4 -> Keypad R1
- D3 -> Voice Recognition Module RDX
- D2 -> Voice Recognition Module RTX
Servo Motor
- GND -> Arduino UNO GND
- VCC -> Arduino UNO 5V
- PWM -> Arduino UNO D9
Voice Recognition Module
- GND -> Arduino UNO GND
- VCC -> Arduino UNO 5V
- RDX -> Arduino UNO D3
- RTX -> Arduino UNO D2
4x4 Membrane Matrix Keypad
- R1 -> Arduino UNO D4
- R2 -> Arduino UNO D5
- R3 -> Arduino UNO D6
- R4 -> Arduino UNO D7
- C1 -> Arduino UNO D8
- C2 -> Arduino UNO D10
- C3 -> Arduino UNO D11
- C4 -> Arduino UNO D12
LED: Two Pin (Red)
- Cathode -> Arduino UNO GND
- Anode -> Arduino UNO A0
LED: Two Pin (Blue)
- Cathode -> Arduino UNO GND
- Anode -> Arduino UNO D13
Piezo Buzzer
- Pin 1 -> Arduino UNO A0
- Pin 2 -> Arduino UNO GND
Documented Code
#include <SoftwareSerial.h>
#include "VoiceRecognitionV3.h"
#include <Arduino_APDS9960.h>
#include <Servo.h>
#include <Keypad.h>
#define ROW_NUM 4
#define COLUMN_NUM 4
Servo myservo;
char keys[ROW_NUM][COLUMN_NUM] = {
{'1', '2', '3', 'A' },
{'4', '5', '6', 'B' },
{'7', '8', '9', 'C' },
{'*', '0', '#', 'D' }
};
byte pin_rows[ROW_NUM] = {4, 5, 6, 7};
byte pin_column[COLUMN_NUM] = {8, 10, 11, 12};
Keypad keypad = Keypad(makeKeymap(keys), pin_rows, pin_column, ROW_NUM, COLUMN_NUM);
const String password_1 = "123AA";
const String password_2 = "5678BC";
const String password_3 = "77657";
String input_password;
int angle = 0;
unsigned long lastTime;
VR myVR(2, 3);
uint8_t records[7];
uint8_t buf[64];
int led = 13;
#define onRecord (0)
#define offRecord (1)
void printSignature(uint8_t *buf, int len)
{
int i;
for(i=0; i<len; i++){
if(buf[i]>0x19 && buf[i]<0x7F){
Serial.write(buf[i]);
}
else{
Serial.print("[");
Serial.print(buf[i], HEX);
Serial.print("]");
}
}
}
void printVR(uint8_t *buf)
{
Serial.println("VR Index\tGroup\tRecordNum\tSignature");
Serial.print(buf[2], DEC);
Serial.print("\t\t");
if(buf[0] == 0xFF){
Serial.print("NONE");
}
else if(buf[0]&0x80){
Serial.print("UG ");
Serial.print(buf[0]&(~0x80), DEC);
}
else{
Serial.print("SG ");
Serial.print(buf[0], DEC);
}
Serial.print("\t");
Serial.print(buf[1], DEC);
Serial.print("\t\t");
if(buf[3]>0){
printSignature(buf+4, buf[3]);
}
else{
Serial.print("NONE");
}
Serial.println("\r\n");
}
void setup()
{
input_password.reserve(32);
myservo.attach(9);
Serial.begin(9600);
while (!Serial);
if (!APDS.begin()) {
Serial.println("Error initializing APDS-9960 sensor!");
}
Serial.println("Detecting gestures ...");
myVR.begin(9600);
Serial.begin(115200);
Serial.println("Elechouse Voice Recognition V3 Module\r\nControl LED sample");
pinMode(led, OUTPUT);
if(myVR.clear() == 0){
Serial.println("Recognizer cleared.");
}else{
Serial.println("Not find VoiceRecognitionModule.");
Serial.println("Please check connection and restart Arduino.");
while(1);
}
if(myVR.load((uint8_t)onRecord) >= 0){
Serial.println("onRecord loaded");
}
if(myVR.load((uint8_t)offRecord) >= 0){
Serial.println("offRecord loaded");
}
}
void loop(){
char key = keypad.getKey();
if (key) {
Serial.println(key);
if (key == '*') {
input_password = "";
} else if (key == '#') {
if (input_password == password_1 || input_password == password_2 || input_password == password_3) {
Serial.println("The password is correct, rotating Servo Motor to 90°");
digitalWrite(led, HIGH);
delay(3000);
digitalWrite(led, LOW);
lastTime = millis();
} else {
Serial.println("The password is incorrect, try again");
}
input_password = "";
} else {
input_password += key;
}
}
int ret;
ret = myVR.recognize(buf, 50);
if(ret>0){
switch(buf[1]){
case onRecord:
/** turn on LED */
digitalWrite(led, HIGH);
delay(3000);
digitalWrite(led, LOW);
break;
}
}
if (APDS.gestureAvailable()) {
int gesture = APDS.readGesture();
if (gesture == GESTURE_UP){
digitalWrite(led, HIGH);
delay(3000);
digitalWrite(led, LOW);
}
myservo.write(90);
}
char