Skip to content

10. Input Devices


This week’s group assignment is to probe an input device’s analog and digital signals and to document the work in a group or individually. As individual assignment I have to measure something. ie after adding a sensor to a microcontroller board that I have designed I have to read it.

Files and Tools

Input Board File
Program to detect motion

Roland Modela MDX-20
Arduino IDE

The 3-month lockdown has changed a lot of things for me and everyone around me. I have decided that I have to chuck my initial project idea and that is mentioned in week 1 and decided on a new project plan. The new idea is to create an automated cat litter system for my cats. Already one group has presented their final project. I don’t have much time and have to spirally develop the project starting this week.
A feature of automated cat litter box needs to be detecting the presence of cat. The cleaning process should start only when a cat is not inside the box, ie an input should go into the box that the cat is not there. For this I need a sensor that detects the cat’s presence. I thought a motion sensor would be good for this.


Tips for using pet-friendly sensors
When sensors creates problems
Ultrasonic deterrents reduce nuisance cat activity on suburban properties Although both PIR sensor and ultrasonic sensor are widely used for projects related to cats, after reading the problems created by ultrasonic sensors, when they malfunction, I decided to use a Passive Infra Red(PIR) sensor instead. The term passive means that the sensor is using energy for detecting purposes; it just works by detecting energy given off by the other objects and not actively emit heat.

Group Assignment

Find it here

Individual Assignment

I didn’t know where to start, and Joel told me to buy a PIR sensor module from the local electronics shop as we don’t have one at our lab. This modeule looked like a tiny board with a white dome on one side and 3 pins sticking out from the other along with other components inside. That dome is designed so the heat from the living beings would all be concentrated to the lens, called fresnel lens.
I removed the dome to see the internal part of the dome. This showed the markings and each of the pins were named as well. GND, Digital Out and +5 input are marked clearly.

Designing the board

Next I designed my hello.HC-SR501 board. I used Prof.Neil’s design and made the necessary changes. Initially, I followed Neil’s drawing designed using an ATtiny 45 as the microcontroller. I needed only very few I/O pins which needed to be connected to PIR, relay driver, and indicator LED. But, later when Joel, our teaching assistant, suggested using a microcontroller with more pins, ie ATTiny44 and since we don’t have ATTiny44 I used ATTiny84 which has the same pins. This helps in extending the project later on. I used Eagle for designing the circuit. Designing the board was pretty straight forward. I used my own board from electronic design as a base design and made the changes required. I added a resonance crystal Xtal 20hz as an external clock. In order to provide an external supply of 5V I’ve added a voltage regulator LM7805. I added a FTDI header for communication. I also added an LED to indicate the status of whether PIR Detects motion or not. The PIR sensor HC-SR 501 has only three pins, 5V, GND and Output pin. I connected the output pin to the pin 10 of the microcontroller. I connected LED over pin 11 through a 499 ohm resistor. After a bit of trial and error I was able to route it. I had to add a 0ohm resistor between the GND of FTDI header and the rest of the components with GND. Once I finished the routing I decided to add the word “Input” underneath the board to distinguish it from other boards. Addendum: Later on it proved really useful because every board is similar and everyone has multiple boards and this helped me to identify easily. Also it showed me the TOP and BOTTOM according to my design.

Schematics File

Board File


I milled using Roland Modella MDX-20. I followed the same procedure as I did for completing week 5

Traces ready to be milled

Milling in progress

My traces looked like a dog bit it. This was because the bit wasn’t very good. But I decided to use it and did a bit of cleaning up with the


I got all other components from the lab.

Components for soldering

While soldering, I realised that the board would look better if the PIR sensor is placed behind the board. So I put holes through the board at the pads of the PR sensor and attached a 3 pin header on the other side. Now I connected the respective VCC and GND carefully as the places have now mirrored.

Board after Soldering


I have done embedded programming week from another computer. So I had to download Arduino software. I connected my ATTiny from my electronic design week to program my Hello HC.SR501 board. I tried to understand Neil’s board and I also used this link. First I wrote a simple program that gives an output 1 when motion is detected and 0 otherwise.

Then I edited it to give output as motion detected whenever it detects motion.

PIR Sensor

Board connected

// This is a comment that doesn't affect the code, just text to explain.

#include <SoftwareSerial.h> //This is a library that make us initialize the communication to use the TX & RX pin.

#define RX    0 // In my board I don't use the RX, I chose an unconnected pin.
#define TX    1 // the pin that the ATtiny RX will send data to the PC
#define s 3 // pin connected to sensor's output
#define led 2 //pin connected to LED 

SoftwareSerial window(RX, TX); // giving the pin variables to the softwareSerial library after defining them in the line upward.

void setup()
  window.begin(9600); //define the baud rate that the communication will start on.
  pinMode(led, OUTPUT);
  pinMode(s,  INPUT);
void loop()
  int waittime=0;
  int val; //variable to store the values of the reading.
  val = digitalRead(s); // read the input pin and store it in Val variable.
    window.println("Motion Detected"); 
    digitalWrite(2, HIGH);
    else if(val==0)
  window.println("No Movement");  
  digitalWrite(2, LOW);  
  delay(1000); //Optional delay to ease reading the serial monitor values.


Mistakes and Learnings

One of the most common mistakes with PIR sensor, which I would have also made had Joel not warned me, is to connect the pins of PIR sensor in reverse order.
I learned to program the board after giving time delay.