Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

The team utilized an Arduino Uno to control the mechatronic components of the system. In the main loop of the code shown below, the Aduino first checks the state of the Hall effect sensor. When the user puts a magnet in proximity to the Hall effect sensor, its state changes from high to low and when . When the magnet is removed from the sensor the state changes from low to high. Upon a transistion from low to high, the code checks the servo position and commands the servo to toggle to a different position. The first time a magnet is brought close to the sensor and removed the gripper mechanism will close. If the process is repeated the mechanism will open. We utilized this logic so that the user only has to tap the side of the device with a magnet to get the gripper to open or close. The code shown below was compiled to the Arduino to demonstrate the prototype, and a more robust code that includes voltage monitoring is in progress.

...

Code Block
languagec#
titleRobot Gripper Code
linenumberstrue
#include <Servo.h>
Servo myservo;  // create servo object to control a servo
int val = 0;    // variable to store the servo position
int openPos=180;
int closePos=0;
char reader=0;
const int hallPin = 2;
const int servoPin = 10;
const int ledPin = 13;
const int closedVal=120; // define servo open position in degrees
const int openVal=20; //define servo closed position in degrees
int hallState=0;
int lastState=1;
bool servoPosition=LOW;
void setup() {
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object
    // initialize the LED pin as an output:
  pinMode(hallPin, INPUT);
  pinMode(servoPin, OUTPUT);
  pinMode(ledPin, OUTPUT);
}
void loop() {
  hallState = digitalRead(hallPin);
   
  if (hallState == LOW && lastState == HIGH){
    if (servoPosition == HIGH){
      servoPosition = LOW;
      digitalWrite(servoPin, HIGH);
      digitalWrite(ledPin, HIGH);
      myservo.write(closedVal);
      delay(1000);
      digitalWrite(servoPin, LOW);
      digitalWrite(ledPin, LOW);
    }
  
  else{
          servoPosition = HIGH;
          digitalWrite(servoPin, HIGH);
          digitalWrite(ledPin, HIGH);
          myservo.write(openVal);
          delay(1000);
          digitalWrite(servoPin, LOW);
          digitalWrite(ledPin, LOW);    
      }
  }
  else{}
  lastState = hallState;
}
 

     

Next Page (Manufacturing Considerations) ->