motor knife (Spencer Russell)

giphy

This is my project for the kitchen. I use a light sensor and two servos and a button to make it run. You can make the knife side to side giving it action that has to be done by hand.

#include <Servo.h>

Servo myservo1;
Servo myservo2;

int pos = 0;
int LDR = 0;
int LDRValue = 200;
int light_sensitivity = 200;
const int Safebutton = 6;
const int ledPin = 7;
const int button1 = 2;
const int button2 = 3;
const int button3 = 4;
const int button4 = 5;

int buttonSafeState = 0;
int button1State = 0;
int button2State = 0;
int button3State = 0;
int button4State = 0;

void setup()
{
myservo1.attach(11);
myservo2.attach(10);
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
pinMode(Safebutton, INPUT);
pinMode(button1, INPUT);
pinMode(button2, INPUT);
pinMode(button3, INPUT);
pinMode(button4, INPUT);
}

void loop()
{
buttonSafeState = digitalRead(Safebutton);
button1State = digitalRead(button1);
button2State = digitalRead(button2);
button3State = digitalRead(button3);
button4State = digitalRead(button4);
LDRValue = analogRead(LDR);
//Serial.println(LDRValue);
Serial.println(Safebutton);
delay(50);

if (LDRValue < light_sensitivity && digitalRead(Safebutton))
{

digitalWrite(ledPin, HIGH);
for (pos = 0; pos <= 180; pos += 1) {
myservo1.write(180-pos);
myservo2.write(pos);
delay(15);

}

}
else
{
digitalWrite(ledPin, LOW);
myservo1.write(0);
myservo2.write(180);
delay(15);

}
}

This is the code I used. I had to make the to motors move in the same path at the same time to allow it to have more power behind it.

I learned a lot about safety in this because it could have cut someone or yourself.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

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