Difference between revisions of "User:S8brown"
(Replacing page with 'Hi I'm Seth. Project') |
|||
| Line 1: | Line 1: | ||
Hi I'm Seth. | Hi I'm Seth. | ||
| − | [[User:S8brown/Project | | + | For my midterm project, I created a tilt sensing motor. |
| + | I made two tilt sensors out of ball bearings and bic pens and positioned them on either side of the motor at different angles. | ||
| + | When the motor/device is tilted in one direction, it will spin clockwise, and when tilted the other direction, counter-clockwise. | ||
| + | As for the aesthetic of the device, it would be fitted to the duty it was designed to perform such as a handle for a fishing pole, etc. | ||
| + | For testing, I affixed the components to a toilet paper tube with the tilt sensors pointing up a little bit so that they won't always be triggering. | ||
| + | |||
| + | (I let my friend borrow my Arduino, so there aren't any pictures of the "device" as a whole, but here are the main components!) | ||
| + | |||
| + | [[Image:http://i650.photobucket.com/albums/uu221/onebigword/photo.png]] | ||
| + | [[Image:http://i650.photobucket.com/albums/uu221/onebigword/photo2.png]] | ||
| + | |||
| + | And Here's the code! | ||
| + | |||
| + | |||
| + | int turn1 = 12; // choose the pins for controlling direction | ||
| + | int turn2 = 13; | ||
| + | int tilt1 = 4; // choose the input pin (for the tilt sensors) | ||
| + | int tilt2 = 5; | ||
| + | int val1 = 0; // variable for reading the pin status | ||
| + | int val2 = 0; | ||
| + | |||
| + | void setup() { | ||
| + | pinMode(turn1, OUTPUT); // declare turn pins as output | ||
| + | pinMode(turn2, OUTPUT); | ||
| + | pinMode(tilt1, INPUT); // declare tilt sensors as input | ||
| + | pinMode(tilt2, INPUT); | ||
| + | |||
| + | digitalWrite(0,HIGH); // write a HIGH to allow for current to flow through pin | ||
| + | digitalWrite(1,HIGH); | ||
| + | } | ||
| + | |||
| + | void loop(){ | ||
| + | val1 = digitalRead(tilt1); // read input value | ||
| + | val2 = digitalRead(tilt2); | ||
| + | |||
| + | if (val1 == HIGH) { // if tilted, turn the motor! | ||
| + | pinMode(turn1,OUTPUT); // turn the pins on | ||
| + | pinMode(turn2,OUTPUT); | ||
| + | digitalWrite(turn1, LOW); // turn the motor! | ||
| + | digitalWrite(turn2, HIGH); | ||
| + | } | ||
| + | if (val2 == HIGH) { // if tilted, turn the motor! | ||
| + | pinMode(turn1,OUTPUT); // turn the pins on | ||
| + | pinMode(turn2,OUTPUT); | ||
| + | digitalWrite(turn1, HIGH); // turn the motor the other way! | ||
| + | digitalWrite(turn2, LOW); | ||
| + | } | ||
| + | if(val1 != HIGH && val2 != HIGH){ // if it's not tilted either way | ||
| + | pinMode(turn1,INPUT); // turn the output pins "off" | ||
| + | pinMode(turn2,INPUT); | ||
| + | } | ||
| + | } | ||
| + | |||
| + | |||
| + | [[User:S8brown/Project | Other Projects]] | ||
Revision as of 19:38, 11 June 2009
Hi I'm Seth.
For my midterm project, I created a tilt sensing motor. I made two tilt sensors out of ball bearings and bic pens and positioned them on either side of the motor at different angles. When the motor/device is tilted in one direction, it will spin clockwise, and when tilted the other direction, counter-clockwise. As for the aesthetic of the device, it would be fitted to the duty it was designed to perform such as a handle for a fishing pole, etc. For testing, I affixed the components to a toilet paper tube with the tilt sensors pointing up a little bit so that they won't always be triggering.
(I let my friend borrow my Arduino, so there aren't any pictures of the "device" as a whole, but here are the main components!)
File:Http://i650.photobucket.com/albums/uu221/onebigword/photo.png File:Http://i650.photobucket.com/albums/uu221/onebigword/photo2.png
And Here's the code!
int turn1 = 12; // choose the pins for controlling direction
int turn2 = 13;
int tilt1 = 4; // choose the input pin (for the tilt sensors)
int tilt2 = 5;
int val1 = 0; // variable for reading the pin status
int val2 = 0;
void setup() {
pinMode(turn1, OUTPUT); // declare turn pins as output pinMode(turn2, OUTPUT); pinMode(tilt1, INPUT); // declare tilt sensors as input pinMode(tilt2, INPUT); digitalWrite(0,HIGH); // write a HIGH to allow for current to flow through pin digitalWrite(1,HIGH);
}
void loop(){
val1 = digitalRead(tilt1); // read input value
val2 = digitalRead(tilt2);
if (val1 == HIGH) { // if tilted, turn the motor!
pinMode(turn1,OUTPUT); // turn the pins on
pinMode(turn2,OUTPUT);
digitalWrite(turn1, LOW); // turn the motor!
digitalWrite(turn2, HIGH);
}
if (val2 == HIGH) { // if tilted, turn the motor!
pinMode(turn1,OUTPUT); // turn the pins on
pinMode(turn2,OUTPUT);
digitalWrite(turn1, HIGH); // turn the motor the other way!
digitalWrite(turn2, LOW);
}
if(val1 != HIGH && val2 != HIGH){ // if it's not tilted either way
pinMode(turn1,INPUT); // turn the output pins "off"
pinMode(turn2,INPUT);
}
}