Lab7: Output — DC Motors

Yuetian Wang
Oct 19, 2021

--

Yuetian Wang, Professor Kimiko Ryokai, Info C262, Tangible User Interfaces, Fall 2021

Description

I tried to use the Senbazuru as the tactile output to create the rotational motion. And the red LED is another outputs. The rotation rate of Senbazuru and the brightness of the LED can be adjusted by the potentiometer.

Image

Code

/* DC Motor with potentiometer control
* Theory and Practice of Tangible User Interfaces
* Fall 2021
*/

int motorPin = 9;
int potPin = A0;

int potVal = 0;
int motorCtrlVal = 0;

void setup() {
pinMode(potPin, INPUT);
pinMode(motorPin, OUTPUT);
Serial.begin(9600);
}

void loop() {
potVal = analogRead(potPin);
Serial.print("potVal: ");Serial.println(potVal);
motorCtrlVal = map(potVal, 0, 1024, 0, 255);
Serial.print("motorCtrlVal: ");Serial.println(motorCtrlVal);
analogWrite(motorPin, motorCtrlVal);
}

Video

Components Used

1-Arduino

1-Breadboard

1-LED

1- 1K ohm Resistor

1- Diode

1- Transistor

1- DC Motor

1- Potentiometer

--

--