Making Things Interactive

February 12, 2008

Assignment 5

Filed under: 5: Making Motion,Assignments,Lingshui Wang — lingshui @ 2:27 am

So after talking to Jet, I decided to use a rangefinder offline, here I’m experimenting with the rangefinder (variable analog switch) and a servo motor, whenever the rangefinder detects motion, it sets the servo through a script, there is sometimes a slight delay because of the time delays in the servo script. Here’s the code and a video:

int servoPin = 10; //set servo to digital PWM pin 10
int rangeFinder = 0; //set rangefinder to analog 0
int val;
int val2;
int servoMode = 0; //set variable modes for servo

void setup ()
{
Serial.begin(9600); //set up serial library
pinMode (servoPin, OUTPUT); //servo output
pinMode (rangeFinder, INPUT); //rangefinder input
}

void loop(){
Serial.print(“Value: “);
Serial.println(val); //print value to monitor switch values
val = analogRead(rangeFinder);
delay(10);
val2 = analogRead(rangeFinder); //check values match before taking action
if (val == val2) {
if (val < 30) { //if resistance is less than 30... servoMode = 1; //run servomode 1 if (servoMode == 1) { //servomode 1 analogWrite (servoPin, 10); delay (1000); analogWrite (servoPin, 200); delay(1000); } if (servoMode == 0) { //servomode 0 (default) digitalWrite (servoPin, LOW); } }}} [/sourcecode]

Advertisements

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: