The objective of this project is to develop a device that is able to measure the orientation of the operator’s hands and fingers for robot control purposes. We will cover the basics of resistance and voltage divider. Also, we will learn how to get measurements from a gyroscope and an accelerometer by I2C bus and how to make a Bluetooth Arduino–PC connection. All these will be useful when you integrate this hardware into Arduino Bluetooth Gloves.
Figure 1: Basic diagram of the Arduino Bluetooth Gloves project
The Arduino-based acquisition system is located on each hand of the user. The Arduino board gets flexion of the fingers (finger bending) by measuring the resistance of each potentiometer. Orientation of the user’s hand can be defined after processing data from inertial measurement unit (IMU), which includes gyroscope and accelerometer. Battery and wireless data transfer allow this Arduino-based acquisition system to be used as a wearable smart glove. For example, this could be used as a universal input device to manually control a robot arm.
Bending of the fingers can be defined by measuring resistance of each potentiometer when the rotation is transmitted from the fingers to the potentiometer grip. The potentiometer’s resistance can be measured using the voltage divider scheme. The voltage divider is used in electrical circuits if you want to reduce voltage and get some of its fixed values. It consists of two or more resistors.
Figure 2: Voltage divider circuit
V – is a voltage from Arduino’s 5V power supply; I – is a current, that flows through the circuit; R1 – is a resistor with defined resistance; R2 – is potentiometer with variable resistance; and V1 and V2 are voltmeters.
Voltage drop occurs at each of the resistances R1 and R2. Sum of V1 and V2 will be equal to the value of V. According to Ohm’s law:
Replace V2 voltmeter with Arduino analog input to measure resistance of the potentiometer.
Figure 3: Voltage divider circuit diagram
Figure 4: Voltage divider circuit placed on a breadboard
1 2 3 4 5 6 7 8 9 10 11 12 |
int sensorValue; void setup() { Serial.begin(9600);// initialize serial communication at 9600 bits per second } void loop() { sensorValue = analogRead(A0);// read the input on analog pin 0 Serial.println(sensorValue);// print out the value you read delay(100); // delay in between reads for stability } |
An inertial measurement unit (IMU) is an electronic device that measures body’s specific force and angular rate. By continuous integration of the angular rate we can get the current orientation of the body where the IMU sensor is installed.
IMU sensors became popular and widely available, thanks to MEMS technology. Most of MEMS IMU sensors utilize I2C protocol as the main way to send out measurement results to the controller.
You must provide voltage supply (V and G) to the chip and connect data & clock pins (D and C) to corresponding digital pins (SDA and SCL) as shown on Figure 5:
Figure 5: IMU sensor connection
Figure 6: IMU sensor connected to the Arduino board
Usually, IMU sensors from different manufacturers have the same structure in a way that all MEMS chips are connected to the I2C bus. So, to get measurements from gyroscope, accelerometer, and magnetometer, you will use just those two pins.
IMU sensor we use here contains STMicroelectronics chips (L3G4200D and LIS331DLH). If you use any IMU sensor that contains different MEMS chips, you can change the address in the source code to make it work.
Now, let’s program for testing!
You should install the IMU library (click “View Raw” on Github to download IMU_Sensor.zip).
Add the .ZIP Library on Arduino IDE (Sketch >> Include Library >> Add .ZIP Library…)
Figure 7: Adding .ZIP Library on Arduino IDE
You will be able to see the IMU_Sensor library in Arduino libraries folder (Figure 8). Now, we will test the IMU sensor by using “#include <imu.h>”.
Figure 8: IMU_Sensor library appearing in Arduino libraries folder
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
#include <Wire.h> // Library for I²C #include <imu.h> // Library for working with IMU modules Gyroscope gyro; // Create an object to work with Gyroscope Accelerometer accel; // Create an object to work with Accelerometer void setup () { Serial.begin (9600); // Open the serial port Serial.println ("Begin init ..."); // Display a message on the beginning of the initialization gyro.begin (); // Initialize the gyroscope accel.begin (); // Initialization of accelerometers Serial.println ("Init completed"); // Display a message about the successful initialization Serial.println ("Gyroscope\t\t\tAccelerometer"); } void loop () { Serial.print (gyro.readX_DegPerSec ()); // Output angular velocity around the axis X Serial.print ("\t"); Serial.print (gyro.readY_DegPerSec ()); // Output of the angular velocity around the Y axis Serial.print ("\t"); Serial.print (gyro.readZ_DegPerSec ()); // Output of the angular velocity about the Z axis Serial.print ("\t\t"); Serial.print (accel.readX_G ()); // Output of the direction and magnitude of acceleration along the X axis Serial.print ("\t"); Serial.print (accel.readY_G ()); // Output of the direction and magnitude of acceleration along the Y-axis Serial.print ("\t"); Serial.print (accel.readZ_G ()); // Output of the direction and magnitude of acceleration along the Z axis Serial.print ("\t\t"); Serial.println (""); delay (300); } |
Figure 9: IMU sensor outputs
A wireless connection can be established with Bluetooth Bee (bluetooth wireless BT module). The Bluetooth Bee module comes with an on-board antenna. It acts like a transparent serial port, which works with a variety of Bluetooth adapters and Bluetooth phones.
To check the Bluetooth module configuration, put the switch to AT Mode. When the module is on AT mode, the user or a host microcontroller can configure it by sending predefined AT commands through the serial port. AT mode will allow you to request service data from the BT module and to change some of the settings (name, baud rate, parity, and stop bits).
Figure 10: Bluetooth Bee switched to AT Mode
Stack the BT module and the Xbee adapter together and connect the Xbee adapter to your PC via micro USB cable. The LEDs must be switched ON.
Figure 11: Bluetooth Bee is placed on Xbee adapter
Launch the Arduino IDE, choose COM port corresponding to the Xbee adapter from Tools >> Serial Port menu.
Open Arduino’s Serial Monitor (Tools >> Serial Monitor or Ctrl+Shift+M). If the COM port doesn’t show up correctly, install the driver for Xbee USB adapter. Choose “Both NL & CR “, “38400” from corresponding boxes to change the serial setting of your PC to read/write from/to the Xbee adapter.
Send “AT” and receive “OK”.
Send “AT+UART?” and receive serial settings like “9600,0,0”.
If you have serial settings that are different from “9600,0,0”, then send “AT+UART=9600,0,0” command and receive “OK”.
Close the Serial Monitor, disconnect the micro USB cable and the BT module from the Xbee adapter. Don’t forget to switch off AT Mode by turning the switch to the left.
Place Bluetooth Bee on Arduino Wireless Shield and connect the Arduino with USB A-B Cable as shown on Figure 12:
Figure 12: Bluetooth Bee is on Arduino Wireless Shield
After this step, you will be able to find your Bluetooth Bee with your default My Bluetooth device window. Pair your Bluetooth Bee with a default “1234” password. Note which COM port was connected to your device and choose this COM-port in the next sketch.
Here is an Arduino sketch to test Bluetooth connection. (Please note that you will NOT be able to deploy your sketch when Bluetooth Bee is installed into Arduino Wireless Shield.)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
#define LED 13 int pause = 0; // variable to store sent value void setup() { pinMode(LED, OUTPUT); Serial.begin(9600); // open the serial port } void loop() { if (Serial.available() > 0) { // read incoming serial data: String inStr = Serial.readString(); Serial.println("Get Message:"+inStr); pause = inStr.toInt(); } digitalWrite(LED, HIGH); // turn the LED on (HIGH is the voltage level) delay(pause); // wait for a second digitalWrite(LED, LOW); // turn the LED off by making the voltage LOW delay(pause); // wait for a second } |
Figure 13: Testing Bluetooth Bee connection
If you have any comments or questions, please leave them for us at Google +. Follow us there; we will be posting more soon.