Arduino and PCA9685 Controlled Robotic Hand with Flex Sensors
View and Edit Project In Cirkit Designer
Circuit Documentation
Summary
This circuit involves an Arduino UNO, an Arduino Nano, an Adafruit PCA9685 PWM Servo Breakout, multiple resistors, flex resistors, and micro servos. The circuit is designed to control the movement of servos based on input from flex resistors, with communication facilitated by Bluetooth.
Component List
Micro servo 9G
- Pins: GND, +5V, PWM
- Description: A small servo motor used for precise control of angular position.
Arduino UNO
- Pins: UNUSED, IOREF, Reset, 3.3V, 5V, GND, Vin, A0, A1, A2, A3, A4, A5, SCL, SDA, AREF, D13, D12, D11, D10, D9, D8, D7, D6, D5, D4, D3, D2, D1, D0
- Description: A microcontroller board based on the ATmega328P.
Adafruit PCA9685 PWM Servo Breakout
- Pins: 5.0V, GND, PWRIN, PWM7, PWM6, PWM5, PWM4, PWM3, PWM2, PWM1, PWM0, VCC, SDA, SCL, OE, PWM15, PWM14, PWM13, PWM12, PWM11, PWM10, PWM9, PWM8
- Description: A 16-channel PWM driver for controlling servos.
2.2 inch Basic Flex Resistor
- Pins: Pin 2, pin 1
- Description: A flexible resistor that changes resistance when bent.
Resistor
- Pins: pin1, pin2
- Description: A passive electrical component that provides resistance.
- Properties: Resistance: 10 Ohms
Arduino Nano
- Pins: D1/TX, D0/RX, RESET, GND, D2, D3, D4, D5, D6, D7, D8, D9, D10, D11/MOSI, D12/MISO, VIN, 5V, A7, A6, A5, A4, A3, A2, A1, A0, AREF, 3V3, D13/SCK
- Description: A small, complete, and breadboard-friendly board based on the ATmega328P.
Wiring Details
Micro servo 9G
- GND connected to Adafruit PCA9685 PWM Servo Breakout GND
- +5V connected to Adafruit PCA9685 PWM Servo Breakout 5.0V
- PWM connected to Adafruit PCA9685 PWM Servo Breakout PWM4
Micro servo 9G
- GND connected to Adafruit PCA9685 PWM Servo Breakout GND
- +5V connected to Adafruit PCA9685 PWM Servo Breakout 5.0V
- PWM connected to Adafruit PCA9685 PWM Servo Breakout PWM8
Arduino UNO
- 5V connected to Resistor pin1
- GND connected to Adafruit PCA9685 PWM Servo Breakout GND
- A4 connected to Adafruit PCA9685 PWM Servo Breakout SDA
- A5 connected to Adafruit PCA9685 PWM Servo Breakout SCL
- D5 connected to 2.2 inch Basic Flex Resistor pin 1
- D3 connected to 2.2 inch Basic Flex Resistor pin 1
Adafruit PCA9685 PWM Servo Breakout
- OE connected to Resistor pin1
- GND connected to Arduino UNO GND
- GND connected to Micro servo 9G GND
- 5.0V connected to Micro servo 9G +5V
- PWM4 connected to Micro servo 9G PWM
- GND connected to Micro servo 9G GND
- 5.0V connected to Micro servo 9G +5V
- PWM8 connected to Micro servo 9G PWM
- SDA connected to Arduino UNO A4
- SCL connected to Arduino UNO A5
2.2 inch Basic Flex Resistor
- Pin 2 connected to Resistor pin2
- Pin 2 connected to Resistor pin2
- pin 1 connected to Arduino Nano A7
- Pin 2 connected to Resistor pin1
- Pin 2 connected to Arduino Nano GND
- pin 1 connected to Arduino Nano A6
- pin 1 connected to Arduino UNO D5
- pin 1 connected to Arduino UNO D3
Resistor
- pin1 connected to Resistor pin1
- pin1 connected to Adafruit PCA9685 PWM Servo Breakout OE
- pin2 connected to 2.2 inch Basic Flex Resistor Pin 2
- pin2 connected to 2.2 inch Basic Flex Resistor Pin 2
- pin1 connected to 2.2 inch Basic Flex Resistor Pin 2
- pin1 connected to 2.2 inch Basic Flex Resistor Pin 2
Arduino Nano
- A7 connected to 2.2 inch Basic Flex Resistor pin 1
- GND connected to 2.2 inch Basic Flex Resistor Pin 2
- A6 connected to 2.2 inch Basic Flex Resistor pin 1
- 5V connected to Arduino UNO 5V
Code Documentation
Arduino UNO Code
#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>
// Define pins
const int bluetoothRxPin = 11; // RX pin for Bluetooth module
const int bluetoothTxPin = 10; // TX pin for Bluetooth module
// Create PWM driver instance
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
// Define servo channels on the PCA9685
const int servo1Channel = 4;
const int servo2Channel = 8;
// Define servo positions
const int openPosition = 150;
const int closePosition = 600;
void setup() {
Serial.begin(9600); // Initialize serial communication
pinMode(bluetoothRxPin, INPUT);
pinMode(bluetoothTxPin, OUTPUT);
pwm.begin();
pwm.setPWMFreq(60); // Analog servos run at ~60 Hz
}
void loop() {
if (Serial.available() > 0) {
String command = Serial.readStringUntil('\n');
if (command == "Grip Close") {
pwm.setPWM(servo1Channel, 0, closePosition);
pwm.setPWM(servo2Channel, 0, closePosition);
} else if (command == "Grip Open") {
pwm.setPWM(servo1Channel, 0, openPosition);
pwm.setPWM(servo2Channel, 0, openPosition);
}
}
delay(100); // Small delay to avoid spamming
}
Adafruit PCA9685 PWM Servo Breakout Code
void setup() {
// put your setup code here, to run once:
}
void loop() {
// put your main code here, to run repeatedly:
}
Arduino Nano Code
const int flexSensor1Pin = A6;
const int flexSensor2Pin = A7;
const int bluetoothTxPin = 2;
const int bluetoothRxPin = 3;
void setup() {
Serial.begin(9600); // Initialize serial communication
pinMode(flexSensor1Pin, INPUT);
pinMode(flexSensor2Pin, INPUT);
pinMode(bluetoothTxPin, OUTPUT);
pinMode(bluetoothRxPin, INPUT);
}
void loop() {
int flexValue1 = analogRead(flexSensor1Pin);
int flexValue2 = analogRead(flexSensor2Pin);
if (flexValue1 < 380 || flexValue2 < 230) {
Serial.println("Grip Close");
// Send signal to close the grip
digitalWrite(bluetoothTxPin, HIGH);
} else if (flexValue1 > 410 || flexValue2 > 260){
Serial.println("Grip Open");
// Send signal to open the grip
digitalWrite(bluetoothTxPin, LOW);
}
delay(100); // Small delay to avoid spamming
}