User login

Powered by Drupal, an open source content management system

Theory and Practice of Tangible User Interfaces

Lab 6: DC Motor Actuation 1

Submitted by Becky on Tue, 10/14/2008 - 21:58

Assignment: DC Motor: Actuation Assignment 1

Collaborators:

Description: In this lab, we learned how to control DC motors with analog input devices.  I created a system of using one potentiometer, 3 photocells, and 3 motors.  The potentiometer acts as a sort of on off switch for the system.  Once it is turned, an LED turns on to show that the system is on, if photocell 1 is occluded, motor 1 spins; when spinning, the shape on motor 1 occludes photocell 2, which makes motor 2 spin after a brief pause; when spinning, the shape on motor 2 occludes photocell 3, which makes motor 3 spin after a brief pause.  To stop the motors, the user remove occlusion from photocell 1.  The motors will stop spinning after that, and the user can reset the shapes attached to the motors so that the photocells are again exposed to the light.  When the user turns the system on again using the potentiometer, the motors will not spin because the shapes attached to them have been reset.  Now the user can cover photocell 1 and the process can repeat.

Components:

  • Arduino board
  • laptop
  • 2 breadboards
  • 1 potentiometer
  • 3 photocells
  • 3 dc motors
  • 3 AA battery power supplies
  • cardboard
  • 3 transistors
  • 3 diodes
  • 2 leds
  • wire
  • usb cable

Code:

/*
* one pot fades one led
* modified version of AnalogInput
* by DojoDave <http://www.0j0.org>
* http://www.arduino.cc/en/Tutorial/AnalogInput
*/
int pot1Pin = 0; // select the input pin for the potentiometer
int photo1Pin = 1;
int photo2Pin = 2;
int photo3Pin = 3;
int pot1Val = 0; // variable to store the value coming from the sensor
int photo1Val = 0;
int photo2Val = 0;
int photo3Val = 0;
int led1Pin = 10; // select the pin for the LED
int led2Pin = 11;
int motor1Pin = 9; // select the pin for the Motor
int motor2Pin = 5; // select the pin for the Motor
int motor3Pin = 6; // select the pin for the Motor


void setup() {
Serial.begin(9600);
}

void loop() {
pot1Val = analogRead(pot1Pin); // read the value from the sensor, between 0 - 1024
photo1Val = analogRead(photo1Pin); // read the value from the sensor, between 0 - 1024
photo2Val = analogRead(photo2Pin); // read the value from the sensor, between 0 - 1024
photo3Val = analogRead(photo3Pin); // read the value from the sensor, between 0 - 1024

analogWrite(led1Pin, pot1Val/4); // analogWrite can be between 0-255

if (photo1Val > 200){
analogWrite(motor1Pin, 0);
analogWrite(motor2Pin, 0);
analogWrite(motor3Pin, 0);
analogWrite(led2Pin, 0);
}else if (photo1Val<200 && photo2Val>740 && photo3Val>970){
analogWrite(led2Pin, photo1Val); // analogWrite can be between 0-255
analogWrite(motor1Pin, 50); //analogWrite can be between 0-255
analogWrite(motor2Pin, 0);
analogWrite(motor3Pin, 0);
}else if (photo1Val<200 && photo2Val<740 && photo3Val>970){
analogWrite(led2Pin, photo1Val); // analogWrite can be between 0-255
analogWrite(motor1Pin, 50); //analogWrite can be between 0-255
delay(1000); // waits 1 second
analogWrite(motor2Pin, 100);
analogWrite(motor3Pin, 0);
}else if (photo1Val<200 && photo2Val<740 && photo3Val<970){
analogWrite(led2Pin, photo1Val); // analogWrite can be between 0-255
analogWrite(motor1Pin, 50); //analogWrite can be between 0-255
delay(1000); // waits 2 second
analogWrite(motor2Pin, 100);
delay(2000); // waits 2 seconds
analogWrite(motor3Pin, 100);
}
writeDataToPC(pot1Val, photo1Val, photo2Val, photo3Val);
}

void writeDataToPC(int potA, int photo1, int photo2, int photo3){
//Serial.print("a");
//Serial.println(potA);

Serial.print("c");
Serial.println(photo3);
}

Images:

IMG_1772crop

Motor 1 and photocell 2 are connected to the square shape; Motor 2 and photocell 3 are connected to the round shape; Motor 3 is connected to the cross.

IMG_1759crop

Both Motor1 and Motor 2 are spinning.

IMG_1765crop

The sytem at rest; potentiometer turned so blue light glows.

Observations/Conclusions:

The code reflects a system wherein the potentiometer's sole purpose is to turn the blue LED on and off.  This is because, after testing the system, I realized that I could program it so that, as long as photocell 1 was not occluded, the motors would not run.

In the future, it would be interesting to attach different kinds of shapes to these motors.  The system I built with cardboard, a manilla folder, and cork is good for showing the functionality of the system, but is not the most attractive presentation.

Using more than one breadboard creates a delicate system in which it is difficult to maintain all of the connections while the motors and photocells are also in box.