Read PWM value of a RC rx with an arduino

Hi everyone,

Having recently  found a chassis that is not motorized ( snow service toy ).
I would like to remote control ( 2.4 ghz transmitter )  but I do not have a DC motor controllers to control the motors of the robot and I did not really want to 'purchase.

So i think I could go through a arduino and a L298N to control the motors ( I think 12V engines)


So the probleme is: How to communicate with a remote to a arduino?
So i told that i can connect the signal pin of the receiver to a digital pin of the arduino to read PWM value to control the motor.

I could read these values ​​(0 to 1023?) That I "map" between 0 and 255 and then to vary "enable Pin" on my L298N and thus the speed of my engines.

This solution you seem possible? and if so I'm going to need a boost for the code because I'm still struggling ^ ^

 

Sorry for spelling :/

pulseIn

pulseIn is what you are looking for, sir.

http://arduino.cc/en/Reference/PulseIn

Thank evrebody :slight_smile:

I just found a tutorial of a guy who explain how to do that https://www.sparkfun.com/tutorials/348 but in the tutorial the final code seems to be to easy and i wonder if it include the communication with the L298N and if the speed of the motor can vary.

 

"The Arduino would be more or less extraneous in this setup and in a sense be going to waste."

I wanna use an arduino for this project for three reason :

- Because i want to learn more aboute arduino

- Because i don’t wan’t to buy RC cc controller ( I’m 15 so ive only some pocket money ^^ )

- Because i would put a anti shock sensor or some another cool stuff who need arduino

 

Here is the final code of the tutorial :

 

/
 RC PulseIn Joystick Servo Control
 By: Nick Poole
 SparkFun Electronics
 Date: 5
 License: CC-BY SA 3.0 - Creative commons share-alike 3.0
 use this code however you’d like, just keep this license and
 attribute. Let me know if you make hugely, awesome, great changes.
 /

int ch1; // Here’s where we’ll keep our channel values
int ch2;
int ch3;

int move; // Forward/Back speed
int turn; // Turning Factor

int pwm_a = 3; //PWM control for motor outputs
int pwm_b = 11; //PWM control for motor outputs
int dir_a = 12; //direction control for motor outputs
int dir_b = 13; //direction control for motor outputs

void setup() {

pinMode(5, INPUT); // Set our input pins as such
pinMode(6, INPUT);
pinMode(7, INPUT);

Serial.begin(9600); // Pour a bowl of Serial (for debugging)

  pinMode(pwm_a, OUTPUT); //Set control pins to be outputs
  pinMode(pwm_b, OUTPUT);
  pinMode(dir_a, OUTPUT);
  pinMode(dir_b, OUTPUT);

  analogWrite(pwm_a, 0);
  analogWrite(pwm_b, 0);
}

void loop() {
  
  ch1 = pulseIn(4, HIGH, 25000); // Read the pulse width of
  ch2 = pulseIn(5, HIGH, 25000); // each channel
  ch3 = pulseIn(6, HIGH, 25000);
  /*
  if(ch1>1000){Serial.println(“Left Switch: Engaged”);}
  if(ch1<1000){Serial.println(“Left Switch: Disengaged”);}

Serial.print(“Right Stick X:”);
Serial.println(map(ch3, 1000,2000,-500,500));

Serial.print(“Right Stick Y:”);
Serial.println(map(ch2, 1000,2000,-500,500));

Serial.println();

delay(100);

clearAndHome();
*/

move = map(ch2, 1000,2000, -500, 500); //center over zero
move = constrain(move, -255, 255); //only pass values whose absolutes are
                                   //valid pwm values

/What we’re doing here is determining whether we want to move
forward or backward/
if(move>0){digitalWrite(dir_a, 1);digitalWrite(dir_b, 1);};
if(move<0){digitalWrite(dir_a, 0);digitalWrite(dir_b, 0); move=abs(move);};

/Here we’re determining whether a left or a right turn is being 
executed/
turn = map(ch1,1000,2000,-500,500);
turn = constrain(turn, -255, 255);

/This is where we do some mixing, by subtracting our “turn” 
variable from the appropriate motor’s speed we can execute
a turn in either direction/
if(turn>0){analogWrite(pwm_b, move-turn); analogWrite(pwm_a, move);};
if(turn<0){turn=abs(turn); analogWrite(pwm_a, move-turn); analogWrite(pwm_b, move);};

Serial.print(“move:”); //Serial debugging stuff
Serial.println(move);

Serial.print(“turn:”); //Serial debugging stuff
Serial.println(turn);

Serial.print(“move-turn:”); //Serial debugging stuff
Serial.println(move-turn);

Serial.println(); //Serial debugging stuff
Serial.println();
Serial.println();

}

 

Thanks again :wink:

I’ve try to follow the

I’ve try to follow the tutorial so i start by test my PWM receive.

But, in the tutorial, he says that the values who can read on the serial monitor are range between 1000 and 2000 and they vary when you move the stick on your remote.

But, with me, the value are ranged between 0 and 10000 and don’t vary.

 

here is the code i use

/
 RC PulseIn Serial Read out
 By: Nick Poole
 SparkFun Electronics
 Date: 5
 License: CC-BY SA 3.0 - Creative commons share-alike 3.0
 use this code however you’d like, just keep this license and
 attribute. Let me know if you make hugely, awesome, great changes.
 /
 
int ch1; // Here’s where we’ll keep our channel values
int ch2;
int ch3;

void setup() {

  pinMode(5, INPUT); // Set our input pins as such
  pinMode(6, INPUT);
  pinMode(7, INPUT);

  Serial.begin(9600); // Pour a bowl of Serial

}

void loop() {

  ch1 = pulseIn(5, HIGH, 25000); // Read the pulse width of
  ch2 = pulseIn(6, HIGH, 25000); // each channel
  ch3 = pulseIn(7, HIGH, 25000);

  Serial.print(“Channel 1:”); // Print the value of
  Serial.println(ch1); // each channel

  Serial.print(“Channel 2:”);
  Serial.println(ch2);

  Serial.print(“Channel 3:”);
  Serial.println(ch3);

  delay(100); // I put this here just to make the terminal
              // window happier
}



An idea someone ?

I am feeling wiring…

I don’t know why, but I have a really strong “connected grounds” feeling on this one…

Are your ground wires connected? I would probably not use a 3-wire connector to go from your receiver to the arduino, you may not want to share the +, however you will need the receiver’s ground pin (and of them) connected to the arduino’s ground. 

How do you have this guy wired up, my friend?

I don’t really understand

I don’t really understand what you are saying but here is how i wire up my project ( like in the pics )

http://dlnmh9ip6v2uc.cloudfront.net/tutorialimages/RCReceivers/RC_Rec_bb.jpg