Hello Readers, welcome to my Blog BloggerTipsTricks. com - A Blog For Bloggers By A Blogger. I'm Arun, an entrepreneur Blogger from India.

Analog IR Sensor Interfacing with ATmega16 and LED Display

11457
Mark as Favourite

The principle of operation of an infrared sensor is based on infrared light that is reflected when hitting an obstacle. An IR receiver (Photo Diode) captures the reflected light and the voltage are measured based on the amount of light received. Infrared sensors are used in a wide range of applications proximity detection, robotic applications for distance and object detection, and color detection and tracking. The output of the IR sensor can be digital or analog. Here, we will use an IR sensor with analog output.

In this project, we will learn How to interface an Analog IR Sensor with AVR ATmega16 microcontroller. Since, the output of the analog IR sensor is analog in nature and these analog signals cannot be processed directly by the ATmega16 microcontroller. So, first this signal needs to be converted to digital value to be processed by the microcontroller. The conversion can be done with the help of ADC of the AVR ATmega16 microcontroller. After converting the analog signal to digital, the microcontroller will display the digital value in the 1×8 LED array. But the LED array can display only 8-bit at a time. So, the 1×8 LED array will first display the lower 8-bit and then the upper 2-bit of the 10-bit digital output with a delay of 500ms. Now, we will place our hand or any other obstacle infront of the Analog IR Sensor and we will see the changes in the output of Analog IR Sensor in the LED array.

Softwares Required

Hardwares Required

Name / Unit Price Quantity Total Price
AVR Trainer Board-100 with ATmega16
Rs. 700.00
1pc
Rs.700.00
AVR USB Programmer
Rs. 350.00
1pc
Rs.350.00
12V, 1A DC SMPS Adaptor
Rs. 130.00
1pc
Rs.130.00
Analog IR Sensor
Rs. 30.00
1pc
Rs.30.00
1 to 1 Connector-Female to Female
Rs. 4.00
6pc
Rs.24.00
10 to 10 FRC Female to Female Connector
Rs. 15.00
2pc
Rs.30.00
TOTAL Rs.1264.00

Circuit Diagram

C Program

Fullscreen
 

 //**************************************************************//
//System Clock                          :1MHz
//Software                                 :AVR Studio 4
//**************************************************************//

#include<avr/io.h>
/*Includes io.h header file where all the Input/Output Registers and its Bits are defined for all AVR microcontrollers*/

#define          F_CPU          1000000
/*Defines a macro for the delay.h header file. F_CPU is the microcontroller frequency value for the delay.h header file. Default value of F_CPU in delay.h header file is 1000000(1MHz)*/

#include<util/delay.h>
/*Includes delay.h header file which defines two functions, _delay_ms (millisecond delay) and _delay_us (microsecond delay)*/

#include<avr/adc.h>
/*Includes adc.h header file which defines different functions for Analog to Digital Converter. ADC header file version is 1.1*/

int main(void)
{

DDRB=0xff;
/*All the 8 pins of PortB are declared output (LED array is connected)*/

int analog_ir_sensor_value;
/*Variable declarations*/

adc_init();
/*ADC initialization*/

/*Start of infinite loop*/
while(1)
{

analog_ir_sensor_value=read_adc_channel(0);
/*Reading analog ir sensor value*/

PORTB=analog_ir_sensor_value;
/*Lower 8 bit of analog ir sensor value is displayed in LED array*/

_delay_ms(500);
/*Value is displayed for 500ms*/

PORTB=analog_ir_sensor_value>>8;
/*Upper 2 bit of analog ir sensor value is displayed in LED array*/

_delay_ms(500);
/*Value is displayed for 500ms*/

}

}
/*End of Program*/

  

 //**************************************************************//
//System Clock                          :1MHz
//Software                                 :AVR Studio 4
//**************************************************************//

#include<avr/io.h>
/*Includes io.h header file where all the Input/Output Registers and its Bits are defined for all AVR microcontrollers*/

#define          F_CPU          1000000
/*Defines a macro for the delay.h header file. F_CPU is the microcontroller frequency value for the delay.h header file. Default value of F_CPU in delay.h header file is 1000000(1MHz)*/

#include<util/delay.h>
/*Includes delay.h header file which defines two functions, _delay_ms (millisecond delay) and _delay_us (microsecond delay)*/

