Servo Motors (PWM Select)

Overview

This tutorial will teach you how to implement a servo motor and use PWM Select.

Components

Arduino + power and usb connectors
Museduino Shield
Museduino Smorgasboard
CAT5/RJ45 cable
Servo Motor
Male to Female Jumper wires

pwm tutorial parts

Setup

Before we get started, let’s learn about the PWM Select feature. In our Satellite I/O chart, there are 4 pins that denote PWM Select. Each pin is designated to a port.

2.0_pinchart

Next, look at your Museduino Shield and locate the two red dip switches. Each switch is placed between two ports. The dip switch to the left is between port A and B. The other is placed between port C and D.

20150604_121023

These switches are designed to swap a PWM pin between two ports. By default digital pin 8 is on port A. However, in the instance that an extra PWM pin is needed on port A, the switch allows you to swap digital pin 8 with digital pin 9 on port B.

pwmselect

When both switches are pushed up towards A or D, you can follow the Satellite I/O chart for default PWM Select pins. If either switch is pushed down towards B or C, satellite pins 3 and 5 are swapped. If the right switch pushed up towards D, satellite pins 3 and 5 are swapped.

Now that you have learned about the PWM Select feature, let’s implement a servo motor on port D. First, connect the Museduino and Smorgasboard satellite via Cat5 on port D.

servo tutorial

Then, connect your jumper wires to the Servo Motor.

unnamed-6

Next, connect the opposite ends of the jumper wires to the PWM select arduino pin on your Smorgasboard Satellite. In this instance, satellite i/o 3 on port D is denoted as PWM Select.

pinconfig

Use pins 1 (power), 3 (signal), and 4 (ground).

20150701_161600

Code

/*
  Museduino | Servo Motors (PWM Select) Tutorial
  Servo Motor repeatedly turns from 0 to 180 degrees, then 180 to 0 degrees.
*/

#include  
 
Servo servo;  // create servo object to control a servo 
              // a maximum of eight servo objects can be created 
 
int pos = 0;    // variable to store the servo position 

//Use PWM Select switch to swap default pin D2 with D3~
int s3D = 3; // Digital Pin 3 on Satellite Pin 3 via Port D
 
void setup() 
{ 
  servo.attach(s3D);  // attaches the servo on pin 3 to the servo object 
} 
 
 
void loop() 
{ 
  for(pos = 0; pos =1; pos-=1)     // 180 degrees to 0 degrees 
  {                                
    servo.write(pos);                // tell servo to go to position
    delay(15);                       // waits 15ms for the servo to reach the position 
  } 
} 

Github

Once your code is uploaded, make sure your switch is in the correct position.

unnamed-1

ezgif.com-crop

Advertisements