2

I received the sainsmart motor controller a few days ago, and am now having trouble testing it. The Arduino I am using is an Arduino Mega 2560. I thought it was an I2C communication issue but that wasn't working. So here I am now asking for help. Here is my wiring. enter image description here

Here is my code:

#include <AFMotor.h>

AF_DCMotor motor(2);

void setup() {
 Serial.begin(9600);           // set up Serial library at 9600 bps
 Serial.println("Motor test!");

 // turn on motor
 motor.setSpeed(200);

 motor.run(RELEASE);
}

void loop() {
 uint8_t i;

 Serial.print("tick");

 motor.run(FORWARD);
 for (i=0; i<255; i++) {
  motor.setSpeed(i);  
  delay(10);
 }

 for (i=255; i!=0; i--) {
  motor.setSpeed(i);  
  delay(10);
 }

Serial.print("tock");

motor.run(BACKWARD);

 for (i=0; i<255; i++) {
  motor.setSpeed(i);  
  delay(10);
 }

for (i=255; i!=0; i--) {
  motor.setSpeed(i);  
  delay(10);
 }


Serial.print("tech");
motor.run(RELEASE);
delay(1000);
 }

I also tried this one:

#include<AFMotor.h>
 AF_DCMotor motor2(2);
void setup() {
 // put your setup code here, to run once:
 motor2.setSpeed(255);
}

void loop() {
 // put your main code here, to run repeatedly:
 motor2.run(FORWARD);
  }

None of the two worked. If someone could help me that would be great. Thank You!!!

  • the picture of your board is not a very good representation of the wiring. ... please draw a schematic. ... there is a button for that when you edit your question – jsotola Dec 20 '17 at 4:33
  • How am I supposed to represent the motor shield? I'll tell you the wiring. The sainsmart board connects all the pins on the side of the standard arduino uno except for pin 7 digital. The IC2 is connected to SDA(Digital 20) and SCL (Digital 21). The motor is connected to the M2 Terminal. Thanks!!!! – Ahmed Fouad Dec 20 '17 at 23:06
1

I figured out the problem. One of the terminals was damaged during transportation. Now it's all good. Thanks for the help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.