Tuesday, December 29, 2009

Mill: servo switch relay...

I've been using my mill quite a bit in an attempt to make a circuit board. I've finally gotten annoyed with having to turn my dremel on and off manually and decided it was time to upgrade to automation. The first step was to come up with a simple way to control a high powered device through my arduino. I thought about using a relay board. However, I went with something I thought would be a lot more fun to assemble.



All the household switch parts cost about $4. The servo was just one I had lying around. I'm sure a $12 servo would do the trick.

Next, I did a little research on G-Code, knowing the commands were already standardized. It turns out M03 is the standard command for "Turn Clockwise" and M05 is the standard for "Stop Turning". I updated my firmware and added a servo library. Here it is installed:



I am happy with the result. I did a quick search on thingiverse to see if others have done this and found a much more elegant solution: Servo Controlled Switch by oomlout

Saturday, December 19, 2009

Spiderwheels: eyes...

I have been putting a lot of thought into how to make the head of my spider and finally settled on a simple proximity sensor from SparkFun with two degrees of freedom. It is always good to start with a proof of concept and so I wired it up to my breadboard sanguino. I basically made it pan until it finds an obstacle and then nod. Here is a video:



Here is the source code:

#include <Servo.h> 
Servo zServo; //rotates about z
Servo xServo; //rotates about x

float zPos = 90; //keeps track of position. 90 degrees is resting.
float xPos = 90; //keeps track of position. 90 degrees is resting.

int milisecondsBetween = 20; 
int vMax = 300;

int sensorPin = 0;    // select the input pin for the potentiometer
int sensorValue = 0;  // variable to store the value coming from the sensor

void setup() {
  zServo.attach(13);  // attaches zServo object to pin 13 
  xServo.attach(12);  // attaches xServo object to pin 12 
  Serial.begin(19200);
}
void loop() {
  goLeft();
  goRight();
}
void goLeft(){
  float z = zPos;
  sensorValue = analogRead(sensorPin); 
  while(sensorValue < vMax && z > 50){
    z -= 10;
    moveTo(xPos, z);
    sensorValue = analogRead(sensorPin); 
  }
  if(sensorValue >= vMax){
    sayHi();
    printV(sensorValue);
  }
}
void goRight(){
  float z = zPos;
  sensorValue = analogRead(sensorPin); 
  while(sensorValue < vMax && z < 130){
    z += 10;
    moveTo(xPos, z);
    sensorValue = analogRead(sensorPin); 
  }
  if(sensorValue >= vMax){
    sayHi();
    printV(sensorValue);
  }
}
void printV(int v){
  Serial.print("v: ");
  Serial.print(v);   
  Serial.print("\r\n");  
}
void sayHi(){
  moveTo(90, zPos);
  moveTo(110, zPos);
  moveTo(90, zPos);
}
void moveTo(float x, float z){
  while(xPos != x|| zPos != z){
    if(xPos > x){
      xPos -= 1;
    }
    else if(xPos < x){
      xPos += 1;
    }
    if(zPos > z){

      zPos -= 1;
    }
    else if(zPos < z){
      zPos += 1;
    }
    zServo.write(zPos);
    xServo.write(xPos);
    delay(milisecondsBetween);
  }
}