Have you ever tired of controlling everything with buttons? Thought of controlling something with simple hand movements by sitting on your lazy couch? If yes, then you are at the right site. In this tutorial we are going to control a robot driven by two DC motors by simply using hand movements. There are different kind of sensors to detect your hand movement like flux sensors, Accelerometers and other gravity based sensors. So for wireless transmission we are going to use RF 434 module which transmit 4 bit data. 4 bit data means you can transmit 16 different combinations i.e., 0000 to 1111. Further in this tutorial we will use an encoder and decoder to avoid interference in the air interface. A motor driver will drive the motors from using the decoder data.
Gesture Controlled Robot Using Raspberry Pi
We use our Raspberry pi at the transmitter end to analyze the sensor data and to transmit a data combination to the motor driver to drive the motors accordingly so that the robot can hover around. We will be using a 12 V battery on robot to power the decoder module, receiver module and the motors. At the transmitter end sensors and transmitter encoder module is powered by raspberry pi itself.
Gesture Controlled Robot Using Raspberry Pi – Block Diagram
Gesture Controlled Robot Using Raspberry Pi – Transmitter End
In transmitter side we have Accelerometer, raspberry pi , encoder module and RF transmitter. The gesture data flows from accelerometer to the raspberry pi and there it is processed to decide the movement of the robot and the data for motion is transferred to the encoder module via GPIO pins. The encoder module encodes the data and transmit into air interface with the help of RF transmitter.
Gesture Controlled Robot Using Raspberry Pi – Receiver End
Gesture Controlled Robot Using Raspberry Pi – Receiver End
The RF receiver from the receiver end gets the data from the air interface and gives it to the decoder module. The decoder module decodes the received data and provides it to the motor driver L293D. From the motor driver the motors are driven according to the gesture data.
Aceleration is the measurement of the change in velocity, or speed divided by time. For example if a car moves from rest 0 to 60 Km/hr in 10 seconds, the car is accelerating at 6Km/hr. So what it has to do with my hand gesture?
An accelerometer is an electromechanical device used to measure acceleration forces. Such forces may be static, like the continuous force of gravity or, as is the case with many mobile devices, dynamic to sense movement or vibrations. By measuring the amount of static acceleration due to gravity, you can find out the angle the device is tilted at with respect to the earth. By sensing the amount of dynamic acceleration, you can analyze the way the device is moving.
Some accelerometers use the piezoelectric effect -they contain microscopic crystal structures that get stressed by accelerative forces, which causes a voltage to be generated. Another way to do it is by sensing changes in capacitance. If you have two microstructures next to each other, they have a certain capacitance between them. If an accelerative force moves one of the structures, then the capacitance will change. Add some circuitry to convert from capacitance to voltage, and you will get an accelerometer.
Accelerometers are low power devices which output acceleration in the form of Analog voltage and some accelerometers in digital form. Analog accelerometers like ADXL 335 gives you 3 analog output X,Y,Z base on the axis of your movement. You can convert these analog voltages into digital voltages by means of an ADC. Digital accelerometers such as ADXL345 will communicate through SPI or I2C protocols. This have less very noise and most reliable
There is another sensor MPU6050 which has both accelerometer as well as gyroscope in it. That can also be used in place of accelerometer. The address of ADXL345 and MPU6050 differs while connecting in I2C mode with raspberry pi, for ADXL 0x53 and MPU it is 0x68. In this tutorial i’ll explain how to use both ADXL345 and MPU6050.
Now we will interface our accelerometer ADXL 345 and MPU 6050 to our raspberry pi and check the readings of the sensor. I believe your raspberry pi is installed with latest operating system and python in it, since we are going to use python code here.
Lets connect ADXL345/MPU6050 to our raspberry pi. Here we are going to use I2C protocol to communicate between devices. In I2C protocol the data is transferred via SDA(Serial Data ) and clock in SCL (Serial Clock) . It is asynchronous half duplex communication protocol. The Master controls the whole process and slaves responds according to master commands. Data rate is determined by the slave’s capable frequency. There are only 4 connections between master and slave here 3V, Gnd, SCL and SDA .
ADXL345 Digital Accelerometer
From the GPIO pin out diagram you can see the SDA and SCL pins on Rpi and connect it to the ADXL345/MPU6050 SDA and SCL pins respectively. Power the sensor using RPi itself. Now the connections are done.
Raspberry pi 3 GPIO Header
Before testing the sensor let’s install python-smbus for I2c protocol in rpi and enable the I2C protocol in our RPi.
sudo apt-get install python-smbus i2c-tools
Enabling the I2C in RPi:
Go to interface options and enable I2c protocol.
Then include the i2c specification lines by these commands.
sudo nano /etc/modules
Add these lines
If you’re using a old rpi remove i2c from backlist by using these commands
sudo nano /etc/modprobe.d/raspi-blacklist.conf
Comment out (#) blacklist i2c-bcm2708
Test the connection by using this command. This will show the address of the sensor connected to our pi.
sudo i2c detect -y 1
Adxl will be found in 0x53 and Mpu will be found in 0x68 or 0x69
Now we will download a pre-written library for ADXL345 for pi in python from Github and test the sensor output. Use these commands.
git clone https://github.com/pimoroni/adxl345-python
sudo python example.py
Example.py is the program which outputs the X,Y and Z values as shown below.
We can modify this program or use this for our project.
For MPU6050 pimoroni program wont work, so we will use a different python module from github.
By using these commands.
git clone https://github.com/Tijndagamer/mpu6050.git
python setup.py install
To check our sensor connection and address open terminal and type the command below. It will show the sensor address at 0x68 or 0x69 as shown below.
And to test our sensor data go to the python editor and type these commands only by one to see the sensor output.
from mpu6050 import mpu6050
A step further you can now determine the threshold values of 4 different position for the movement of right, left, forward and backward and note it down. Calibration can be done based on your sensor values at different positions like keep it in a position which you want for the forward movement and note down 5 similar values and round it off to a threshold, so that if the sensor crosses the rounded off value a condition statement in the program can be enabled. Similarly calibrate it for all other movements like left, right ,back and stop.
Read More Information….