#include<avr/adc.h>
/*Includes adc.h header file which defines different functions for Analog to Digital Converter. ADC header file version is 1.1*/

int main(void)
{

DDRB=0xff;
/*All the 8 pins of PortB are declared output (LED array is connected)*/

int analog_ir_sensor_value;
/*Variable declarations*/

adc_init();
/*ADC initialization*/

/*Start of infinite loop*/
while(1)
{

analog_ir_sensor_value=read_adc_channel(0);
/*Reading analog ir sensor value*/

PORTB=analog_ir_sensor_value;
/*Lower 8 bit of analog ir sensor value is displayed in LED array*/

_delay_ms(500);
/*Value is displayed for 500ms*/

PORTB=analog_ir_sensor_value>>8;
/*Upper 2 bit of analog ir sensor value is displayed in LED array*/

_delay_ms(500);
/*Value is displayed for 500ms*/

}

}
/*End of Program*/

Connection Guide

The step-by-step connection guide for Analog IR Sensor Interfacing with ATmega16 and LED Display is as follows:

  • Insert the DC Pin of 12V, 1A DC Adapter to the DC Socket of AVR Trainer Board-100.

    Steps - 1 ( 0f 8 )

  • Connect PortB header with LED header in AVR Trainer Board-100 with a 10 to 10 FRC Female Connector.

    Steps - 2 ( 0f 8 )

  • Connect the VCC, GND & O/P pins of Analog IR Sensor header to 5V, GND and PA0 pins of Port A header of AVR Trainer Board-100 respectively with 1 to 1 Connectors.

    Steps - 3 ( 0f 8 )

  • Connect the ISP header of AVR Trainer Board-100 with AVR USB Programmer header of AVR USB Programmer with a 10 to 10 FRC Female Connector.

    Steps - 4 ( 0f 8 )

  • Connect the AVR USB Programmer to the PC/Laptop's USB Port directly or with the help of USB AM-AF Cable.

    Steps - 5 ( 0f 8 )

  • Switch on the power with the help of Power Switch of AVR Trainer Board-100.

    Steps - 6 ( 0f 8 )

  • Download Analog IR Sensor Interfacing with ATmega16 and LED Display Hex file to AVR Trainer Board-100 with the help of SinaProg Hex downloader and AVR USB Programmer.

    Steps - 7 ( 0f 8 )

  • Move an obstacle to and fro in-front of the Analog IR Sensor and see the change in output.

    Steps - 8 ( 0f 8 )

  • Insert the DC Pin of 12V, 1A DC Adapter to the DC Socket of AVR Trainer Board-100.

    Steps - 1 ( 0f 8 )

  • Connect PortB header with LED header in AVR Trainer Board-100 with a 10 to 10 FRC Female Connector.

    Steps - 2 ( 0f 8 )

  • Connect the VCC, GND & O/P pins of Analog IR Sensor header to 5V, GND and PA0 pins of Port A header of AVR Trainer Board-100 respectively with 1 to 1 Connectors.

    Steps - 3 ( 0f 8 )

  • Connect the ISP header of AVR Trainer Board-100 with AVR USB Programmer header of AVR USB Programmer with a 10 to 10 FRC Female Connector.

    Steps - 4 ( 0f 8 )

  • Connect the AVR USB Programmer to the PC/Laptop's USB Port directly or with the help of USB AM-AF Cable.

    Steps - 5 ( 0f 8 )

  • Switch on the power with the help of Power Switch of AVR Trainer Board-100.

    Steps - 6 ( 0f 8 )

  • Download Analog IR Sensor Interfacing with ATmega16 and LED Display Hex file to AVR Trainer Board-100 with the help of SinaProg Hex downloader and AVR USB Programmer.

    Steps - 7 ( 0f 8 )

  • Move an obstacle to and fro in-front of the Analog IR Sensor and see the change in output.

    Steps - 8 ( 0f 8 )

Downloads

Analog IR Sensor Interfacing with ATmega16 and LED Display C File
  • 46 downloads
  • 2 Kb
Analog IR Sensor Interfacing with ATmega16 and LED Display Circuit Diagram
  • 49 downloads
  • 161 Kb
Analog IR Sensor Interfacing with ATmega16 and LED Display Hex File
  • 28 downloads
  • 1 Kb
ADC Header File v1.0
  • 732 downloads
  • 2 Kb

Comments