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.

#include <SmartInventor.h>
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 toCW, 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

#include <SmartInventor.h> //Include the library to improve functionality of codes

void setup() {
SmartInventor.DCMotorUse(); //Initializes the use of DC Motors

void loop() {
SmartInventor.DCMotor(M1,CCW,10); //Sets the DC Motor on pin M1 to move in a counter clockwise direction at 10%
delay(1000); //time step for previous command