Hi guys!
I am using Arduino Motor Shield. No energy flows to 2 of the DC motors pins. If I make only those pins to work, no voltage gets there. Tested with a multimeter. But when making the other 2 pins to work, both pins are getting enough voltage. Need help...
show schematic and sketch
Should i send you the pic of the circuit?
#include <AFMotor.h>
#include <Servo.h>
#include <RH_ASK.h>
#ifdef RH_HAVE_HARDWARE_SPI
#include <SPI.h>
#endif
// Motor definitions
AF_DCMotor motor1(1);
AF_DCMotor motor2(2);
AF_DCMotor motor3(3);
AF_DCMotor motor4(4);
// Servo definitions
Servo leftservo;
Servo rightservo;
// Radio driver
RH_ASK driver(2000, 2);
// Analog pin for shooter is A0
void setup() {
pinMode(A0, OUTPUT);
// Attach servos to pins
leftservo.attach(10);
rightservo.attach(9);
// Set initial servo position
leftservo.write(90);
rightservo.write(90);
// Initialize serial communication for debugging
Serial.begin(9600);
Serial.println("Start!");
// Initialize radio communication
if (driver.init()) {
Serial.println("Radio initialized");
}
}
void forward() {
// Set motor speeds for forward movement
motor1.setSpeed(255);
motor1.run(FORWARD);
motor2.setSpeed(255);
motor2.run(FORWARD);
motor3.setSpeed(255);
motor3.run(FORWARD);
motor4.setSpeed(255);
motor4.run(FORWARD);
}
void back() {
// Set motor speeds for backward movement
motor1.setSpeed(255);
motor1.run(BACKWARD);
motor2.setSpeed(255);
motor2.run(BACKWARD);
motor3.setSpeed(255);
motor3.run(BACKWARD);
motor4.setSpeed(255);
motor4.run(BACKWARD);
}
void left() {
// Set motor speeds for left turn
motor1.setSpeed(255);
motor1.run(BACKWARD);
motor2.setSpeed(255);
motor2.run(BACKWARD);
motor3.setSpeed(255);
motor3.run(FORWARD);
motor4.setSpeed(255);
motor4.run(FORWARD);
}
void right() {
// Set motor speeds for right turn
motor1.setSpeed(255);
motor1.run(FORWARD);
motor2.setSpeed(255);
motor2.run(FORWARD);
motor3.setSpeed(255);
motor3.run(BACKWARD);
motor4.setSpeed(255);
motor4.run(BACKWARD);
}
void stop() {
// Stop all motors
motor1.setSpeed(0);
motor1.run(RELEASE);
motor2.setSpeed(0);
motor2.run(RELEASE);
motor3.setSpeed(0);
motor3.run(RELEASE);
motor4.setSpeed(0);
motor4.run(RELEASE);
}
void loop(){
if (driver.available()) {
// Read the incoming message
Serial.println("Available");
char incomingMessage[32];
uint8_t len = driver.recv(incomingMessage, sizeof(incomingMessage));
if (len > 0) {
Serial.println(incomingMessage);
// Check the message content
if (strcmp(incomingMessage, "forwardzzzzz") == 0) {
forward();
} else if (strcmp(incomingMessage, "backwardzzzz") == 0) {
back();
} else if (strcmp(incomingMessage, "leftzzzzzzzz") == 0) {
left();
} else if (strcmp(incomingMessage, "rightzzzzzzz") == 0) {
right();
} else if (strcmp(incomingMessage, "shootzzzzzzz") == 0) {
digitalWrite(A0, HIGH);
delay(15000);
digitalWrite(A0, LOW);
} else if (strcmp(incomingMessage, "gripzzzzzzzz") == 0) {
leftservo.write(0);
rightservo.write(180);
delay(50);
leftservo.write(90);
rightservo.write(90);
} else if (strcmp(incomingMessage, "releasezzzzz") == 0) {
leftservo.write(180);
rightservo.write(0);
delay(50);
leftservo.write(90);
rightservo.write(90);
}
}
}
}
Above are the pic and the code
Motor 1 and motor 4 are working, but motor 2 and motor 3 ain't even getting any voltage (checked by a multimeter), even when uploaded code in the arduino for only those pins to work
what board are you using?
I'm using Arduino uno
You are using 4 motors. Take a look at page 8 here. It shows how many pins the shield uses with all the motors active. Doesn't leave much, not even SPI.
I have read it. I am using no such pins that are being used by the shield
do you have another/second board to test?
Digital pin 11 and 12 are the Uno SPI. Can't use #include <SPI.h>
Digital pin 11: DC Motor #1 / Stepper #1 (activation/speed control)
Digital pin 4, 7, 8 and 12 are used to drive the DC/Stepper motors via the 74HC595
serial-to-parallel latch
that's a lot of motors!
are you using a 4A power supply?
Sorry, I don't
I used d2 instead of d11 for rf modules, using this code:
RH_ASK driver(2000, 2);
I increased the power supply to the shield and the problem solved. Sorry for doing such a silly mistake.
Thank you all for helping...
But now I have one more problem, please help if you can. Here is the post: