Lego have produced many styles of motors over the years (including clockwork ones!) but one of the most popular old style motors was the 9V Technic one, used in many builds. Many of you may still have these motors hanging about. In the video below we look at how to connect these up to an Arduino so that you can breath new life into these old motors by giving them the control of a “Brain” (our Arduino). This makes them almost like the “Power Functions” motors (without the remote control aspect). Below the video you will find the simple test code used in the video.
The Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
#define MOTOR_A_DIR 10 // Motor A connection 1 #define MOTOR_A_SPEED 11 // Motor A connection 2 void setup() { pinMode( MOTOR_A_DIR, OUTPUT ); // Set to outputs pinMode( MOTOR_A_SPEED, OUTPUT ); digitalWrite( MOTOR_A_DIR, LOW ); // Ensure motor starts digitalWrite( MOTOR_A_SPEED, LOW ); // in off position } void loop() { // the delay of 4000 is 4 seconds digitalWrite( MOTOR_A_DIR, LOW ); // direction 1 (whichever that might be, depends on your wiring etc.) analogWrite( MOTOR_A_SPEED, 128 ); // approx half speed of whatever top speed your motor has delay(4000); digitalWrite( MOTOR_A_DIR, LOW ); // Turn off power digitalWrite( MOTOR_A_SPEED, LOW ); // to motor delay(4000); digitalWrite( MOTOR_A_DIR, HIGH ); // reverse direction analogWrite( MOTOR_A_SPEED, 128 ); // approx half speed delay(4000); digitalWrite( MOTOR_A_DIR, LOW ); // Turn off power digitalWrite( MOTOR_A_SPEED, LOW ); // to motor delay(4000); } |
In the next article I’ll present a full fairground ride with opening gates and smooth start up and slow down of the ride.