Week 5: Leave Me Alone Box- Toby and Dom

In the penultimate week of our arduino project, we actually managed to make a working model! By figuring out the correct code to turn the stepper motor a set amount of degrees, it turns the switch off and returns back into the box after doing so.

When first testing this sketch model, we found that the stepper motor didn’t have enough torque to flick the switch off. This is why we had to add an extension onto the switch to increase the moment force, making it easier to turn.

Below is a youtube link to the video of it working:

Here is the code we are currently using:

#include <Stepper.h>

const int switchPin = 2;
const int stepsPerRevolution = 500;
int switchState = 0;
int currentState = 0;
int lastState = 0;

Stepper myStepper(stepsPerRevolution, 8, 10, 9, 11);

void setup() {
 // put your setup code here, to run once:
 pinMode(switchPin, INPUT);

void loop () {
 switchState = digitalRead(switchPin);
 if (switchState == 1)
 currentState = 1;
 lastState = 0;
 if (switchState == 0)
 currentState = 0;
 lastState = 1;

if (currentState == 0 && lastState == 0)
 switchState == digitalRead(switchPin);


Our next step is to make the arm stop after one rotation from turning the switch off to return into the box. We also need to combine the set up for the servo into the same arduino and breadboard as well as write up one script of code with cases for different actions.


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 )

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s