so i am getting issues to control spped of my motor ..
i am using cytron md 10 A motor driver to drive a single motor..
and using a radio transmiter and reciever to get the signals.. all works fine .. but if i use stearing logic or use servo motor i am not able to control spped of my main motor it directly run at full spped when throtle value reach 255..
but if i remove the stearing logic or servo motor library it works fine and speed increase and decrease as i move the throtle...so any one can sugges whats the issue
#include <Servo.h>
// Initialize a PPMReader on digital pin 3 with 10 expected channels.
byte interruptPin = 3;
byte channelAmount = 10;
PPMReader ppm(interruptPin, channelAmount);
// Create servo objects to control a servo motor
Servo steeringServo;
// Define pins for the servo and simple motor
byte steeringPin = 9;
byte MotorDirection = 8; // Motor direction pin
byte MotorSpeed = 10; // Motor speed pin (PWM pin)
void setup() {
Serial.begin(115200);
// Attach the servo on pin 9
steeringServo.attach(steeringPin);
// Declaration for the pins used by the motor driver
pinMode(MotorDirection, OUTPUT);
pinMode(MotorSpeed, OUTPUT);
// Debugging
Serial.println("Setup complete, waiting for PPM signals...");
}
void loop() {
// Read and print the latest valid values from all channels
for (byte channel = 1; channel <= channelAmount; ++channel) {
unsigned value = ppm.latestValidChannelValue(channel, 0);
if (channel < channelAmount) Serial.print('\t');
}
Serial.println();
// Control logic for the servo motor (steering) and simple motor (throttle)
unsigned steeringValue = ppm.latestValidChannelValue(1, 1500); // Channel 1 for steering
unsigned throttleValue = ppm.latestValidChannelValue(3, 1000); // Channel 2 for throttle
// Map the PPM values to servo angles (assuming 1000-2000us PPM range and 0-180 degree servo range)
int steeringAngle = map(steeringValue, 1000, 2000, 0, 180);
steeringServo.write(steeringAngle);
// Control the motor based on the throttle value
if (throttleValue > 1550) {
digitalWrite(MotorDirection, HIGH); // Forward direction
int motorSpeed = map(throttleValue, 1551, 2000, 0, 255); // Map throttle value to motor speed
Serial.println("Motor running forward with speed: " + String(motorSpeed));
analogWrite(MotorSpeed, motorSpeed);
} else if (throttleValue < 1450) {
digitalWrite(MotorDirection, LOW); // Reverse direction
int motorSpeed = map(throttleValue, 1449, 1000, 0, 255); // Map throttle value to motor speed
Serial.println("Motor running in reverse with speed: " + String(motorSpeed));
analogWrite(MotorSpeed, motorSpeed);
} else {
analogWrite(MotorSpeed, 0); // Stop the motor
Serial.println("Motor stopped");
}
delay(20);
}
above code is causing issue
#include <PPMReader.h>
#include "CytronMotorDriver.h"
// Initialize PPMReader on digital pin 3 with 10 expected channels
byte interruptPin = 3;
byte channelAmount = 10;
PPMReader ppm(interruptPin, channelAmount);
// Configure the motor driver
CytronMD motor2(PWM_DIR, 10, 8); // PWM = Pin 10, DIR = Pin 8
void setup() {
Serial.begin(115200);
Serial.println("Setup complete. Waiting for PPM signals...");
}
void loop() {
// Read the throttle value from PPM channel 3
unsigned throttleValue = ppm.latestValidChannelValue(3, 1000); // Default to 1000 if invalid
unsigned steeringValue = ppm.latestValidChannelValue(1, 1500); // Channel 1 for steering
// Debugging: Print the throttle value
Serial.print("Throttle Value: ");
Serial.println(throttleValue);
// Calculate motor speed based on throttle value
int motorSpeed = 0;
if (throttleValue > 1550) {
motorSpeed = map(throttleValue, 1551, 2000, 0, 255); // Forward
} else if (throttleValue < 1450) {
motorSpeed = map(throttleValue, 1450, 1000, 0, -255); // Reverse
} else {
motorSpeed = 0; // Neutral/Stop
}
// Debugging: Print the calculated motor speed
Serial.print("Mapped Motor Speed: ");
Serial.println(motorSpeed);
// Set motor speed
motor2.setSpeed(motorSpeed);
delay(20);
}
this works fine