Showing posts with label avr. Show all posts
Showing posts with label avr. Show all posts

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








Wednesday, 13 November 2013

Make the Easiest AVRISP for your hardware hacking expeditions

I have always found my self in the chicken egg situation when making electronics using microcontrollers. Many open source programmers are based on microcontrollers which require specific firmware to be uploaded before they become useful or they require specific hardware. There are quite a number of open source designs of avr ISPs namely

USBASP

USBasp is a USB in-circuit programmer for Atmel AVR controllers. It simply consists of an ATMega88 or an ATMega8 and a couple of passive components. The programmer uses a firmware-only USB driver, no special USB controller is needed.
This is a great programmer but you must have another programmer to make the circuit useful.

Parallel Port programmer 

Serial Port Programmer

These are  great ones since they do not require any firmware on them but the down side is that a parallel port or the Serial port, which are absent in most new computers, is required to upload firmware to the mcu.

AVR Development boards 
There are quite a large flavour of these platforms offered by various vendors and they are great. They offer many features and support many chips but they are far out of reach for newbies especially in Kenya. 

To avoid all these problems then I used a design that programmes itself. This ISP has been used to upload bootloaders and burn fuses on new ATMEGA chips using the arduino IDE. What many people do not know is that with avrdude, you can upload firmware to any avr chip.
 In the Arduino examples there is an arduino ISP sketch that when uploaded turns an Arduino board into a programmer as seen in this Youtube video.

I had an arduino proto shield left over from previous and I went ahead and converted it into my isp following this design and below are pictures of what I made.




After the programmer is made see an avrdude tutorial here to upload firmware or use the arduino ide with the programmer for uploading firmware.

Snapshot of command line window with avrdude in action

 Feel free to ask any questions in the comments.

Happy hacking