Part 1 – Secret Box

I started this project by perusing the Internet, looking at a variety of things that can be done with an Arduino. After learning that most things that can be imagined can be created using the wonder that is this micro-controller, I landed on one project in particular that someone had done and seemed to grab my attention. The ‘photovore’, a light following robot with two LDRs attached to the front controlling two motors.

http://www.instructables.com/id/First-Arduino-Robot-Light-Seeker/

This seemed like an interesting project to undertake but I wanted my own twist on it. I started looking into ‘sound dependent resistors’ rather than light dependent resistors or, as they’re more commonly known, microphones.

This project really excited me and I wanted to try to try to build this whole robot in the three weeks that we had for this project but as I looked into how this was going to need to be made, I soon realised that this idea wasn’t quite such a runner in three weeks.
I started to look into how it could be simplified to make the deadline of three weeks any kind of attainable. I thought about having two platforms, a bottom one with all the electronics on it and then a top one which would be sitting on a servo and could just rotate depending on where the sound was coming to and finish point at the origin of said noise.

I ended up realising that when it comes to an Arduino project while at uni, with three other projects on the go, three weeks is a very short amount of time, and so fairly soon my project was simply experimenting with sensors and getting a sensor and it’s value to move a motor, in my case, a servo.

Originally, I wanted the servo to be on the end of a linkage so that when it pushed the top of the box open it would actually open but when it came to it, the torque of the servo wasn’t high enough and so the lid rested right on the servo arm and the lid only opened a couple of centimetres but it worked.

I added an LED into the mix so that the user knew when they had found the way to open the secret box (cover the LRD) so that as the box opened the LED came on as well.

I started to put in all together by getting an LDR to control an LED…

IMG_3190

Then, when i had that working, I added in the servo…

IMG_3188_2

This is the code that I used for this first project:

#include <Servo.h>

Servo myservo;

int lightPin = 0;

int ledPin = 10;

int pos = 0;

const int threshold = 900;

void setup()

{

myservo.attach(9);

pinMode(ledPin, OUTPUT);

Serial.begin(9600);

}

void loop()

{

int lightLevel = analogRead(lightPin);

lightLevel = map(lightLevel, 300, 600, 0, 255);

if (lightLevel > threshold) {

digitalWrite(ledPin,HIGH);

for(pos = 0; pos < 90; pos += 1)

{

myservo.write(pos);

delay(15);

}

}

else {

digitalWrite(ledPin,LOW);

for(pos = 90; pos >=1; pos -=1)

{

myservo.write(pos);

delay(15);

}

}

Serial.println(lightLevel);

}

Screen Shot 2015-04-17 at 11.25.43 AM

Here is a video of the final product working…

Having made this design and seen how it works, I would probably want to take it further and modify it slightly have a more intricate locking system or to be a sort of halloween decoration. It could be kind of fun as this kind of novelty toy with two red LEDs inside so when the light levels outside drop a certain amount, the box opens up and the two LEDs flash to seem like evil eyes or once you get to a certain distance from them they light up. It felt like the design might lend itself more to that and this would allow me more learning opportunities like how to code for something to turn on once you are that certain distance away or how to use servos to pull objects in different directions to unlock a lid.

Although it was a simple project, it allowed me to learn a lot about how to write code, how to troubleshoot and how to use an Arduino. I learned more about how to calibrate a sensor for different environments, how to scale a sensors output values into something that the Arduino can use, how to move a servo arm and, as I set out to do, learn how to use sensors to control other components. It was a great starter project to allow me to move further in the world of Arduino.

Now onto making the full ‘sound following robot’…

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