Hello,
i'm working to make RC Controlled by Arduino UNO by wireless connected through NRF24L01 at both the Ends
i'm using L293D to control the motor Speed and Direction
able to control the motors direction from TX UNO through RF,
but problem is when there is no input from TX, motor connected in RX UNO should stop, but it is not stopping. Continuously rotating on last command
here is code, kindly advise where i'm doing mistake
RX UNO code
#include <RF24Network.h>
#include <RF24.h>
#include <SPI.h>
// nRF24L01(+) radio attached using Getting Started board
RF24 radio(9,10);
// Network uses that radio
RF24Network network(radio);
// Address of our node
const uint16_t this_node = 0;
// Address of the other node
const uint16_t other_node = 1;
char message;
// map motor poles to Arduino pins
#define Front_Motor_Pole1 3 // Front Motor Pins
#define Front_Motor_Pole2 4 // Front Motor Pins
#define Rear_Motor_Pole1 7 // Rear Motor Pins
#define Rear_Motor_Pole2 8 // Rear Motor Pins
// map L293d motor enable pins to Arduino pins
#define Front_Enable_Pin 5 // Front Motor Speed Control Pin
#define Rear_Enable_Pin 6 // Rear Motor Speed Control Pin
int FrontMotor_Speed = 200; // Front Motor speed
int RearMotor_Speed = 250; // Rear Motor speed
void setup(void)
{
Serial.begin(57600);
Serial.println("Enter your message");
// set mapped L293D motor1 and motor 2 enable pins on Arduino to output (to turn on/off motor1 and motor2 via L293D)
pinMode(Front_Enable_Pin, OUTPUT); // Enable
pinMode(Rear_Enable_Pin, OUTPUT);
// set mapped motor poles to Arduino pins (via L293D)
pinMode(Front_Motor_Pole1 , OUTPUT);
pinMode(Front_Motor_Pole2, OUTPUT);
pinMode(Rear_Motor_Pole1, OUTPUT);
pinMode(Rear_Motor_Pole2 , OUTPUT);
SPI.begin();
radio.begin();
network.begin(/*channel*/ 90, /*node address*/ this_node);
}
void loop(void)
{
// Pump the network regularly
network.update();
// Is there anything Data Ready from Other Node
while( network.available() )
{
// If so, grab it and print it out
RF24NetworkHeader header;
network.read(header,&message,sizeof(message));
Serial.println(message);
if( message == 'w') // If Received 'w' then Call Forward Function
{
Forward();
}
if(message == 'x') // If Received 'x' then Call Reverse Function
{
Reverse();
}
if( message = 'a') // If Received 'a' then Call Left Function
{
Left_Turn();
}
if (message = 'd') // If Received 'd' then Call Right Function
{
Right_Turn();
}
}
//If No Data received from Other Node - Motor gets Stopped
Front_motorstop();
Rear_motorstop();
}
// MOTOR FUNCTIONS
void Front_motorstop() // Stop Front Motor
{
digitalWrite(Front_Motor_Pole1, LOW);
digitalWrite(Front_Motor_Pole2, LOW);
}
void Rear_motorstop() // Stop Rear Motor
{
digitalWrite(Rear_Motor_Pole1, LOW);
digitalWrite(Rear_Motor_Pole2, LOW);
}
void Forward() // Move Forward
{
digitalWrite(Rear_Motor_Pole1, HIGH);
digitalWrite(Rear_Motor_Pole2, LOW);
}
void Reverse() // Move Backward
{
digitalWrite(Rear_Motor_Pole1, LOW);
digitalWrite(Rear_Motor_Pole2, HIGH);
}
void Left_Turn() // Turn Left
{
digitalWrite(Front_Motor_Pole1, LOW);
digitalWrite(Front_Motor_Pole2, HIGH);
}
void Right_Turn() // Turn Right
{
digitalWrite(Front_Motor_Pole1, HIGH);
digitalWrite(Front_Motor_Pole2, LOW);
}
TX UNO Code
#include <RF24Network.h>
#include <RF24.h>
#include <SPI.h>
const int Front_buttonPin = 2; // Front Button
const int Back_buttonPin = 3; // Back Button
const int Left_buttonPin = 4; // Left Button
const int Right_buttonPin = 5; // Right Button
// nRF24L01(+) radio attached using Getting Started board
RF24 radio(9,10);
char byteRead;
char message;
int i=0;
// Network uses that radio
RF24Network network(radio);
// Address of our node
const uint16_t this_node = 1; // Address of JoyStick This Node(Transmitter)
// Address of the other node
const uint16_t other_node = 0; // Address of Car Other Node (Receiver)
void setup(void)
{
pinMode(Front_buttonPin, INPUT); // Enable Buttons
pinMode(Back_buttonPin, INPUT); // Enable Buttons
pinMode(Left_buttonPin, INPUT); // Enable Buttons
pinMode(Right_buttonPin, INPUT); // Enable Buttons
Serial.begin(57600);
SPI.begin();
radio.begin();
network.begin(/*channel*/ 90, /*node address*/ this_node);
}
void loop(void)
{
// Pump the network regularly
network.update();
if(digitalRead(Front_buttonPin) == 1) // IF Front Button is Pressed - "w" is sent to Receiver
{
Serial.println("Front");
byteRead = 'w';
RF24NetworkHeader header(/*to node*/ other_node);
bool ok = network.write(header,&byteRead,sizeof(&byteRead));
}
if(digitalRead(Back_buttonPin) == 1) // IF Back Button is Pressed - "x" is sent to Receiver
{
Serial.println("Back");
byteRead = 'x';
RF24NetworkHeader header(/*to node*/ other_node);
bool ok = network.write(header,&byteRead,sizeof(&byteRead));
}
if(digitalRead(Left_buttonPin) == 1) // IF Left Button is Pressed - "a" is sent to Receiver
{
Serial.println("LeftTurn");
byteRead = 'a';
RF24NetworkHeader header(/*to node*/ other_node);
bool ok = network.write(header,&byteRead,sizeof(&byteRead));
}
if(digitalRead(Right_buttonPin) == 1) // IF Right Button is Pressed - "d" is sent to Receiver
{
Serial.println("RightTurn");
byteRead = 'd';
RF24NetworkHeader header(/*to node*/ other_node);
bool ok = network.write(header,&byteRead,sizeof(&byteRead));
}
}
Thanks
Jay