RFID is most arguably a evolutionary wireless technology which boosted working of embedded devices up to great mark. And there is plenty of systems and devices working based on this technology. This article is focused to teach you how to interface RFID with AVR microcontroller. Before moving on to that interfacing part let’s begin with what RFID exactly is and how it works?
PRINCIPLE OF RFID:
Radio Frequency identification describes the system in which the identity of an individual or object is transmitted by means of a unique serial number through radio waves. Usually RFID system consists of two basic components they are
- Tag
- Reader
RFID tags consists of a simple Microchip which stores 12 byte unique ID and an antenna through which the unique ID is read by the reader. Whereas Reader is nothing but a specifically designed hardware module that senses the tag whenever it brought within a specific range say for example 10cms. The reader emit radio waves and receive signals back from the tag which comes with different operating frequency and sensing distance.
When a RFID tag is brought within the specific range of the reader the unique ID is sensed. After reading the ID from the tag is read by the reader and then that unique id is passed onto a controller/processor. The controller in turn performs specific action using that ID based on the written code.
SCHEMATIC DESIGN OF RFID INTERFACE WITH AVR:
RFID module works at RS232 logic levels hence ATmega32 is connected to RFID module by means of a level converter IC MAX232. The unique ID from the RFID tag is converted into serial mode by means of the reader module and then transmitted to controller via MAX232. The baud rate is set to 9600bps for data transmission. The code was written in such a way when a card/tag comes in the proximity of RFID reader, the microcontroller reads the code and sends it to the LCD module for displaying.
CODE:
#include<avr/io.h> #include<util/delay.h> #include<stdlib.h> #define ctrl PORTA #define en PA5 #define rw PA6 #define rs PA7 void lcd_cmd(unsigned char cmd); void init_lcd(void); void usartinit(); void lcd_write(unsigned char data); void lcd_write_string(); unsigned char a; unsigned char value[15]; unsigned int b; unsigned int k=0,i=0,j,l; unsigned char value1[]={"140071D1A612"}; //Unique ID unsigned char value2[]={"51005D6899FD"}; unsigned char value3[]={"MASTER"}; //Names assigned to ID unsigned char value4[]={"STUDENT"}; unsigned char value5[]={"Unknown number"}; int main () { DDRB=0xFF; DDRA=0xE0; init_lcd(); _delay_ms(50); lcd_write_string("Show your TAG"); usartinit(); while(1) { while((UCSRA)&(1<<RXC)) { value[i]=UDR; _delay_ms(1); i++; if(i==12) { value[i]=''; for(j=0;value1[j]!='';j++) { if(value[j]==value1[j]) k++; } if(k==12) //Checking the ID with predefined ID { lcd_cmd(0x01); lcd_cmd(0x80); for(l=0;value3[l]!='';l++) { a=value3[l]; //Assigning names lcd_write(a); _delay_ms(100); } i=0; k=0; } else { k=0; for(j=0;value2[j]!='';j++) { if(value[j]==value2[j]) k++; } if(k==12) { lcd_cmd(0x01); lcd_cmd(0x80); for(l=0;value4[l]!='';l++) { a=value4[l]; lcd_write(a); _delay_ms(100); } i=0; k=0; } else { lcd_cmd(0x01); lcd_cmd(0x80); for(l=0;value5[l]!='';l++) { a=value5[l]; lcd_write(a); _delay_ms(100); } } } } } } } void init_lcd (void) //LCD initialization { lcd_cmd(0x38); _delay_ms(1); lcd_cmd(0x38); _delay_ms(1); lcd_cmd(0x38); _delay_ms(1); lcd_cmd(0x38); _delay_ms(1); lcd_cmd(0x06); _delay_ms(1); lcd_cmd(0x0c); _delay_ms(1); lcd_cmd(0x01); _delay_ms(1); lcd_cmd(0x02); _delay_ms(1); return; } void lcd_cmd(unsigned char cmd) //LCD command subroutine { PORTB=cmd; ctrl=(0<<rs)|(0<<rw)|(1<<en); _delay_ms(1); ctrl=(0<<rs)|(0<<rw)|(0<<en); _delay_ms(50); return; } void lcd_write(unsigned char data) { PORTB=data; ctrl=(1<<rs)|(0<<rw)|(1<<en); _delay_ms(1); ctrl=(1<<rs)|(0<<rw)|(0<<en); _delay_ms(50); return; } void lcd_write_string(unsigned char *str) //LCD string write sub routine { int b=0; while(str[b]!='') { lcd_write(str[b]); b++; } return; } void usartinit() //USART initialization { UBRRH=00; UBRRL=77; UCSRB|=(1<<RXEN); UCSRC|=(1<<URSEL)|(1<<UCSZ0)|(1<<UCSZ1); }
NOTE:
- In the above code the unique ID’s are identified and some specific individual name was assigned to it for better understanding.
- If your RFID reader works with TTL logic you can eliminate the MAX232 IC in the schematic design.
what are the components inU2 and J2
Code is not works for atmeha32
Omedul,
May I know what problem you are facing ?
hey i have a AVR dragon wiht Atmega16 and also i Arduino RFID reader. can they both work in VR studio ? would i have to import Arduino libraries ?
need help asap!
Can you please list all the softwares required during this process…Please… Its Urgent.?
and I also want to display the result on my laptop too… so please suggest the software for that also.
Hi Gauravraj Sah,
I don’t think there is any software to run the simulation of this project. You should build one to showcase this as a project