Arduino-Based Bluetooth-Controlled Servo System with Flex Sensors and MPU-6050
View and Edit Project In Cirkit Designer
Circuit Documentation
Summary
This circuit involves an Arduino UNO and an Arduino Nano, which are used to control multiple servos and read sensor data. The servos are controlled via a PCA9685 PWM driver, and the sensor data is read from flex sensors and an MPU-6050 accelerometer. The data is communicated between the Arduino Nano and Arduino UNO using Bluetooth modules.
Component List
Micro Servo 9G
- Description: Small servo motor used for precise control of angular position.
- Pins: GND, +5V, PWM
Arduino UNO
- Description: A microcontroller board based on the ATmega328P.
- 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
Adafruit PCA9685 PWM Servo Breakout
- Description: 16-channel, 12-bit PWM driver.
- 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
Arduino Nano
- Description: A small, complete, and breadboard-friendly board based on the ATmega328P.
- 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
HC-05 Bluetooth Module
- Description: Bluetooth module for wireless communication.
- Pins: Key, VCC, TXD, RXD, State, GND
2.2 inch Basic Flex Resistor
- Description: Flex sensor used to measure the amount of bend.
- Pins: Pin 2, Pin 1
Resistor
- Description: 10 Ohm resistor.
- Pins: pin1, pin2
- Properties: Resistance: 10 Ohms
MPU-6050
- Description: 6-axis motion tracking device.
- Pins: VCC, GND, SCL, SDA, XDA, XCL, AD0, INT
Wiring Details
Micro Servo 9G
- GND connected to GND of Adafruit PCA9685 PWM Servo Breakout
- +5V connected to 5.0V of Adafruit PCA9685 PWM Servo Breakout
- PWM connected to:
- PWM0 of Adafruit PCA9685 PWM Servo Breakout
- PWM4 of Adafruit PCA9685 PWM Servo Breakout
- PWM8 of Adafruit PCA9685 PWM Servo Breakout
Arduino UNO
- 5V connected to:
- VCC of HC-05 Bluetooth Module
- OE of Adafruit PCA9685 PWM Servo Breakout
- GND connected to:
- GND of HC-05 Bluetooth Module
- GND of Adafruit PCA9685 PWM Servo Breakout
- D10 connected to TXD of HC-05 Bluetooth Module
- D11 connected to RXD of HC-05 Bluetooth Module
- A4 connected to SDA of Adafruit PCA9685 PWM Servo Breakout
- A5 connected to SCL of Adafruit PCA9685 PWM Servo Breakout
Adafruit PCA9685 PWM Servo Breakout
- GND connected to:
- GND of Micro Servo 9G
- GND of Arduino UNO
- 5.0V connected to:
- +5V of Micro Servo 9G
- 5V of Arduino UNO
- PWM0 connected to PWM of Micro Servo 9G
- PWM4 connected to PWM of Micro Servo 9G
- PWM8 connected to PWM of Micro Servo 9G
- SDA connected to A4 of Arduino UNO
- SCL connected to A5 of Arduino UNO
Arduino Nano
- A4 connected to SDA of MPU-6050
- A5 connected to SCL of MPU-6050
- A6 connected to:
- pin1 of Resistor
- pin 1 of 2.2 inch Basic Flex Resistor
- A7 connected to:
- pin1 of Resistor
- pin 1 of 2.2 inch Basic Flex Resistor
- D2 connected to TXD of HC-05 Bluetooth Module
- D3 connected to RXD of HC-05 Bluetooth Module
- 5V connected to:
- pin2 of Resistor
- VCC of MPU-6050
- VCC of HC-05 Bluetooth Module
- Pin 2 of 2.2 inch Basic Flex Resistor
- GND connected to:
- GND of MPU-6050
- GND of HC-05 Bluetooth Module
HC-05 Bluetooth Module
- VCC connected to:
- 5V of Arduino Nano
- OE of Adafruit PCA9685 PWM Servo Breakout
- GND connected to:
- GND of Arduino Nano
- GND of Adafruit PCA9685 PWM Servo Breakout
- TXD connected to D2 of Arduino Nano
- RXD connected to D3 of Arduino Nano
2.2 inch Basic Flex Resistor
- Pin 2 connected to:
- 5V of Arduino Nano
- pin2 of Resistor
- Pin 1 connected to:
- A6 of Arduino Nano
- pin1 of Resistor
Resistor
- pin1 connected to:
- A6 of Arduino Nano
- pin 1 of 2.2 inch Basic Flex Resistor
- pin2 connected to:
- 5V of Arduino Nano
- Pin 2 of 2.2 inch Basic Flex Resistor
MPU-6050
- VCC connected to 5V of Arduino Nano
- GND connected to GND of Arduino Nano
- SDA connected to A4 of Arduino Nano
- SCL connected to A5 of Arduino Nano
Code Documentation
Arduino UNO Sketch
/*
* Arduino UNO Sketch
* This code controls three servos connected via a PCA9685 PWM driver.
* The servos are connected to PWM channels 0, 4, and 8 of the PCA9685.
* The servos will move slowly back and forth.
*/
#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
const int servoMin = 150; // Minimum pulse length count (out of 4096)
const int servoMax = 600; // Maximum pulse length count (out of 4096)
void setup() {
pwm.begin();
pwm.setPWMFreq(60); // Analog servos run at ~60 Hz updates
}
void loop() {
for (uint16_t pulselen = servoMin; pulselen < servoMax; pulselen++) {
pwm.setPWM(0, 0, pulselen);
pwm.setPWM(4, 0, pulselen);
pwm.setPWM(8, 0, pulselen);
delay(10);
}
for (uint16_t pulselen = servoMax; pulselen > servoMin; pulselen--) {
pwm.setPWM(0, 0, pulselen);
pwm.setPWM(4, 0, pulselen);
pwm.setPWM(8, 0, pulselen);
delay(10);
}
}
Arduino Nano Sketch
/*
* Arduino Nano Sketch
* This code reads values from two flex sensors and an MPU-6050 accelerometer
* and sends the data to an Arduino UNO via Serial communication.
* The flex sensors are connected to analog pins A6 and A7.
* The MPU-6050 is connected via I2C to pins A4 (SDA) and A5 (SCL).
* The data is sent over a Bluetooth module