How to Program DC Motors with the Inventor Board

This lesson will go over the Motor Pins found on PINS(2~5)

First, begin the code by including the smart inventor library. Enter the following before the void setup(); method.

Learn More: What’s a library?

A library is a saved set of functions()  and variables that provide users with improved functionality when coding.

Any code that starts with SmartInventor._____  is a function in the SmartInventor library.  Any variable that highlights ORANGE, is an initialized variable from an included library.

Learn More

Next, inside   void setup(); ,enter the following to initialize the use of the DC motor within the sketch.

Next, inside   void loop(); enter the following to move the DC motor within the sketch.
SmartInventor.DCMotorUse( )

SmartInventor.DCMotor( Name of the motor, Direction, Power);

  • Entries for the name of the motor are either  M1, M2, M3 or M4 This refers to which motors you will be controlling. The pins on the smart Inventor board are paired, meaning that when M1 is called on M3 will also operate, same with M2 and M4.
  • Entries for the direction, refer to CW, CCW, STOP or LOOSE . CW stands for Clockwise, CCW stands for Counter Clockwise, STOP will make the motor not move, and LOOSE will make the motor stall to a stop
  • Entries for power are positive numbers ranging from 1 through 100.

Lastly, input a  delay() to assign a time step for when the motor should change.

delay( )

delay( time in milliseconds );

delay()is a function that will define how long an action should be performed. There are 1000 milliseconds in 1 second. This means that if the action should run for 3 seconds, the time entered in the delay() should be 3000.

Note: this code will only allow you to control one motor. As an activity try controlling two motors at the same time, and by inputting the CW, CCW, STOP, and LOOSE commands in the direction entry.

Final Code