trying to get two joysticks to run a servo motor and a DC motor. There are 2 Arduino nanos. 1 reads the joysticks and transmits the other receives the transmission and runs the servo and motor. latency with receiver is obvious and sporadic. Also, when it eventually receives motor DC data it crashes. I have connected both servo and DC motor to a separate 5V power supply with a current limit of 1A.
Transmit code:
//transmitter variables---------------------------------------------------
#include <RH_ASK.h>
#include <SPI.h> // Not actually used but needed to compile
RH_ASK driver(1000, 4, 2, 5);
//steering variables------------------------------------------------------
int potpin = A0; // analog pin used to connect the potentiometer
int val; // variable to read the value from the analog pin
//throttle variables-----------------------------------------------------
#define POTENTIOMETER_PIN A1 // Analog pin connected to potentiometer
int potValue;
///////////////////////////
void setup() {
Serial.begin(9600);
//transmitter-------------------------------------------------
if (!driver.init())
Serial.println("init failed");
}
///////////////////////////
void loop() {
//steering----------------------------------------------------
val = analogRead(potpin);
Serial.print("val = ");
Serial.println(val);
//throttle---------------------------------------------------
potValue = analogRead(POTENTIOMETER_PIN);
Serial.print(" potValue = ");
Serial.println(potValue);
//transmitter--------------------------------------------
// Example code for transmitting with RadioHead
// 'driver' is the RadioHead object
// You would first convert the integer to a byte array
uint8_t buf[4];
//steering send
buf[0] = (val >> 8) & 0xFF; // High byte
buf[1] = val & 0xFF; // Low byte
//throttle send
buf[2] = (potValue >> 8) & 0xFF; // High byte
buf[3] = potValue & 0xFF; // Low byte
//transmit 4 byte buffer
driver.send(buf, sizeof(buf));
driver.waitPacketSent();
delay(5);
}
Receiver code:
//recieving variables
#include <RH_ASK.h>
#include <SPI.h>
RH_ASK driver(1000, 2, 4, 5);
//steering variables
#include <ServoTimer2.h>
#define steeringPin 9
// create Servo object to control a servo
ServoTimer2 servoSteering;
int steerVal; // variable to read the value from the analog pin
int steeringPulse;
//throttle variables
const int forwardPin = 6;
const int backwardPin = 10;
int throttleVal;
int speed;
/////////////////////////////////
void setup() {
Serial.begin(9600);
//reciever
if (!driver.init()) {
Serial.println("init failed");
}
//steering
servoSteering.attach(steeringPin); // attaches the servo on pin 9 to the Servo object
//throttle
pinMode(forwardPin, OUTPUT);
pinMode(backwardPin, OUTPUT);
}
/////////////////////////////////
void loop() {
//reciever----------------------------------------------------
// Example code for the receiver Arduino
// 'manager' is the RadioHead object
uint8_t buf[RH_ASK_MAX_MESSAGE_LEN];
uint8_t len = sizeof(buf);
if (driver.recv(buf, &len)) {
// Check if the received message is the correct size
if (len == 4) {
// Reconstruct the 10-bit integer
steerVal = (buf[0] << 8) | buf[1];
Serial.println(steerVal);
throttleVal = (buf[2] << 8) | buf[3];
Serial.print("Steering: ");
Serial.print(steerVal);
Serial.print(" | Throttle: ");
Serial.println(throttleVal);
int steeringPulse = map(steerVal, 0, 1023, 750, 2250);
servoSteering.write(steeringPulse);
}
if (throttleVal > 506 && throttleVal < 518) {
analogWrite(forwardPin, 0);
analogWrite(backwardPin, 0);
} else {
if (throttleVal > 512) {
speed = map(throttleVal, 511, 1023, 0, 255);
analogWrite(forwardPin, speed);
analogWrite(backwardPin, 0);
} else {
speed = map(throttleVal, 0, 511, 255, 0);
analogWrite(backwardPin, speed);
analogWrite(forwardPin, 0);
}
}
}
}
Would it be possible to send your schematic in a higher resolution as what you have posted is too small to see correctly.
Also why have you used two Arduinos ? It is a common beginners mistake to think that using two processors is the answer to a perceived problem. When normally it is not and causes more problems than you might ay first think.
We want Annotated Schematics: They are essential because they show exactly how your circuit is set up. Without them, it's difficult for anyone to understand what you’ve done, which makes troubleshooting nearly impossible. Fritzing diagrams or unclear pictures are not enough. A good schematic can save days in time when problems occur.
It’s important to include every connection, especially power, ground and power sources in your schematic. Missing these details makes it hard to determine if a setup issue might be causing your problem.
Many modules look similar and may even have the same name, but they can function differently. This is why we always ask for links to detailed technical information, not just sales pages like those on Amazon, which often lack the specifics we need.
Please understand we don’t know your skill level or what resources you have available. If you’re missing key technical details or seem unprepared, it may indicate that you need to spend more time learning the basics before starting your project.
I have used two Arduinos since I am trying to make an RC car and wish to have the transmitting circuit as a handheld remote and the receiver circuit on the car, being able to receive over a larger distance. The original schematic showed both Arduinos linked to the same power supply. I have fixed this in the updated schematic attached.
The modules I am using to transmit and receive are, RF 433Mh transmitter and receiver modules. I got them from ebay.ch and have struggled to find out any more about them. they were 'cheeeeep' as chicken feed so I guess that they are not the greatest.
There seems to be a problem with sending messages faster than the receiver can handle. It does a lot of stuff before trying to read another message. Try increasing the transmitter delay.
Now I can see that you have connected the L293D. incorrectly.
There are two inputs to this device, one is to define the logic level of the input / outputs of the device. This is correct on your wiring.
The other should be connected to the motor drive voltage, but you have also connected this to 5V as well. This is way too low to actually drive a motor. This needs to be connected to your motor drive voltage, I guess this should be 12V or so, in order that the motor will move.
I've dropped baud rate to 500 .... RH_ASK driver(500, 4, 2, 5); for both transmit and receive and set input to DC motor at 12v and 650mA.
Servo as well as the receiver module, runs off 5v input from Arduino.
Arduino runs off 12v in the Vin.
steering servo works great. No probs at all. but then when the DC motor gets some numbers that make it run, it starts up and then everything dies. The Arduino stops printing the received values. Which i guess means that the package of the correct size is not received.
Still a problem with receiver when it receives 3-4 packages for the DC motor and seems to crash and stop serial printing completely.
I am using a nano for the transmitter and a uno for the receiver. genuino!
Thanks to all for your assist.
I don’t see that anyone has suggested temporarily removing the motor driver(s) and the servo(s) and arranging LEDs in their stead merely to prove that the messages are fine, they are arriving well and being acted upon properly from a program logic point of view.
This may show that the problems occur when your power supplies are inadequate to the tasks you are asking of them. Or it will motivate you and others to find a software issue.
Please try to understand the baud rate and the frequency of sending messages are NOT the same thing! Your problem is the frequency of sending the messages!
Those cheap radios can work well. I assume you bought pairs of RX and TX modules.
I have taken a fast flight about your sketches, and an even simpler experiment is to get any example you can find for sending data from one Arduino to the other working.
I won’t assume you did that; if you did, post exactly the RX and TX code you used.
Worrying about steering and throttle if the basic comms is not solid frutile.
This arrangement can also be done without the radios at all, which would let you in another way see where your issue may be:
Provide a common ground and wire the TX output on one part to the RX input on the other, that is to say where the 433 modules were hooked up, using a 2K2 or similar (1K to 4K7 should be OK).
This lets the RF data stream reach the destination. See if the same behaviour turns up.
There are three issues. Power, radio operation and software. Perform or design your own experiments which will allow you to focus on one aspect of this at a time.