Tuesday 1 April 2014

making infrared intruder counter / alarm


Introduction

This is a gadget for counting the number of times an infrared beam of light is interrupted. It is arduino based and implemented with an atmega328 chip on a veroboard. This is an easy project and may take a day to put together.

The counter working

Parts required

  • 220 ohms resistors
  • 10k resistors 
  • 4 digit 7 segment display
  • atmega328p/ arduino uno
  • infrared photo transistor
  • infrared diode
  • 7805 voltage regulator
  • power source: 7.5Vdc to 15Vdc
  • buzzer

Connecting it together

I use the pin mapping of the atmega328p from the arduino site and is also shown below. To protect the microcontroller pins from being destroyed by large currents that may flow, add 220 ohms resistors on the common cathodes or anodes of your display. 

For connecting the 4 digit  7 segment display use the assignment shown in the picture below. Just in case you have the same display I had, otherwise find the display pin assignment in the datasheet.



Connect the 4digit 7-segment display using pin assignement in the code and load the code to the MCU using a programmer. For me I use UsbTinyISP.

Code


/*Written by Dean Reading, 2012.  deanreading@hotmail.com
/Edited by Peter Mbari to Count number of Intruders using Infrared
 

 */

#include "SevSeg.h"

//Create an instance of the object.
SevSeg sevseg;

int sPin=12;
int buzzer=13;
int people=0;
//Create global variables
unsigned long timer;
int CentSec=0;

void setup() {
  //I am using a common anode display, with the digit pins connected
  //from 0-3 and the segment pins connected from 4-11
  sevseg.Begin(1,0,1,2,3,4,5,6,7,8,9,10,11);
  //Set the desired brightness (0 to 100);
  sevseg.Brightness(50);
  
  pinMode(sPin, INPUT);// Setup the Infared sensor pin as input
  
  pinMode(buzzer, OUTPUT);// Set Buzzer pin as output
  timer=millis();
}

void loop() {
  //Produce an output on the display
  sevseg.PrintOutput();
  
 if(digitalRead(sPin)==LOW)
 {
   people++;
  while(digitalRead(sPin)==LOW)sevseg.PrintOutput();
  digitalWrite(13,HIGH);  
  delay(500);
  digitalWrite(13, LOW);
 }
 
  
    //Update the number to be displayed, with a decimal
    //place in the correct position.
    sevseg.NewNum(people,(byte) 0);
  
}


Finaly after the board is assembled and working you get a nice display like the one shown in the video below.




Happy making








No comments:

Post a Comment