R/C controller with arduino

Ok, I have an R/C controller which I am trying to get to control 4 motors connected to an Adafruit motorshield. In an earlier sketch I used serial print and found that all four channels have a neutral number of about 1000 to 1500. Now on to my new sketch which is supposed to do the actual controlling. It currently just turns on two motors and the remote control has no effect on the motors. Anyone have any idea why that would be?

#include <Wire.h>
#include <Adafruit_MotorShield.h>
#include "utility/Adafruit_MS_PWMServoDriver.h"

Adafruit_MotorShield AFMS = Adafruit_MotorShield();
Adafruit_DCMotor *driveWheel1 = AFMS.getMotor(1);
Adafruit_DCMotor *driveWheel2 = AFMS.getMotor(2);
Adafruit_DCMotor *armMotor1 = AFMS.getMotor(3);
Adafruit_DCMotor *armMotor2 = AFMS.getMotor(4);
int ch1;
int ch3;
int ch4;


void setup()
{
  AFMS.begin();
  driveWheel1->setSpeed(255);
  driveWheel1->run(FORWARD);
  driveWheel1->run(RELEASE);
  driveWheel2->setSpeed(255);
  driveWheel2->run(FORWARD);
  driveWheel2->run(RELEASE);
  armMotor1->setSpeed(255);
  armMotor1->run(FORWARD);
  armMotor1->run(RELEASE);
  armMotor2->setSpeed(255);
  armMotor2->run(FORWARD);
  armMotor2->run(RELEASE);
  pinMode(A0, INPUT);
  pinMode(A1, INPUT);
  pinMode(A3, INPUT);


}

void loop() 
{
  ch1 = pulseIn(A3, HIGH, 25000);
  ch3 = pulseIn(A1, HIGH, 25000);
  ch4 = pulseIn(A0, HIGH, 25000);
 if (ch3 > 1500)
 {
  armMotor1->run(FORWARD);
  armMotor2->run(FORWARD);
 }
 else if (ch3 < 1000)
 {
  armMotor1->run(BACKWARD);
  armMotor2->run(BACKWARD);
 }
 else if ((ch3 > 1000) && (ch3 < 1500))
 {
 armMotor1->run(RELEASE);
 armMotor2->run(RELEASE);
 }
 if (ch4 > 1500)
 {
  driveWheel1->run(FORWARD);
  driveWheel2->run(BACKWARD);
 }
 else if (ch4 < 1000)
 {
  armMotor1->run(BACKWARD);
  armMotor2->run(FORWARD);
 }
 else if ((ch4 > 1000) && (ch4 < 1500))
 {
  armMotor1->run(RELEASE);
  armMotor2->run(RELEASE);
 }
}

I am confused.

  • ch1 is set but never used.
  • If ch3 is exactly 1000 then nothing happens with it.
  • If ch4 is exactly 1000 then nothing happens with it.
  • If ch3 is greater than 1500 then nothing happens with it.
  • If ch4 is greater than 1500 then nothing happens with it.
  • You have no way of knowing what value ch1 is.
  • You have no way of knowing what value ch3 is.
  • You have no way of knowing what value ch4 is.
  • A neutral number of 1000 to 1500 is a wide range.

...AND MOST OF ALL...

  1. What remote control?
  2. Which two motors are turned on and in which direction?

I think that a much more complete explanation is needed. A wiring diagram may help too.

The remote which I am using is from tetrix, here is a link http://www.tetrixrobotics.com/RC_Controllers/Wireless_Joystick_Gamepad_System
And actually now that I redid the neutral number I must not have been paying much attention because it is more like 1450-1500. The program currently turns on motors 3 and 4. I thought that the value for the channels was found using the pulsein function and channel 1 isn't being used because it was going to be a servo but I decided to wait and try to figure out the other motors first.

Ok, I changed some things on the code and am printing it to the serial monitor and it appears as though the reciever is getting a really varied signal because when I look at the serial monitor it rapidly switches between left and down. Anyone have any idea how to fix this?

#include <Wire.h>
#include <Adafruit_MotorShield.h>
#include "utility/Adafruit_MS_PWMServoDriver.h"

Adafruit_MotorShield AFMS = Adafruit_MotorShield();
Adafruit_DCMotor *driveWheel1 = AFMS.getMotor(1);
Adafruit_DCMotor *driveWheel2 = AFMS.getMotor(2);
Adafruit_DCMotor *armMotor1 = AFMS.getMotor(3);
Adafruit_DCMotor *armMotor2 = AFMS.getMotor(4);

int ch3;
int ch4;
int moveArmMotor;
int turn;


void setup()
{
  AFMS.begin();
  driveWheel1->setSpeed(255);
  driveWheel1->run(FORWARD);
  driveWheel1->run(RELEASE);
  driveWheel2->setSpeed(255);
  driveWheel2->run(FORWARD);
  driveWheel2->run(RELEASE);
  armMotor1->setSpeed(255);
  armMotor1->run(FORWARD);
  armMotor1->run(RELEASE);
  armMotor2->setSpeed(255);
  armMotor2->run(FORWARD);
  armMotor2->run(RELEASE);
  pinMode(A0, INPUT);
  pinMode(A1, INPUT);
  pinMode(A3, INPUT);
  Serial.begin(9600);


}

void loop() 
{
  
  ch3 = pulseIn(A1, HIGH, 25000);
  ch4 = pulseIn(A0, HIGH, 25000);
  moveArmMotor = map(ch3, 1000,2000, -500,500);
  moveArmMotor = constrain(moveArmMotor, -255,255);
 if (moveArmMotor > 0)
 {
  Serial.println("up");
  armMotor1->run(FORWARD);
  armMotor2->run(FORWARD);
 }
 
 else if (moveArmMotor < 0)
 {
  Serial.println("down");
  armMotor1->run(BACKWARD);
  armMotor2->run(BACKWARD);
 }
 else if (moveArmMotor == 0)
 {
 Serial.println("nothing");
 armMotor1->run(RELEASE);
 armMotor2->run(RELEASE);
 }
 turn = map(ch4, 1000,2000, -500,500);
 turn = constrain(turn, -255,255);
 if (turn > 0)
 {
  Serial.println("right");
  driveWheel1->run(FORWARD);
  driveWheel2->run(BACKWARD);
 }
 else if (turn < 0)
 {
  Serial.println("left");
  armMotor1->run(BACKWARD);
  armMotor2->run(FORWARD);
 }
 else if (turn = 0)
 {
  Serial.println("straight");
  armMotor1->run(RELEASE);
  armMotor2->run(RELEASE);
 }
}

straight will never be printed.

turn = 0

sets turn to zero and causes the if statement to fail. Perhaps you intended

turn == 0

It's definitely true that turn was supposed to be turn == 0, sadly that isn't the only problem apparently

I agree that something else is wrong. I still do not see a way to view ch3 or ch4. I still do not see a schematic. Powering motors from an Arduino can be a very bad thing to do. Missing grounds can be bad too.