IV. System Controls

Mechatronics

We used an Aruduino Uno microcontroller along with a Ardumoto motor control board, with a 12V supply powering the system.  For our user input, the bread was placed on the platform and when the user was ready, a button on the front of the device was depressed.  This prompted our motor to complete 4 revolutions at a speed of 12 rpm.  The Aruduino code for this control system can be seen below:

 

Wiring Diagram

Attached is a pdf of the wiring diagram. This shows how we connected the motor, power supply, and button to the ardumoto. Note: The ardumoto plugged in directly on top of the Arduino Uno Microcontroller. The ardumoto acted as the motor shield for the arduino. 

Wiring_Diagram.pdf


Arduino Code

basic_ardumoto_control.ino

/* Ardumoto Example Sketch

  by: Jim Lindblom; edited by Riley Noble

  date: November 8, 2013

  license: Public domain. Please use, reuse, and modify this

  sketch!

  Three useful functions are defined:

    setupArdumoto() -- Setup the Ardumoto Shield pins

    driveArdumoto([motor], [direction], [speed]) -- Drive [motor]

      (0 for A, 1 for B) in [direction] (0 or 1) at a [speed]

      between 0 and 255. It will spin until told to stop.

    stopArdumoto([motor]) -- Stop driving [motor] (0 or 1).

  setupArdumoto() is called in the setup().

  The loop() demonstrates use of the motor driving functions.

*/

// Clockwise and counter-clockwise definitions.

// Depending on how you wired your motors, you may need to swap.

#define CW  0

#define CCW 1

// Motor definitions to make life easier:

#define MOTOR_A 0

// Pin Assignments //

// Don't change these! These pins are statically defined by shield layout

const byte PWMA = 3;  // PWM control (speed) for motor A

const byte DIRA = 12; // Direction control for motor A

// constants won't change. They're used here to

// set pin numbers:

const int buttonPin = 0;     // the number of the pushbutton pin

const int ledPin =  13;      // the number of the LED pin

// variables will change:

int buttonState = 0;         // variable for reading the pushbutton status

void setup()

{

  setupArdumoto(); // Set all`` pins as outputs

  // initialize the LED pin as an output:

  pinMode(ledPin, OUTPUT);      

  // initialize the pushbutton pin as an input:

  pinMode(buttonPin, INPUT);

}

void loop()

{

  buttonState = digitalRead(buttonPin);  

  // check if the pushbutton is pressed.

  // if it is, the buttonState is HIGH:

  if (buttonState == LOW) {     

    // turn LED on:    

    digitalWrite(ledPin, HIGH);  

    

    // Drive motor A (and only motor A) at various speeds, then stop.

    driveArdumoto(MOTOR_A, CW, 68); // Set motor A to CCW at any value between: 0 and 255 (255 =

max speed)

 

    delay(12000); //this is the time delay in [ms] that the motor will run for

  }

  else {

    // turn LED off:

    digitalWrite(ledPin, LOW);

    

    stopArdumoto(MOTOR_A); //motor will not run

}

}

// driveArdumoto drives 'motor' in 'dir' direction at 'spd' speed

void driveArdumoto(byte motor, byte dir, byte spd)

{

    digitalWrite(DIRA, dir);

    analogWrite(PWMA, spd);

 

}

// stopArdumoto makes a motor stop

void stopArdumoto(byte motor)

{

  driveArdumoto(motor, 0, 0);

}

// setupArdumoto initialize all pins

void setupArdumoto()

{

  // All pins should be setup as outputs:

  pinMode(PWMA, OUTPUT);

  pinMode(DIRA, OUTPUT);

  // Initialize all pins as low:

  digitalWrite(PWMA, LOW);

  digitalWrite(DIRA, LOW);

}