10. Input devices¶
Started with the Group Assingment
A fun week where I decided to test using a sensor I’m gonna need in my final project : A motion sensor , cause I want to monitor my cat’s toilet visits number .
What motion sensor ?¶
I watched this Video m which made a useful comparison between the RCWL-0516 Microwave & HC-SR501 PIR Motion sensors . I chose to use the PIR sensor , cause I need a short range motion detection and not in all angles .
Design¶
Desinged my circuit on KiCad ,
Did the routing ,
And used Gerber Viewer & Gimp to get my photos for machining .
The design files are Here
Milling¶
Using FabModules , I generated the Gcode .
Milled on China Router , using OpenBuilds .
And we have a board !
Soldering¶
Quite easy , with such few components .
Programming¶
The code
#include <avr/io.h>
#define output(direction,pin) (direction |= pin) // set port direction for output
#define set(port,pin) (port |= pin) //set port pin
#define clear(port,pin) (port &= (~pin)) // clear port pin
#define pin_test(pins,pin) (pins & pin) // test for port pin
// The Sensor is connected to PB4 & Led to PB3
#define Led_port PORTB
#define Led_direction DDRB
#define Led_pin (1 << PB3)
#define Sensor_port PORTB
#define Sensor_direction DDRB
#define Sensor_pins PINB
#define Sensor_pin (1 << PB4)
void setup() {
// set Led as output
output(Led_direction,Led_pin);
clear(Led_port,Led_pin);
// Setting sensor first reading as 0
clear(Sensor_port,Sensor_pin);
}
void loop(){
//Read Sensor and toggle Led based on Sensor input
if (pin_test(Sensor_pins,Sensor_pin))
set(Led_port,Led_pin);
else
clear(Led_port,Led_pin);
}
Uploaded using Arduino IDE
And it’s alive !!