Gesture Control Car MPU6050 and NRF24L01
The gesture control robot is popular common type of projects made by hobbyists. The concept behind it is simple: the orientation of the palm controls the motion of the robot car.
MPU6050 to sense the orientation of the wrist and transmits it to the arduino in digital value. The value range is from -32768 to +32767 for each axis.
Module based on the NRF24L01 chip having two-way communication on the 2.4GHz band. The circuit board has a built-in antenna. The module communicates with microcontrollers via SPI reference. The range of such a module in the theory is up to 100 meters. In addition, you can control the power of the transmitter to reduce power consumption. The motors are controlled by the L298N module powered by six AA / R6 batteries.
List Elements:

Transmitter:

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 |
#include <SPI.h> #include <nRF24L01.h> #include <RF24.h> #include<Wire.h> RF24 radio(9,10); // CE, CSN const byte address[6] = "00001"; int dupa=0; int joystick[2]; const int MPU_addr=0x68; // I2C address of the MPU-6050 void setup(){ Serial.begin(9600); radio.begin(); radio.openWritingPipe(address); radio.setPALevel(RF24_PA_MAX); radio.stopListening(); Wire.begin(); Wire.beginTransmission(MPU_addr); Wire.write(0x6B); // PWR_MGMT_1 register Wire.write(0); // set to zero (wakes up the MPU-6050) Wire.endTransmission(true); } void loop(){ Wire.beginTransmission(MPU_addr); Wire.write(0x3B); // starting with register 0x3B (ACCEL_XOUT_H) Wire.endTransmission(false); Wire.requestFrom(MPU_addr,14,true); // request a total of 14 registers joystick[0]=Wire.read()<<8|Wire.read(); // 0x3B (ACCEL_XOUT_H) & 0x3C (ACCEL_XOUT_L) joystick[1]=Wire.read()<<8|Wire.read(); // 0x3D (ACCEL_YOUT_H) & 0x3E (ACCEL_YOUT_L) joystick[2]=Wire.read()<<8|Wire.read(); // 0x3F (ACCEL_ZOUT_H) & 0x40 (ACCEL_ZOUT_L) radio.write( joystick, sizeof(joystick) ); } |
Receiver:

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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
/* * Arduino Car NRF24L01 * * ForbiddenBit.com */ #include <SPI.h> #include <nRF24L01.h> #include <RF24.h> #define enA 6 #define in1 7 #define in2 5 #define enB 3 #define in3 4 #define in4 2 RF24 radio(9,10); // CE, CSN const byte address[6] = "00001"; char receivedData[32] = ""; int16_t AcX,AcY,AcZ,Tmp,GyX,GyY,GyZ; int joystick[2]; int z0 = 3000; int zstop = 13000; int y0 = 10000; void setup() { pinMode(enA, OUTPUT); pinMode(enB, OUTPUT); pinMode(in1, OUTPUT); pinMode(in2, OUTPUT); pinMode(in3, OUTPUT); pinMode(in4, OUTPUT); Serial.begin(9600); radio.begin(); radio.openReadingPipe(0, address); radio.setPALevel(RF24_PA_MAX); radio.startListening(); digitalWrite(in1, LOW); digitalWrite(in2, LOW); digitalWrite(in3, LOW); digitalWrite(in4, LOW); } void loop() { if (radio.available()) { // If the NRF240L01 module received data radio.read( joystick, sizeof(joystick) ); radio.read(&receivedData, sizeof(receivedData)); AcX = joystick[0]; AcY = joystick[1]; // DELETE //----------------------------- Serial.print("AcX :"); Serial.print(AcX); Serial.print(" "); Serial.print("AcY :"); Serial.print(AcY); delay(300); //----------------------------- if(AcX<-6000){ //Forward Serial.print(" Forward "); digitalWrite(enA, HIGH); digitalWrite(enB, HIGH); digitalWrite(in1, HIGH); digitalWrite(in2, LOW); digitalWrite(in3, HIGH); digitalWrite(in4, LOW); } else if(AcX>6000){ //BACK Serial.print(" BACK "); digitalWrite(enA, HIGH); digitalWrite(enB, HIGH); digitalWrite(in2, HIGH); digitalWrite(in1, LOW); digitalWrite(in4, HIGH); digitalWrite(in3, LOW); } else if(AcY<-6000 ){ ///LEFT Serial.print(" LEFT "); digitalWrite(enA, HIGH); digitalWrite(enB, HIGH); digitalWrite(in1, HIGH); digitalWrite(in2, LOW); digitalWrite(in3, LOW); digitalWrite(in4, HIGH); } else if(AcY>6000){ //RIGHT Serial.print(" RIGHT "); digitalWrite(enA, HIGH); digitalWrite(enB, HIGH); digitalWrite(in1, LOW); digitalWrite(in2, HIGH); digitalWrite(in3, HIGH); digitalWrite(in4, LOW); } else if(AcX<6000 && AcX>-6000 && AcX<6000 && AcX>-6000 ) { //Stop Serial.print(" Stop "); digitalWrite(enA, LOW); digitalWrite(enB, LOW); digitalWrite(in1, LOW); digitalWrite(in2, LOW); digitalWrite(in3, LOW); digitalWrite(in4, LOW); } } } |
After uploading sketches to arduinos, connect the receiver to the computer and open the SERIAL MONITOR. Turn on the transmitter and see you see the values of the X axis and Y axis. Now set the values for each direction of travel. STOP value: if the FORWARD value is AcX <-6000 and the BACK value is AcX> 6000. The STOP value will be the range between these values AcX <6000 && AcX> -6000.

Do the same for the Y axis. If your receiver is now well configured, remove this piece of code and upload the program.
1 2 3 4 5 6 7 8 9 10 11 |
// DELETE // ----------------------------- Serial.print ("AcX:"); Serial.print (ACX); Serial.print (""); Serial.print ("AcY:"); Serial.print (ACY); delay (300); // ----------------------------- |