DC Motor

Overview

This tutorial will teach you how to implement a DC Motor with a Satellite Board of your choice.

Components

Arduino + power and usb connectors
Museduino Shield
1 Museduino Satellite board
CAT5/RJ45 cables
DC Motor
1N4001 diode
1k resistor

Setup

Attach your Museduino Shield to your Arduino and connect a Satellite board on Port A. For this tutorial we are going to use Satellite I/O 3. Before we get started, take a look at the Pin Configuration Chart.

pinconfig

Both the Smorgasboard and External Power boards have a built-in Mosfet which is ideal for I/O that require more power than an Arduino digital output can handle directly.

When working with DC motors, it is also important to use a flyback Diode, which is a diode used to eliminate negative voltage spikes when power is suddenly reduced or removed. To prevent damage to the Mosfets on your Satellite boards, place the diode in parallel with the motor. Use pin 1 for power and pin 2 for Signal with an Open drain to Ground. Then place a resistor between pin 3 and 4.

Next, upload our example DC Motor sketch.

Code


/*
  Museduino | DC Motor Tutorial
  Set the speed of a DC motor.
*/

//satellite Pin 1 on Port A
int s2A = A1;

//satellite Pin 3 on Port A 
int s3A = 9; //default arduino pin is D8, use PWM Select to swap with D9

//variables
int InputValue = 0; //potentiometer value
int motorValue = 0; //motor speed value

// the setup routine runs once when you press reset:
void setup() { 
  
  Serial.begin(9600);
  
  // initialize potoentiometer as input and the motor pin as an output.
  pinMode(s2A, INPUT);
  pinMode(s3A, OUTPUT); 

}

// the loop routine runs over and over again forever:
void loop() {
  
  //read value from potentiometer
  inputValue = analogRead(s2A);
  
  //map value from 0 (off) to 255 (on)
  motorValue = map(inputValue, 1023, 0, 0, 255);
  
  Serial.println(motorValue);
  
  //if motorvalue > 0, set the speed
  if(motorValue > 0) {
    analogWrite(s3A, motorValue);
  } else {
    //stop the motor
    digitalWrite(s3A, LOW);
  }
  
  
}

Github

Advertisements