Pet Trick Final

[yframe url=’′%5D

My pet trick didn’t turn out exactly how I planned but it was close.  The biggest problem is that I ran out of time to really spend on Arduino code.  The code I ended up with works fairly well and is very simple:

//initialize vars
const int ledPin = 9;
int aVal = 0;
int dist = 0;

void setup(){
pinMode(ledPin, OUTPUT);


void loop(){
//read analog signal
aVal = analogRead(A0);
// convert distance to briteness
dist = map(aVal, 40, 700, 0, 90);

if (dist > 1) {
analogWrite(ledPin, dist);
else if (dist < 1){
analogWrite(ledPin, 0);

I wanted to do something with easing so that the LED wouldn’t just turn on and off and wouldn’t flicker the way it does.  The flickering is not so bad since it works with the Halloween theme, but I would have preferred an easing functionality.  I spent about an hour trying to code this but it was too complicated and I had more pressing things to finish since the code was functional.  I’m pretty sure its fairly simple math.  Hopefully I’ll learn it soon.

I finished the circuit, which splits one 9v battery between Arduino and LED and has one dedicated to LED.

Here’s the final circuit, with two batteries, IR sensor, transistor, LED and Arduino.

After putting the frame together I put the electronics inside the frame.

Then I tested the electronics and tweaked my Arduino code before putting the back on.  A friend helped me test it.  Again it wasn’t perfect, but I adjusted the range in the map() function until I was happy with the distance at which the light was activated.

[yframe url=’’%5D

Then I put the back on.  This was complicated because I had to put the switch on and plug it into the bread board first and I had to cut out the slots for the cat parts in advance.

Then I used the slots to test the cat parts and cut new ones.

I set the cat parts with wood glue. Finally it was all together.  I think it works best in the dark.

[yframe url=’’%5D

Improvements I would like to make:

The design didn’t make enough room for the wiring and somehow the space at the bottom for all the electronics was smaller and didn’t fit everything as well.  I also intended to secure all of the electronics which would have helped the previous issue but I didn’t have time.  The switch was unnecessarily large.  I did a poor job cutting the wood and it looks uneven and doesn’t fit everywhere, which looks okay with the halloween theme, but isn’t what I intended.   The cat parts are too frail.


Author: owen ribbit


Leave a Reply

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

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