Hello everyone.
I want to make the most controlled car with Arduino.
I used 1 arduino nano, 1 MPU6050 6 Axis Acceleration and Gyro Sensor, 1 nRF24L01 2.4GHz Wireless Module for hand control. The necessary connections were made. Gyro sensor is working.
The code used for the transmitter:
#include <SPI.h>
#include <RF24.h>
#include <Wire.h>
#include <MPU6050.h> //Mpu6050 library
MPU6050 acceleration_sensor;
int x, y, z; //defining acceleration
RF24 radio(7, 8); // CE, CSN
int data[2]; // Defining array for X and Y plane
void setup()
{
Wire.begin();
ivme_sensor.initialize();
radio.begin();
radio.openWritingPipe(1234);
}
void loop()
{
acceleration_sensor.getAcceleration(&x, &y, &z); // read acceleration and gyro values
data[0] = map(x, -17000, 17000, -255, 255 ); //X plane data (forward-backward)
data[1] = map(y, -17000, 17000, -255, 255); //Y plane data (right-left)
radio.write(data, sizeof(data));
}
I used arduino toolkit for the receiver. I used L298N motor driver, arduino uno, the sensor used for the transmitter. I connected a 9v battery to both arduino uno and l298n motor driver differently to power it.
The code used for this:
#include <SPI.h>
#include <RF24.h>
RF24 radio(7, 8); // CE, CSN
int data[2];// X ve Y düzlemi için dizi tanımlama
int in1 = 5;
int in2 = 6;
int in3 = 9;
int in4 = 10;
void setup() {
radio.begin();
radio.openReadingPipe(1,1234);
radio.startListening();
}
void loop() {
if (radio.available()) {
radio.read(data, sizeof(data));
if(data[0] > 50)//ileri
{
analogWrite(in1,data[0]);
analogWrite(in2,0);
analogWrite(in3,data[0]);
analogWrite(in4,0);
}
if(data[0] < -50)//geri
{
analogWrite(in1,0);
analogWrite(in2,-data[0]);
analogWrite(in3,0);
analogWrite(in4,-data[0]);
}
if(data[1] > 50)//sol
{
analogWrite(in1,0);
analogWrite(in2,data[1]);
analogWrite(in3,data[1]);
analogWrite(in4,0);
}
if(data[1] < -50)//sag
{
analogWrite(in1,-data[1]);
analogWrite(in2,0);
analogWrite(in3,0);
analogWrite(in4,-data[1]);
}
if(data[0] > -50 && data[0] < 50 && data[1] > -50 && data[1] < 50)//dur
{
analogWrite(in1,0);
analogWrite(in2,0);
analogWrite(in3,0);
analogWrite(in4,0);
}
}
}
These are the codes. But I think that the data from the transmitter is not going to the receiver because the vehicle is not moving. What should I do about this. I am waiting for your help.