[Solved] Lego NXT motor not turning

Hello together,

I have a problem controlling my Lego-NXT-motors with the arduino leonardo.

I bought two NXT Servo motors and now I’ve received all parts to control them.
What I did do:

  1. Use a power supply with ajustable voltage which can do 0-30V and 0-3A.
  2. Use a 7809CV to regulate the voltage.
  3. Power the arduino from USB (just for now)
  4. Use a L293D to control the motors

Enable Pins to A5 and A4 → programmed the Leonardo to give +5V on them
Vss-> regulated Voltage from 7809CD (I measure about 8-8.5V)
VS → Logic-voltage: +5V
GND-Pins to GND

I looked into the NXT cables and saw that the blue, yellow and green wires are responsible for driving the motor.
Black, white and red are the rotary encoder, which I do not need.
So I connected the blue and yellow ones with the outputs from L293D and the green one with the GND pin from L293D.
Same on the other side with the other NXT motor.

Now wrote a small program to drive the motors:

#include "NXT_Motors.h"
#include <LegoMotors.h>


NXTMotor li(4, 5);
NXTMotor re(6, 7);

void setup()
	digitalWrite(ENABLELIPIN, 1);
	digitalWrite(ENABLEREPIN, 1);

void loop()


#include "avr/interrupt.h"
#include "LegoMotors.h"
#include "arduino.h"

NXTMotor::NXTMotor(short pinP, short pinM) {
  _pinP = pinP;
  _pinM = pinM;
  pinMode(_pinP, OUTPUT);
  pinMode(_pinM, OUTPUT);
  digitalWrite(_pinP, 0);
  digitalWrite(_pinM, 0);

void NXTMotor::setSpeed(short speed) {
	if(speed > 255) speed = 255;
	else if(speed < -255) speed = -255;

	if(speed > 0) {
	  	analogWrite(_pinM, 0);
  		analogWrite(_pinP, speed);
  	else if(speed < 0) {
  		speed = -speed;
	  	analogWrite(_pinM, speed);
	  	analogWrite(_pinP, 0);
    } else if(speed == 0) {
    	digitalWrite(_pinM, 0);
    	digitalWrite(_pinP, 0);


(I’m using Eclipse to program the Leonardo).

Now, when I upload the program, nothing happens :frowning:
I measure ~8V on one of the output-cables to the motors and -0.4V on the other.
Since 8V >> -0.4V, the motor should turn… at least that is what I’ve read…
Also when I put 9V directly on the blue wire and 0V on yellow and green (directly from the power supply to the motors) nothing happens.
Also my power supply is just showing a current flow of 0.07A, which is far too low. I assume about 0.5A per motor…

What is wrong? Should’nt the motors turn when I power them directly?

The motors are new (I’ve never used them before and bought them over ebay) and I do not know what could be the problem.
I get the same behaviour when I use a 9.6V, 1500mAh 8x Nimh accu pack…

Thanks for reading :slight_smile:

OMG, my fault… I misinterpreted this guide: http://de.scribd.com/doc/24698262/Rj12-and-Lego-Nxt
It says the first one is motor and from the pictures a guessed that by first the blue one is meant…
Here however it sais the contrary: LEGO NXT Motor Wiring | BrickEngineer: LEGO Design

Now I’ve already soldered everything… I will try to change it and report back later… Sorry…

Okay, it’s working now… the second link is correct and detailed :wink: