Hardware components | ||||||
| × | 1 | ||||
| × | 1 | ||||
| × | 2 | ||||
| × | 1 | ||||
| × | 1 | ||||
| × | 2 | ||||
| × | 1 | ||||
| × | 2 | ||||
| × | 1 | ||||
Software apps and online services | ||||||
|
This project shows how to make a Gesture Controlled Car using NRF24L01 Transceiver, MPU6050 Accelerometer and Gyroscope, and Arduino. This project has two parts, transmitter and receiver.
The transmitter section has an Arduino NANO, MPU6050 and NRF24L01.
The receiver section consists of an Arduino UNO, NRF24L01, two DC motors, and an L298N motor driver.
Arduino NANO continuously gets data from MPU6050. NRF24 module connected to NANO transmits this data to NRF24 module connected to Arduino UNO on the receiver. According to the received data, Arduino UNO moves the DC motors.
/*
This program identifies the tilt position
of MPU6050 and assigns a value based on
the position.
This value is sent to the receiver module
through NRF24L01
This program is made by Shreyas for
Electronics Champ YouTube Channel.
Please subscribe to this channel
Thank You
*/
//Include the libraries
#include <Wire.h>
#include <TinyMPU6050.h>
#include <SPI.h>
#include <NRFLite.h>
MPU6050 mpu (Wire);
int message;
const static uint8_t RADIO_ID = 1; // Our radio's id.
const static uint8_t DESTINATION_RADIO_ID = 0; // Id of the radio we will transmit to.
const static uint8_t PIN_RADIO_CE = 7;
const static uint8_t PIN_RADIO_CSN = 8;
struct RadioPacket { // Any packet up to 32 bytes can be sent.
uint8_t FromRadioId;
uint32_t Data;
uint32_t FailedTxCount;
};
//Create NRF24 object
NRFLite _radio;
RadioPacket _radioData;
void setup() {
// Initialization
mpu.Initialize();
// Calibration (wait for about 20s to calibrate)
mpu.Calibrate();
//start up
Serial.begin(9600);
Serial.println("Done Clabration");
if (!_radio.init(RADIO_ID, PIN_RADIO_CE, PIN_RADIO_CSN)) {
Serial.println("Cannot communicate with radio");
while (1); // Wait here forever.
}
_radioData.FromRadioId = RADIO_ID;
}
void loop() {
mpu.Execute();
while (mpu.GetRawAccX() <= -8000) {
//send msg to move front
message = 1;
_radioData.Data = message;
sendData();
Serial.println("front");
mpu.Execute();
}
while (mpu.GetRawAccX() >= 8000) {
//send msg to move back
message = 2;
sendData();
_radioData.Data = message;
Serial.println("back");
mpu.Execute();
}
while (mpu.GetRawAccY() <= -8000) {
//send msg to move left
message = 3;
sendData();
_radioData.Data = message;
Serial.println("left");
mpu.Execute();
}
while (mpu.GetRawAccY() >= 8000) {
//send msg to move right
message = 4;
sendData();
_radioData.Data = message;
Serial.println("right");
mpu.Execute();
}
while (mpu.GetRawAccX() < 8000 and mpu.GetRawAccX() > -8000 and mpu.GetRawAccY() < 8000 and mpu.GetRawAccY() > -8000) {
//send msg to stop
message = 0;
sendData();
_radioData.Data = message;
Serial.println("none");
mpu.Execute();
}
}
void sendData() {
if (_radio.send(DESTINATION_RADIO_ID, &_radioData, sizeof(_radioData))) { // Note how '&' must be placed in front of the variable name.
}
else {
Serial.println("Failed");
_radioData.FailedTxCount++;
}
delay(500);
mpu.Execute();
}
/*
This program receives the message from
the transmitter and moves the car
accordingly.
This program is made by Shreyas for
Electronics Champ YouTube Channel.
Please subscribe to this channel
Thank You
*/
//Include the libraries
#include <SPI.h>
#include <NRFLite.h>
//Initializing the variables
boolean x = 0;
int directionOfMovement = 0;
int leftMotorForward = 2;
int leftMotorBackward = 3;
int rightMotorForward = 4;
int rightMotorBackward = 5;
String message;
const static uint8_t RADIO_ID = 0; // Our radio's id. The transmitter will send to this id.
const static uint8_t PIN_RADIO_CE = 7;
const static uint8_t PIN_RADIO_CSN = 8;
struct RadioPacket { // Any packet up to 32 bytes can be sent.
uint8_t FromRadioId;
uint32_t Data;
uint32_t FailedTxCount;
};
//Create NRF object
NRFLite _radio;
RadioPacket _radioData;
void setup() {
Serial.begin(9600);
//Set the pin modes
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(12, OUTPUT);
pinMode(13, OUTPUT);
if (!_radio.init(RADIO_ID, PIN_RADIO_CE, PIN_RADIO_CSN)) {
Serial.println("Cannot communicate with radio");
while (1); // Wait here forever.
}
}
void loop() {
while (_radio.hasData()) {
_radio.readData(&_radioData); // Note how '&' must be placed in front of the variable name.
message = _radioData.Data;
Serial.println(message);
directionOfMovement = message.toInt();
moveAccordingly();
}
}
//this function moves the car according to the message
void moveAccordingly() {
if (directionOfMovement == 1) {
front();
Serial.println("front");
}
else if (directionOfMovement == 2) {
back();
Serial.println("back");
}
else if (directionOfMovement == 3) {
left();
Serial.println("left");
}
else if (directionOfMovement == 4) {
right();
Serial.println("right");
}
else if (directionOfMovement == 0) {
none();
Serial.println("none");
}
}
void front() {
digitalWrite(leftMotorForward, HIGH);
digitalWrite(rightMotorForward, HIGH);
digitalWrite(leftMotorBackward, LOW);
digitalWrite(rightMotorBackward, LOW);
}
void back() {
digitalWrite(leftMotorBackward, HIGH);
digitalWrite(rightMotorBackward, HIGH);
digitalWrite(leftMotorForward, LOW);
digitalWrite(rightMotorForward, LOW);
}
void left() {
digitalWrite(leftMotorForward, LOW);
digitalWrite(rightMotorForward, HIGH);
digitalWrite(leftMotorBackward, LOW);
digitalWrite(rightMotorBackward, LOW);
}
void right() {
digitalWrite(leftMotorForward, HIGH);
digitalWrite(rightMotorForward, LOW);
digitalWrite(leftMotorBackward, LOW);
digitalWrite(rightMotorBackward, LOW);
}
void none() {
digitalWrite(leftMotorForward, LOW);
digitalWrite(rightMotorForward, LOW);
digitalWrite(leftMotorBackward, LOW);
digitalWrite(rightMotorBackward, LOW);
}
Electronics Champ
3 projects • 10 followers
Projects based on breadboard electronics and Arduino with clear step-by-step instructions, circuit diagrams, schematics, and source code.
Comments