We try to remote control an elegoo robot car, (https://www.elegoo.com/product/elegoo-uno-project-smart-robot-car-kit-v1-0/) with a RF-433 transmitter and receiver. The car has 4 dc motors, controlled by an L298N controller and the motors are powered by 2 18650 4200mAh 3.7V Li-ion batteries which also power an Arduino Uno. When we try to control the car with PWM through analogWrite without the RF-433 it works fine, but when RF is used motors on one side of the car does not work. We have narrowed down the problem to a specific part of the code:
if (!Radio.init()) {
Serial.println("init failed");
}
When this part is included the problem occurs. But when commented out the car moves fine. Which is why we think that there is an interference, between the RH_ASK library and the arduino code. The rest of the code is here.
#include < RH_ASK.h >
#include < SPI.h > // Not actually used but needed to compile
RH_ASK Radio(2000, 0);
// Pin connections to L298n motor controller
int in1 = 9;
int in2 = 8;
int in3 = 7;
int in4 = 6;
/*define channel enable output pins*/
int ENA = 10;
int ENB = 5;
/*define forward function*/
void _mForward() {
analogWrite(ENA, 130);
analogWrite(ENB, 130);
digitalWrite(in1, LOW);
digitalWrite(in2, HIGH);
digitalWrite(in3, LOW);
digitalWrite(in4, HIGH);
Serial.println("Forward");
}
// function to turn right
void _mRight() {
analogWrite(ENA, 130);
analogWrite(ENB, 130);
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
digitalWrite(in3, LOW);
digitalWrite(in4, HIGH);
Serial.println("Right");
}
// Function to stop the car
void _mFreeze() {
analogWrite(ENA, LOW);
analogWrite(ENB, LOW);
}
void setup() {
Serial.begin(9600); // Debugging only
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);
pinMode(in3, OUTPUT);
pinMode(in4, OUTPUT);
pinMode(ENA, OUTPUT);
pinMode(ENB, OUTPUT);
if (!Radio.init()) { // initialize rf communication
Serial.println("init failed");
}
}
void loop() {
_mForward();
uint8_t buf[RH_ASK_MAX_MESSAGE_LEN]; //Read transmitted message into an array
uint8_t buflen = sizeof(buf);
// stop the car if we receive a message
while (Radio.recv(buf, & buflen)) {
_mFreeze();
}
}
Another program runs the transmission and sends a message when a button is pressed.