Arduino Motor Shield's DC Motors not reading analog values less than 255

Hello, I am relatively new to Arduino and the Remote Radio (SMAKN® 315Mhz Rf Transmitter and Receiver Link Kit for Arduino/Arm/McU) so I have encountered an issue I can’t solve.

I have one Arduino board with 3 potentiometers that is supposed to remotely control 2 DC Motors hooked up to a motor shield and a servo motor on another board. 2 potentiometers are supposed to send values up to 255, which directly correspond to the speed values in analogWrite() for the motors. However, two problems occured:

  1. When the servo is referenced in the code (I control servo values in the code), the DC Motors do not respond to any values received that are in between 0 and 255. The code to control the motor is being called and everything in the code works fine according to the debugging, but the motors do not spin.

  2. Once any servo code is removed/commented from the code, the DC Motors will respond to values between 0 and 255 but then the board stops receiving messages - no new values are taken in, the code inside the vw message checker doesn’t run, and the motors continue spinning without responding to any changes in the potentiometers of the remote board; the motors essentially go rogue spinning.

Please help, I don’t understand why this is happening. I am willing to clarify or provide additional information if it helps, thanks!

P.S. how can I boost the signal and strength of my RF modules? What wire do you use for the antenna and how do you make the antenna (coils, etc.)?

Remote.ino (1.01 KB)

Pictures of my setup are posted as attachments.
Here is the code:

// TRANSMITTER CODE

#include <VirtualWire.h>

// potentiometers
int turretPotPin = A0;
int turretPotData = 0;

int motorAPotPin = A2;
int motorAPotData = 0;
int motorBPotPin = A1;
int motorBPotData = 0;

char potArray[20];

// transmitter
int txPin = 2;

void setup() {
// setup transmitter
vw_set_tx_pin(txPin);
vw_setup(1000);

Serial.begin(9600);
}

void loop() {
// read potentiometers
turretPotData = (int) ((double) analogRead(turretPotPin) * (1000.0/1023.0)) + 1000;
motorAPotData = mapMotorPotData(analogRead(motorAPotPin));
motorBPotData = mapMotorPotData(analogRead(motorBPotPin));

sprintf(potArray, “%d, %d, %d.”, turretPotData, motorAPotData, motorBPotData);
Serial.println(motorAPotData);

// send data
vw_send((uint8_t *) potArray, sizeof(potArray));
vw_wait_tx();
}

int mapMotorPotData(int potData) {
// shifts potentiometer values to values motor shield can use -255 to 255
if (potData <= 400) {
return ((int) ((double) potData * (255.0/400.0))) - 255;
} else if (potData > 624) {
return (int) ((double) (potData - 623) * (255.0/400.0));
} else {
return 0;
}
}

// RECEIVER CODE

#include <VirtualWire.h>
#include <ServoTimer2.h>

// servo
ServoTimer2 servo;

// motors
int aDirectPin = 12;
int aSpeedPin = 3;
int aBrakePin = 9;

int bDirectPin = 13;
int bSpeedPin = 11;
int bBrakePin = 8;

double fullSpeed = 255.0;

// leds
int ledPin = 4;

// receiver
int rxPin = 5;
int rxTurretPotData = 0;
double rxMotorAPotData = 0;
double rxMotorBPotData = 0;

void setup() {
// setup port A
pinMode(aDirectPin, OUTPUT);
pinMode(aBrakePin, OUTPUT);
aBrake();

// setup port B
pinMode(bDirectPin, OUTPUT);
pinMode(bBrakePin, OUTPUT);
bBrake();

// setup servo
servo.attach(2);
servo.write(1500);

// setup leds
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, HIGH);

// setup receiver
vw_set_rx_pin(rxPin);
vw_setup(1000);
vw_rx_start();

Serial.begin(9600);
}

void loop() {
// receiver
uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;

// use data
if (vw_have_message()) {
vw_get_message(buf, &buflen);
rxTurretPotData = atoi(strtok((char *) buf, ", "));
rxMotorAPotData = atoi(strtok(NULL, ", "));
rxMotorBPotData = atoi(strtok(NULL, ", "));

servo.write(rxTurretPotData);
aRun(rxMotorAPotData);
bRun(rxMotorBPotData);
} else {
//servo.write(1500);
//aBrake();
//bBrake();
}
}

// motor functions
void aRun(double data) {
Serial.println(“aRun Called”);
if (data == 0) {
aBrake();
} else {
Serial.print(“A Run”);
if (data < 0) {
digitalWrite(aDirectPin, LOW);
Serial.print(" Backwards “);
} else {
digitalWrite(aDirectPin, HIGH);
Serial.print(” Forwards ");
}
digitalWrite(aBrakePin, LOW);
int motorSpeed = abs((int) data);
analogWrite(aSpeedPin, motorSpeed);
Serial.println(motorSpeed);
}
}

void bRun(int data) {
Serial.println(“bRun Called”);
if (data == 0) {
bBrake();
} else {
Serial.print(“B Run”);
if (data < 0) {
digitalWrite(bDirectPin, LOW);
Serial.print(" Backwards “);
} else {
digitalWrite(bDirectPin, HIGH);
Serial.print(” Forwards ");
}
digitalWrite(bBrakePin, LOW);
int motorSpeed = abs((int) data);
analogWrite(bSpeedPin, motorSpeed);
Serial.println(motorSpeed);
}
}

void aBrake() {
Serial.println(“Brake”);
digitalWrite(aBrakePin, HIGH);
}

void bBrake() {
Serial.println(“Brake”);
digitalWrite(bBrakePin, HIGH);
}

The very first thing you need to do is to learn how to post code.

Enclose it using the ( </> ) code tags.

sounds like a power supply issue