4*4 Racing Vehicle
Power Drive Unit
It a set of motor and gear to reduce/increase RPM and Torque
Receiver and Transmitter circuit diagram
Receiver
TRANSMITTER CODES:-//SUBSCRIBE "TESTFEST"
// 6 Channel Transmitter |
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
const uint64_t pipeOut = 0xE9E8F0F0E1LL; //IMPORTANT: The same as in the receiver 0xE9E8F0F0E1LL |
RF24 radio(9, 10); // select CE,CSN pin |
struct Signal {
byte throttle;
byte pitch;
byte roll;
byte yaw;
byte aux1;
byte aux2;
//#define SW1 D4;
//#define SW2 D5;
};
Signal data;
void ResetData()
{
data.throttle = 0; // Motor stop | Motor Kapalı (Signal lost position |
data.pitch = 127; // Center | Merkez (Signal lost position |
data.roll = 127; // Center | merkez (Signal lost position |
data.yaw = 127; // Center | merkez (Signal lost position |
data.aux1 = 0; // Center | merkez (Signal lost position |
data.aux2 = 0; // Center | merkez (Signal lost position |
}
void setup()
{
//Start everything up
radio.begin();
radio.openWritingPipe(pipeOut);
radio.setAutoAck(false);
radio.setDataRate(RF24_250KBPS);
radio.setPALevel(RF24_PA_HIGH);
radio.stopListening(); //start the radio comunication for Transmitter |
ResetData();
// pinMode(SW1,INPUT_PULLUP);
// pinMode(SW2,INPUT_PULLUP);
}
// Joystick center and its borders |
int mapJoystickValues(int val, int lower, int middle, int upper, bool reverse)
{
val = constrain(val, lower, upper);
if ( val < middle )
val = map(val, lower, middle, 0, 128);
else
val = map(val, middle, upper, 128, 255);
return ( reverse ? 255 - val : val );
}
void loop()
{
// Control Stick Calibration
// Setting may be required for the correct values of the control levers. | :Kontrol kolların doğru değerleri için ayar gerekebilir.
data.throttle = mapJoystickValues( analogRead(A0), 13, 512, 1024, true ); // "true" or "false" for signal direction |
data.roll = mapJoystickValues( analogRead(A3), 0, 516, 1024, true ); // "true" or "false" for servo direction |
data.pitch = mapJoystickValues( analogRead(A2), 0, 526, 1024, false ); // "true" or "false" for servo direction |
data.yaw = mapJoystickValues( analogRead(A1), 0, 502, 1024, false ); // "true" or "false" for servo direction |
data.aux1 = digitalRead(4);
data.aux2 = digitalRead(5);
// int SWITCH[2];
// SWITCH[0] = digitalRead(SW1);
// SWITCH[1] = digitalRead(SW2);
//
// radio.write(&switch,sizeof(Switch));
radio.write(&data, sizeof(Signal));
}
RECEIVER CODES:-// 6 Channel Receiver |
// PWM output on pins D2, D3, D4, D5, D6, D7
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <Servo.h>
int ch_width_1 = 0;
int ch_width_2 = 0;
int ch_width_3 = 0;
int ch_width_4 = 0;
int ch_width_5 = 0;
int ch_width_6 = 0;
Servo ch1;
Servo ch2;
Servo ch3;
Servo ch4;
Servo ch5;
Servo ch6;
struct Signal {
byte throttle;
byte pitch;
byte roll;
byte yaw;
byte aux1;
byte aux2;
};
Signal data;
const uint64_t pipeIn = 0xE9E8F0F0E1LL;
RF24 radio(9, 10);
void ResetData()
{
// Define the inicial value of each data input. |
// The middle position for Potenciometers. (254/2=127) |
data.roll = 127; // Center |
data.pitch = 127; // Center |
data.throttle = 13; // Motor Stop |
data.yaw = 127; // Center |
data.aux1 = 0; // Center |
data.aux2 = 0; // Center |
}
void setup()
{
//Set the pins for each PWM signal | Her bir PWM sinyal
ch1.attach(2);
ch2.attach(3);
ch3.attach(4);
ch4.attach(5);
ch5.attach(6);
ch6.attach(7);
//Configure the NRF24 module
ResetData();
radio.begin();
radio.openReadingPipe(1,pipeIn);
radio.setAutoAck(false);
radio.setDataRate(RF24_250KBPS);
radio.setPALevel(RF24_PA_HIGH);
radio.startListening(); //start the radio comunication for receiver |
pinMode(6,OUTPUT);
}
unsigned long lastRecvTime = 0;
void recvData()
{
while ( radio.available() ) {
radio.read(&data, sizeof(Signal));
lastRecvTime = millis(); // receive the data |
}
}
void loop()
{
recvData();
unsigned long now = millis();
if ( now - lastRecvTime > 1000 ) {
ResetData(); // Signal lost.. Reset data |
ch_width_4 = map(data.yaw, 0, 255, 1000, 2000); // pin D5 (PWM signal)
ch_width_2 = map(data.pitch, 0, 255, 1000, 2000); // pin D3 (PWM signal)
ch_width_3 = map(data.throttle, 0, 255, 1000, 2000); // pin D4 (PWM signal)
ch_width_1 = map(data.roll, 0, 255, 1000, 2000); // pin D2 (PWM signal)
ch_width_5 = map(data.aux1, 0, 1, 1000, 2000); // pin D6 (PWM signal)
ch_width_6 = map(data.aux2, 0, 1, 1000, 2000); // pin D7 (PWM signal)
//ch_width_5 = map(data.aux1,
//int AUX[2];
//radio.read(&,sizeof(Signal));
//if([CH_width_5]==0){
// digitalWrite(CH_width_5,1);
//}
//if([CH_width_5]==1){
// digitalWrite(CH_width_5,0);
//}
// if([CH_width_6]==0){
// digitalWrite(CH_width_6,1);
// }
//
// if([CH_width_6]==1){
// digitalWrite(CH_width_6,0);
// }
// Write the PWM signal | PWM
ch1.writeMicroseconds(ch_width_1);
ch2.writeMicroseconds(ch_width_2);
ch3.writeMicroseconds(ch_width_3);
ch4.writeMicroseconds(ch_width_4);
ch5.writeMicroseconds(ch_width_5);
ch6.writeMicroseconds(ch_width_6);
}
Relay Circuit Diagram
Drive 4x4 RC