Making Things Interactive

February 19, 2008

tilt sensor servo motor

Filed under: 5: Making Motion,Assignments,Christopher Bridgman — cbridgma @ 1:44 am

so, i guess this is a continuation of the making motion assignment. in my first attempt at this making motion, i tried using a simple button switch which when activated, sent a power surge into my usb port. me and a couple other students tried again to get a solenoid working, but we think that it is trying to send power into the arduino, not ground, and thus not working. so to complete the making motion assignment, i used a tilt sensor to control where the servo motor goes to. the servo motor goes to a certain position when the tilt sensor is HIGH, and to another position when the sensor is LOW.

int statusPin = 13;                // LED connected to digital pin 13
int switchPin = 6;                 // Gravity switch connected to pin 6
int servoPin = 11;                 //servo connected to pin 11
int val;

void setup()                    // run once, when the sketch starts
{
  pinMode(statusPin, OUTPUT);      // sets the digital pin as output
  pinMode(servoPin, OUTPUT);
  pinMode(switchPin, INPUT);
  Serial.begin(9600);  //sets the digital pin as input
}

void loop()                     // run over and over again
{
  val = digitalRead(switchPin);

  Serial.print("Value: ");
  Serial.println(val);    

  if (val == 1)
  {
      analogWrite(servoPin,16);
      digitalWrite(statusPin,HIGH);
    }
  if (val == 0)
  {
    analogWrite(servoPin,96);
    digitalWrite(statusPin, LOW);
  }
}
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

Create a free website or blog at WordPress.com.

%d bloggers like this: