Interactive Media

Mohamed Al-Kaf - Media Explorations

Using the Advanced Arduino KIT

Written by: Mohamed Al-Kaf | Posted on: | Category:

Using the advanced kit, I easily followed instruction to make the circuts and copy the code to the ardiuno. I found my self confused on how the code is read by the ardiuno. I was not sure how i can change the code to do something different. Looking deeper at code examples, that where included in the Advance Arduino KIt.

With experiment i was not sure what to create. Possible when i have an idea and want to see what i could acheive it would possible to build a basic portotype to see if the idea acheivable.

First idea that came into my mind was to create a automatic trash can. Using the distance ultrasonic distance sensor as trigger to move a servo which would be used to open the lid. Here is the code from the experintation. I noticed that the servos would not always move the angels that were wanted. upon futher research It could be because the plastic gears type and not the mataliic type which is more accurat in ts movement.

#include <Servo.h>

int trigPin = 9;
int echoPin = 10;
int led = 13;

Servo myservo;

int pos = 0;    // variable to store the servo position

void setup() {
  Serial.begin(9600);
  pinMode(led, OUTPUT);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
 myservo.attach(11);  // attaches the servo on pin 9 to the servo object
}

void loop() {
  long duration, distance;
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(1000);
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance = (duration / 2) / 29.1;
  Serial.print(distance);
  Serial.println("uCM");
  delay(10);

  if ((distance <= 8))
  {
    digitalWrite(led, HIGH);
  }
  else if (distance > 8)
  {
    digitalWrite(led, LOW);
  }

   for (pos = 15; pos <= 165; pos += 1) { // goes from 0 degrees to 180 degrees
   // in steps of 1 degree
   myservo.write(pos);              // tell servo to go to position in variable 'pos'
   delay(1);                       // waits 15ms for the servo to reach the position
  }
  for (pos = 165; pos >= 15; pos -= 1) { // goes from 180 degrees to 0 degrees
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(1);                       // waits 15ms for the servo to reach the position

  }
}