Week 4: Leave Me Alone Box – Dom and Toby

This week we have been busy creating a sketch model of our box. We successfully setup and coded a servo so that it can open the lid of the box when the potentiometer is turned. The potentiometer allows the box lid to be raised different heights, but we will replace the potentiometer with code in our final model so that the only input is the switch.

This is the code we used:

#include <Servo.h>
Servo myservo;
int potpin = 0;
int val;
void setup()
{
myservo.attach(9);
}
void loop()
{
val = analogRead(potpin);

val = map(val, 0, 1023, 0, 100);

myservo.write(val);

delay(15);
}

This is the setup we used:

5U4XPK1HDL4xZZxd9_M-LYD0vXU-k5bOoMq4jnCRvovoVKXOT0zifN1PwjrPrNhjV1DyLKX2g6yFUcO207I58O8b-nSvoX4h-OHL87OsBX4Ic5fZ_T5dn3h2iwtkJ93DBjcWmzhQxE2aZtr3ULlqnZ07OxyqQOO0Hs_K94fl-ORRmbTtfR_0wVxXyrbteZRFKBGLpSxVsa2CX32WRKjp5U691VujW-r5CZ6FoJlC8ZfccC8wdaLeetxB5n39Xi4bRhpFfxoSau5k24-RJjUPtppvNiwhWTyLJkKuDAisxYzYGdcSktFuNV90-dKWfN8dw5KC-wUZFanqP4tvaieSMHDfuyPwpOPTOJSXp_LEbpXLkED4ha8La3GQmzgJ5P8n7JxEGKXKdlXMDB5mDCkOKDO4Hx52DxzCn8LJfbrFCtQN9P0T16KM-NI1Hn4R6dRxFVa4ZNvaJzb-6L62TEpLIt-r9y9xdYpehxB02mRuPrEO7vj1UgJPaxLc4A0sR5btVa-CXqMX3jcq-8dirNJRvnJt0eLJX-EqIfZpKmoNb8IQ1ewesRw3kfQvJZXYhHN3qRmuai-mQ9qJBUmF1x7gcy4FY41F24JQDucU-r7MsnIFfJ4l8TZz=s659-no.jpg

This is a YouTube video of it working:

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