RF control of DC motors

I have completed a small project using an existing 433mhz remote handset, UNO clone, L298N dual motor controller(ebay) to control 2 12V DC motors on a self propelled and remote controlled golf cart. Too cumbersome to connect motors at this time so I am reading voltages at the output of the L298N when running tests. Standard assembly of the hardware with serial input on pin 2. Everything works as is should. The 3 directional buttons and stop button on the remote send the signal and I get the correct readings at the output of the L298. I am hoping to use this in the real world but cannot as it currently works.
Two problems.

  1. It is not practical or safe to run the device at full speed or near full speed.
    There are conditions when it needs to run slowly, so i need to find a way to vary the speed. Searches indicate this can be done through better coding and i will address this at the last stage of the project, although any insight now would be welcome.
  2. I think this may be and issue with serial communication. 90% of the time this device runs it is moving straight forward. As DC motors have different efficiencies and the device operates on uneven surfaces it drifts in one direction or the other. On the original controller I would just push one of the directional button and jog it back on line and it would continue to move forward. With the existing hardware and code, if I push a direction button it will continue to move in that direction until I push the forward button again. This too is not practical. Preferably the unit will always move in a forward direction with only small input for the directional buttons.
    Can someone confirm if the existing components can achieve this type of control or do i need different hardware?
    My coding skills are very weak. I was able to combine codes from few similar projects to come with the attached code.
    Any help is appreciated.

trial2.ino (2.12 KB)

Unless that is a very small toy "golf cart" it is unlikely that an L298N driver will be able to drive the motors as it is an old-fashioned very low power device.

Most motor drivers have PWM inputs which allow the motor speed to be controlled fairly easily.

Details of the motors you expect to drive would be useful.

Steve

Thanks for the response.
This is a 10+ year old device, Chinese made. There is no documentation and I am leary of taking it apart as there will likely not be any information on the motors. At the point I am not concerned if the l298n burns out. I am more concerned that I can make remote control work at least similar to the original control. If so I will look at the cost of a better driver, although if you can recommend a better driver I can research it now.
Thanks

You have not given us any information about the signals that the Arduino can detect from the remote-control.

Have you got a simple program working that can detect the RF signals and show the result on the Serial Monitor?

...R

I tested the RF signals using the example sketches serial_simple and serial_advanced and used the 7 digit numbers from serial_simple that I used for

