Hello everyone,

I’m glad to take you through the procedure involved in interfacing an LDR sensor with ATmega 16/32 microcontroller board. LDR sensor can be bought from our online store by clicking here

Hardware Prerequisites:-

  • ATmega 16/32 board.
  • LDR sensor: You can avail this module easily from our online store
  • AVR USB programmer:-USBasp. This is also available in our online store by clicking here
  • CP2102:-USB to TTL serial converter. Avail this from our online store
  • Jumper Wires for making connections.

Software Prerequisites:-

  • AVR studio for coding and compiling
  • AVRdude for burning/uploading hexcode
  • PuTTy:- A terminal software.

ATMEGA 16

FEATURES

  • ATmega16 is an 8-bit high performance microcontroller from the Atmel’s Mega AVR family.
  • Atmega16 is a 40 pin microcontroller based on enhanced RISC architecture with 131 powerful instructions.
  • It has a 16 KB programmable flash memory, static RAM of 1 KB and EEPROM of 512 Bytes.
  • Most of the instructions execute in one machine cycle.
  • It can work on a maximum frequency of 16MHz.

LDR SENSOR

Procedure:

STEP 1:

 

Make clean connections for ldr sensor with ATmega 16/32 board by following these pin inter-connections.

LDR SENSOR PINS ATMEGA 16/32 PINS
V 5V
A0  keep open
D0  PA7
GND GND

            

Connect led array to PORTB of microcontroller board. Connect its common pin to ground.

Also connect CP2102 to ATmega 16/32 microcontroller board as depicted in table below.

CP2102 pins ATmega 16/32 pins
TXD RXD
RXD TXD
GND GND
5V 5V

 

Below figure shows the hardware connection

STEP 2:

Open AVR studio. Copy the program source code along with its attachment libraries and headers. Build the main program source code in AVR studio.

To set board and frequency go to Project>Configuration options in AVR studio. Select device as ATmega16 and set Frequency as 8000000 Hz

STEP 3:

Connect USBasp USB programmer to ATmega 16 board. Open AVRdude software.

In configuration settings, select ATmega 16 as microcontroller.

STEP 4:

In memories, browse for hexcode generated for the main source code.


STEP 5:

Also, check if the write button is ticked. If not ,tick it. After uploading hexcode. Press execute to burn the code into ATmega 16 board.


If everything is uploaded perfectly, then if  ldr detects darkness, then the led array turns ON.

//Program Code

You can see the sample code by clicking here.Open atmega16 folder->open pir folder-> attach all the libraries to the AVR Studio,upload it to the board.