Wednesday, October 3, 2007

Lab_04 | Connecting a flex sensor

I connected a flex sensor instead of a pot. When I bent a flex sensor, a servo changed. Actually I did this lab with Chris and David because we are in the same group. The voices in this video are from them .

Lab_04 | The servo follows the pot!

After I programmed the microcontroller, I could make the servo move.

Lab_04 | Programming the microcontroller

I copied and pasted this code from the lab page
but I didn't understand this code very well.

I think I need to study programming arduino more..


int servoPin = 2;
int minPulse = 500;
int maxPulse = 2500;
int pulse = 0;

long lastPulse = 0;
int refreshTime = 20;

int analogValue = 0;
int analogPin = 0;

void setup() {
pinMode(servoPin, OUTPUT);
pulse = minPulse;
Serial.begin(9600);
}

void loop() {
analogValue = analogRead(analogPin);
pulse = (analogValue * 19) / 10 + minPulse;


if (millis() - lastPulse >= refreshTime) {
digitalWrite(servoPin, HIGH);
delayMicroseconds(pulse);
digitalWrite(servoPin, LOW);
lastPulse = millis();
}
}

Lab_04 | Connect an anolog input and a servo

First of all, I connected power and ground on the breadboard to power and ground from the arduino. And then, I connected the pot to analog pin 0 as an analog input and connected a seromotor to digital pin 2. The blue wire in the right side is a servo.