if (mySwitch.available()) {

int value = mySwitch.getReceivedValue();

possibly from the RCSwitch library

Did my compete code show up on the original post?

trial2.ino (2.12 KB)

Edremote:
I tested the RF signals using the example sketches serial_simple and serial_advanced and used the 7 digit numbers from serial_simple that I used for

So what values did you get for each of the different controls?

And, to make it easier for people to help you please include short programs in your Post using the code button </>. Look at some other Threads to see how it should be done. See How to use the Forum

...R

I gave bad information earlier
The sample sketches were ReceiveDemo_simple and RecieveDemo_advanced

I used these values that came from RecieveDemo_simple
Forward — 4044392
Stop — 4044394
Turn left — 4044388
Turn right - 4044396

The values from ReceiveDemo_advanced
Included binary, pulselength, protocol and raw data

Edremote:
The values from ReceiveDemo_advanced
Included binary, pulselength, protocol and raw data

I can understand Forward, Stop, Left and Right but I have no idea what the "advanced" items mean.

I presume there are 4 buttons to produce Forward, Stop, Left and Right. What produces each of the advanced items?

How about a photo of the control unit? See this Simple Image Guide

...R

PS ... It would be nice if you would supply all this information without having to be asked.

When i first started working to get the remote transmitter to communicate with the Uno i found the two sketches ReceiveDemo_simple and ReceiveDemo_advanced.
they appear do do the same thing but one displays much more information. The examples are below.
I was not sure which version or values i would need for the code.
In my first attempt i used the simpler version 7 digit numbers 4044***. For now it works, but i am not sure these other valves may be needed to get the control needed
i will follow with photo of remote handset.

Simple -
Received 4044392 / 24bit Protocol: 1

Advance -
Decimal: 4044392 (24Bit) Binary: 001111011011011001101000 Tri-State: not applicable PulseLength: 336 microseconds Protocol: 1
Raw data: 10420,368,1024,352,1024,1028,368,1024,360,1012,368,1008,392,320,1056,1004,392,1000,384,312,1060,996,404,988,392,308,1064,992,404,988,396,320,1068,312,1064,992,388,988,408,304,1068,992,408,144,436,60,48,124,52,

Photo of remote transmitter attached.
Actually 6 buttons. Reverse and horn buttons not use at this time.

Photo of remote transmitter attached.
Actually 6 buttons. Reverse and horn buttons not use at this time.

s-l225.jpg

Image from Reply #10 so we don't have to download it. See this Simple Image Guide

s-l225.jpg

...R

I don't see how you can control the speed reliably with a simple controller like that. You might be able to ramp up the speed through a series of button presses but as you have said "It is not practical or safe to run the device at full speed or near full speed." I suspect that sort of system would not be sufficiently reliable. There is no means for the user to know how many time s/he has pressed the button or how many of the button presses have been detected.

Also, if you are climbing a hill, for instance, you will need more power than when travelling on the flat so limiting the power going to the motors is unlikely to solve the problem either.

My suggestion (for what its worth) is to ditch that controller and make one that is more comprehensive with a proper speed control, perhaps with a joystick. You could make a very effective control system with a pair of Arduinos and a pair of nRF24L01+ transceivers - assuming the required range is not enormous.

Other people may have other suggestions.

...R
Simple nRF24L01+ Tutorial

Thanks very much for your input. I have seen the rf24l01 referenced on many projects during my searches. I disregarded them of course as I was hoping to use my relatively new transmitter. Although it is not feasible to use a joystick, as I would probably not be able to operate it with one hand, I will look further into the rf24l02. I have come to the conclusion that I may be able to make this work using a fixed speed. I can adjust the value to the enable pins on the motor controller to approximate my normal walking speed. This should cover most operating conditions.
I would still like some guidance with the second problem from my OP.
Once the forward button is pushed the device will continue to move until stop is pressed.
I will need to make small course corrections while the device is in motion by simply pressing the left or right directional button to stay on course. With current code I would have to push a directional button and then quickly push the forward button which would not be practical.
Is there some way to adjust the code or components to get the desired control?
Again thank your help and have a nice holiday.

Edremote:
I will need to make small course corrections while the device is in motion by simply pressing the left or right directional button to stay on course. With current code I would have to push a directional button and then quickly push the forward button which would not be practical.

How is the steering implemented? Are there steered wheels (like a car) or is it done by differentially varying the motor speed for the drive wheels?

...R

The steering is controlled by varying the speed of the drive motors through the H Bridge L298N.

There are many options in controlling the motors with the code.
the sample below shows a right turn. in this case the left motor is moving faster the the right steering the device to the right at probably a long arc. The code can be modified to just keep the left motor running and the right off, which would create a much sharper turn.
I have included a link to youtube showing the control of a device similar to what i have.
Maybe i should have put this on my OP.
thanks

    if (mySwitch.getReceivedValue() == 4044388) { //turn right
      digitalWrite(in1, HIGH);
      digitalWrite(in2, LOW);
      analogWrite(enA, 200);
      digitalWrite(in3, HIGH);
      digitalWrite(in4, LOW);
      analogWrite(enB, 100);

Edremote:
The steering is controlled by varying the speed of the drive motors through the H Bridge L298N.

Then you need separate variables to hold the PWM values for the two motors.

When you press the FWD button they both get incremented equally. When you press STOP they both get set to zero.

When you press a turn button a little gets added to the value for one motor and subtracted from the value for the other motor.

You haven't said if you want the motors to be able to go in reverse, but, in theory, with one motor going FWD and the other in REVerse you could turn on the spot.

...R

You are correct.
For the turn condition many options. Either a slight difference of input for the speed of each motors or turning one off completely and the option of one motor moving forward and the other in reverse.
I have seen that on many of the projects for the small RC cars. Probably not a good idea for this application.
The unit seldom goes in reverse and i was trying to keep things as simple as possible. Should not be too much trouble to add it at some point.
thanks,

I have doing more research for this project when i realized i may not have clarified the requirements for directional control. I thought this might be another hurdle but possibly it may make things less complicated.
All the buttons on the remote handset are momentary. The clumsy code i put together has all the inputs from the remote creating an on/off condition or something similar to a relay. A function is turned on an remains on until another input from the remote.
This of course is ideal for the required continuous froward motion, but not for the directional adjustments needed when steering the device. Ideally when a direction button is pushed the control function is only active as long as it is engaged and stops when the button released.
This will accommodate a short press of the button to make a small course correction or keeping the button engaged to make a full turn.
i will look for solutions.
Happy Holidays.

Edremote:
This will accommodate a short press of the button to make a small course correction or keeping the button engaged to make a full turn.

While that is true, I wonder if it will provide enough feedback for the user.

The advantage of a joystick (which is just a particular construction of potentiometers) is that the user has obvious control of "how fast" or "how far"

...R