Step 4Step 6 More info on the 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 Step | Download PDFView All Steps | Next Step » |
1
comment
|
Add Comment
|
![]() |
Add Comment
|















































