3 Simple Ways to
Share What You Make

With Instructables you can share what you make with the world — and tap into an ever-growing community of creative experts.

PhotosPhotos

Share one or more photos of a project, recipe, or whatever you've made, quickly and easily.

Step by StepStep-By-Step

Share your step-by-step photos with text instructions of what you made so others can do it too!

VideoVideo

Share your how-to video. You'll need your embed code from a video site such as YouTube.

Motion Sensor Cat Toy (endless fun... literally)

Step 4Step 6 More info on the code

Step 6 More info on the code
Here is the pseudo code and commented C code:

Microcontroller pseudo code

Delay 42 seconds in the beginning (7, 6 second delays)
Port 4 (motor) is the output
Port 3 is the input (motion sensor)
If the motion sensor = 5 V, spin the motor for 12 seconds
Then turn it off

The C code

#include <avr\io.h> // include input and output instructions
#define F_CPU 1000000UL // processor speed is 1 MHz
#include <util\delay.h> // include delay function

int main(void)
{

_delay_ms(6000); // delay 6 seconds
_delay_ms(6000); // delay 6 seconds
_delay_ms(6000); // delay 6 seconds
_delay_ms(6000); // delay 6 seconds
_delay_ms(6000); // delay 6 seconds
_delay_ms(6000); // delay 6 seconds
_delay_ms(6000); // delay 6 seconds

DDRB |= (1 << 4); // define PORTB 4 as an output, rest inputs

while(1)
{
if (PINB & 0x08) // if motion is sensed on PORTB3
{
PORTB |= (1<<4); // turn motor on
_delay_ms(6000); // delay 6 seconds
_delay_ms(6000); // delay 6 seconds
PORTB = 0x00; // turn motor off
}
}
}
« Previous StepDownload PDFView All StepsNext Step »
1 comment
Mar 10, 2009. 12:32 PMJoeyJunior says:
The microcontroller was an Atmel Attiny25

Pro

Get More Out of Instructables

Already have an Account?

close

All Steps Viewing
View all steps of an Instructable on the same page when you're a Pro Member.

Upgrade to Pro today!
7
Followers
2
Author:Kateham