Arduino Mega 2560 Serial Communications problem

I am doing arduino for a school project and I need to test the individual subsystems one of which is a motor. The code, provided below, requires that the amount of steps be input through the serial monitor. I know that the arduino is receiving the code because I have been able to set the on board led to blink. However the stepper motor does not react to any commands given through the serial monitor.
Any help would be appreciated. Thanks

sketch_jul03a.ino (476 Bytes)

Hi, you may want to check which version of the program you attached. This one has no serial calls in it.

sorry that was the wrong one here is the correct one

sketch_jul03b.ino (478 Bytes)

First, check out that your stepper is wired correctly by running one of the example programs. File - Examples - Stepper - stepper_oneRevolution for example.

Then, in your program, add some print statements to check what data is being received by the Arduino. For example:

void loop()
  if ( Serial.available())
    char ch =;

    Serial.print("Character received >");

      steps = steps * 10 + ch - '0';

      Serial.print("Steps = ");

    else if(ch == '+')
      Serial.println("Calling step +");
      steps = 0;
    else if (ch == '-')
      Serial.println("Calling step -");
      stepper.step(steps * -1);
      steps = 0;

I know the stepper is wired correctly as the program works on my other arduino. On the arduino mega the rx and tx leds do not light up like the other arduino.

But you don't know if it is wired correctly on this Arduino :slight_smile:

Are you saying that the program attached to reply # 2 works correctly on a different Arduino? What type of Arduino?

It works on an arduino uno and I have managed to get the code to work on the arduino mega I am currently working on but it has stopped working.

I have managed to get the code to work on the arduino mega I am currently working on but it has stopped working.

So to help diagnose the problem, add print statements as suggested to see if the Mega is receiving serial data correctly from serial monitor.

When I input the code provided to help diagnose the problem the serial monitor displays what is expected how ever the motor does not move.

OK, that's good.

You said it did work before on this Mega? Were you using the same pin numbers for the stepper?

Can you post a diagram of how the Mega and stepper motor are wired, including power supplies. A photo of a hand-drawn diagram is OK.

Yes to both questions.

Motor Wiring.jpg

Motor Wiring.jpg

Pin 8 of the h-bridge is just connected to 5V on the arduino board as the motors do not require any external power

Some things to try ...

  • Move the stepper connections to different pins on the Mega, updating the pin numbers in your program.

  • Power the stepper from a separate supply.

  • If you have a multimeter, check that supply voltage is reaching the H-bridge and the stepper.

Are you using soldered connections or a breadboard and jumpers to make the connections to the H-bridge?

After it worked the last time I got this error code the very next time I tried it avrdude: stk500_getsync(): not in sync: resp=0x00

Thanks for the help hackscribble but I think the problem was that avr was not installed properly and so the board wouldn’t receive any communications from the computer other than the code

Hello Everyone,

I am a new user of Arduino Eno R3 kit.
My intention is program SCI communication this kit with PC.
Kindly, help me in this project code and instruction.