I have made one project that is two BO dc Motor (300rpm) and one servo controlled by remote (nrf24l01) with joy stick and buttons
I have used two push button this controlled motor 2 rotation i.e, clock and anticlockwise.
I have used joy stick ,X axis controlled Motor 1 rotation i.e, clock and anticlockwise.Y axis controlled servo
I have used L298N Motor driver for two motor.
I used the NRF24L01 with 3.5volt adaptor.
Two number External dc power supply (230AC-24VDC-5A) with Buck converter (3A) used for TX and RX circuit seperately.
Now coming to my problem.
If i have controlled the Motor2 by push button and servo controlled by joy stick (Yaxis), system working satisfactory.
But when i controlled the BO motor by the joy stick(Xaxis) ,the connection between the TX and RX is disconnected shortly after the operation.Than RX i has to be again to start work again.
My TX code is here
#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
#define CE_PIN 9
#define CSN_PIN 10
#define yAxis A0 // A0 for Arduino UNO
#define xAxis A1 // A1 for Arduino UNO
// NOTE: the "LL" at the end of the constant is "LongLong" type
const uint64_t pipe = 0xE8E8F0F0E1LL; // Define the transmit pipe
/*-----( Declare objects )-----*/
RF24 radio(CE_PIN, CSN_PIN); // Create a Radio
/*-----( Declare Variables )-----*/
int joystick[6]; // 10 element array holding Joystick reading and 4 buttons
int HstUp = 2;
int HstDwn = 3;
void setup() {
Serial.begin(9600);
radio.begin();
radio.openWritingPipe(pipe);
pinMode(xAxis,INPUT);
pinMode(yAxis,INPUT);
pinMode(HstUp,INPUT_PULLUP);
pinMode(HstDwn,INPUT_PULLUP);
delay(1000);
}
void loop() {
radio.stopListening();
radio.write( joystick, sizeof(joystick) );
joystick[0] = analogRead(xAxis);
joystick[1] = analogRead(yAxis);
joystick[2] = digitalRead(HstUp);
joystick[3] = digitalRead(HstDwn);
Serial.print("X = ");
Serial.print(analogRead(xAxis));
Serial.print(" Y = ");
Serial.print(analogRead(yAxis));
Serial.print(" Up = ");
Serial.print(digitalRead(HstUp));
Serial.print(" Down = ");
Serial.print(digitalRead(HstDwn));
}
My RX code is here
#include <SPI.h>
#include <nRF24L01.h>
#include <printf.h>
#include <RF24.h>
#include <RF24_config.h>
#include <Servo.h>
#define CE_PIN 9
#define CSN_PIN 10
const uint64_t pipe = 0xE8E8F0F0E1LL; // Define the transmit pipe
int servoVal; // variable to read the value from the analog pin
Servo myservo1; // create servo1
const int servo1 = 6;
RF24 radio(CE_PIN, CSN_PIN);
int joystick[6]; // 8 element array holding Joystick readings Xangle and 7 button state
int joystickX;
int joystickY;
int Mtr1A = 2; // digital out put
int Mtr1B = 3; // digital out put
int Mtr2A = 4; // digital out put
int Mtr2B = 5; // digital out put
void setup() {
myservo1.attach(servo1);
Serial.begin(9600);
pinMode(Mtr1A, OUTPUT);
pinMode(Mtr1B, OUTPUT);
pinMode(Mtr2A, OUTPUT);
pinMode(Mtr2B, OUTPUT);// put your setup code here, to run once:
pinMode(joystickX, OUTPUT);
pinMode(joystickY, OUTPUT);
radio.begin();
radio.openReadingPipe(1, pipe);
radio.startListening();;
} //--(end setup )-
void loop() {
// put your main code here, to run repeatedly:
radio.startListening();
if ( radio.available() )
{
radio.read( &joystick, sizeof(joystick));
joystickX = map(joystick[0], 0, 1023, 179, 0);; // turn value of 0-1023
joystickY = map(joystick[1], 0, 1023, 179, 0);
int HstUp = joystick[2];
int HstDwn = joystick[3];
////////////////Button oprtn////////////
if (HstUp == HIGH) {
digitalWrite(Mtr2A, LOW);
digitalWrite(Mtr2B, HIGH);
Serial.println ("UP");
}
else {
digitalWrite(Mtr2A, HIGH);
}
if (HstDwn == HIGH) {
digitalWrite(Mtr2A, HIGH);
digitalWrite(Mtr2B, LOW);
Serial.print ("DWN");
}
else {
digitalWrite(Mtr2B, HIGH);
}
/////////////Joy Stick/////////////
if (joystickX < 50)
{
//Serial.println (joystickX);
digitalWrite(Mtr1A, LOW);
digitalWrite(Mtr1B, HIGH);
//digitalWrite(led3, HIGH);
delay(50);
}
if (joystickX > 130)
{
digitalWrite(Mtr1A, HIGH);
digitalWrite(Mtr1B, LOW);
delay(50);
}
if (joystickX > 55 && joystickX < 125 )
{
digitalWrite(Mtr1A, HIGH);
digitalWrite(Mtr1B, HIGH);
}
// Serial.println (joystickX);
Serial.println (joystickY);
servoVal = joystickY; // scale it to use it with the servo (result between 0 and 180)
myservo1.write(servoVal);
}
}
I don't know whether the problem in my code .Expecting valuable advice from the arduino Forum members.
Thank you