Atmega32 www.ir-micro.com
Dec 27, 2015
���������� �
�� ��������������������������� �
Atmega32
� �
www.ir-micro.com ��������
���������Atmega32 �8-bit Microcontroller MegaAVR Series��
With 32K Bytes In-System Programmable Flash�
8-channel, 10-bit ADC 32 x 8 General Purpose Working
Registers
Power Consumption at 1 MHz, 3V, 25°C 4.5 - 5.5V for
ATmega3��
Six Sleep Modes: Idle, ADC Noise Reduction, Power-save,
Power-down, Standby�and Extended Standby
40-pin PDIP, 44-lead TQFP, and 44-pad MLF
Figure 0
MQ-2 Type Sensor in air quality control-HanWei
17 Semiconductor Type Gas Sensor
Target gas: smoke, hydrogen, NH3, propane, ammoniac, etc.
Standard circuit conditions:
Heater voltage: 5V DC/AC
Circuit voltage: 3~15V DC
Heater power consumption: 750 mW
Temperature range: -20deg. C to +40 deg. C
Size: Diameter19mm×High17mm�Figure 1
Paradox ��� PA-476�Improved Auto Pulse Signal Processing
Detecteur DE Mouvement Analogue Avance
& Advanced Analog Motion Detecto
� �
� �
Figure 2 This is Improve Circuit of End Product Example
Anti Fire and Squrity System
For Home Situate or Other Simple Place!
By Buzzer or Multisonous Output
Micro Resolution Power in Multifarious Sensor's
Signal Processing
Figure 3
� ��!�"� �����#�$����%�&'��� �
������������� PORT 4 � ��������������� � A,B,C,D ��������� ��������
�������� PIN 8 ������ �� !"#$%�&'�
� ���� �� �� (��)������ �������� �
����*+�, ����-����.���� �/�0� 1�
�-�� ����2�� �3��4� � �����5�678
�0� 1����$������-� A ������9����.���
���.������� �����, ��/ PIN A.3 �
PORT A.3 �0� 1������������:;���$�
���&���. �������-���<=��0�>��? ������
*+�0� 1����������������@A
1� ������B������� �78��4� PORTA ���.��� PA � PORTB �� ���.PB ��C���
��<=��0������*+�, �����.��1�������� �������� I�����?�1D A �:.�� �����4=���
������VCC ��/�E����� ������� ��F�G4��������� �H4���*I��������� �����J��<;�
�+� ��GK�+���*I��L�4�-�����0����;������ ����� �E���-�����G���'A3�� �JAJ��������
����0� MG=����� GND ��/1���� ����� �N1=��-�������B��<=������� �� M4��=������ �
�:.����*I��L�4��-����
RESET �/����������� ����� RESET � ������������� �+��������������� GND
��F�.�� ����� RESET 0����� 44��:.���-��=����O��=�����P�� ��?�1D��
�0����0 ����F Q���P�������
XTAL1 ��/ �F G����� �����7=���0�44��<�����P���������� �������� �.
XTAL2 ��/1�� (��) �0�44��<���������� �
AVCC ��/������ ���� A ��������� ADC=(Analog to Digital Converter) 1�� � ��
�F GR������S�; ���:�����:)����������4� � �<=��0����- =� (��������������1�
�����E����� �������� A � ���� 1������� ������4� �E����J�����:.��0����;�+��<;���
(�')*�$+����� �� �
��������/������������ ���� ��:����� �� ���-����.��������0����0�T�����-��0U���������Figure 4
��
��
������ �?�VB���<V� W�� VX�������YVZ[�� V�����4=�\������
��4G��A���E��VGX��-����+�Z(�������4� ���������]K >���������� �0�� �������H� 1�
�� �� ������� ��A4����� ���� D=�� � = 4��0���>��4^1������V4������V_�\ DV��<>���
A���������V� �� V� GD4V.� V��\�V���V��- V������� �- +�<��� � = 4��������4=�\����������� �
���^1�� � �- +� � = 4����������4=�\�������-��0� MG=���4^1�LPG�`��� ���`��� ����`�
�� G`����U�������H41��<=��0���L_����(����������A������V�� � GV=�����V�DataSheet�
�<� =���������� ����4=����www.hwsensor.com��4���D(���A����<V�� VG����V���(��� �
�� ���� ��<Da����(�MQ2���� �� ���-����.���� (��)�����A�����������������������������������������������������Figure 5��
��b���� ����� G=� ���
�,- ��(�')*�$+����� �
������0����c �X��NG; DK��������������K��<��X���� 1�d����4=� ��<��X�- =�� ���
�� 1�� �e� )�������� ��� �f������� ����P� ���� ��B. ���4= PIR ���(������
�� ������X��������� ��>GA �� ���N4�������A� ��� ���������� �g�>G���(����
�� �����X� A������? ����� ���e�(�h�����;�P����������<�������������� � 1�� GX
����e� )���������� ����0����<��X����4= LED �� ��������������GK��� ����A���
� ( LED ������ �9� (Buzzer) ���4��0� MG=�A� MG=�����.���� (�����9��-��0 LED
����e� )��������� (��� LED �����)����E������.�g�>G���(�<��X����.���
�4�.�Figure 6
��-���4�� �i� �� 1�(������� ��� Q5� � ��0���>��-�&2`�
� �32�j��*I�U G;��0���>����J�� �k'�<;�����������������-
�lXmJ�����(����A �������K����n����4=��������0� =��� �i���
�������������� �K��4��<��X�e��������-�A�F 8����4i���
�� ����� =�� �� T� 1G) =����������AAAA� ����������- �� �����K���
��o� )�������-����K���� ���4�� ������������������, 1����0����:1i����4=���������G�
���.��
��VVVV����VVVV8�����: VVVV����- VVVV�������VVVV(��� VVVV�� 1VVVV�d&���4GVVVV����VVVV=�o�-
����?�1D����<�����*I�������F���o�-m�� �k'�<���<;�A��
, ������=�o�-�P� Tamper ��(���<�����������V=����-��LV_���������PV�����VC���Op�V=��
�� 1�d�h��� 1���+�� ;��<����G����� i�<; X����Op�=�������0����GK�+������V�������
��- �����Op�=������4��- ��������A������L_������� �� 1�d������G���<4�P���Op�V=
����� �������D������h�������- �� ������- �����Op�=����� 1�d���A�V��<���,�=���
Op�=���<��X�q5������r����Op�= Tamper ���44�� ���=������Vi�1R��V���ls=��
�������9VV���0 CGVV=��� VVT��-�-�� VV����VV������VV4�� VV�:VVQG��VV+��-���GVV�=�PVV������
Op�=���� 1���G�;� Tamper �������- ���
�P���=�o�-9�������V=����-���V=�o�-��V������r�����=�������<���<��X�q5�������
P��+�Op�=�0����GK��A�� G��X����4=�� ��������� �q5���A���Op�V=������V4�� V�- V���
��� � 1����G��9�����P��P1��������2N3904 �� �BC337����- V�� GX���!2�%����V���GV�����
!k%���<���<��X�q5��� ��t���G����Op�=���������2�� �J�������<;���:��V�������-
��4�����������P������������s���A��������)���-����.����������A����
Figure 7��
��
��
��. *� ! /� 0� �
-�� =�������������,��+�������� PIN � � MISO - MOSI - SCK - RESET - ��
GND - VCC ����� �0� MG=�.��4�� �0�� ����-������� ���.����A�� = PIN ��� �
������ Td������ A - D - C - B T���-�� (��)����4i��������� ����n����� �����
����0� MG=�� T���-�����������4i��������� ����������0� MG=�!A� ������� CG�� ���l������%��
��Figure 10��
����� �
NOTE: should you do parallel R1 and connected to the between micro vcc pin
and buffer vcc Pin
1
14
2
15
3
16
4
17
5
18
6
19
7
20
8
21
9
22
10
23
11
24
12
25
13
J3
CONN-D25M
PA0/ADC040
PA1/ADC139
PA2/ADC238
PA3/ADC337
PA4/ADC436
PA5/ADC535
PA6/ADC634
PB0/XCK/T01
PB1/T12
PB2/INT2/AIN03
PB3/OC0/AIN14
PB4/SS5
PB5/MOSI6
PB6/MISO7
PB7/SCK8
PA7/ADC733
RESET9
XTAL113
XTAL212
PC0/SCL22
PC1/SDA23
PC2/TCK24
PC3/TMS25
PC4/TDO26
PC5/TDI27
PC6/TOSC128
PC7/TOSC229
PD0/RXD14
PD1/TXD15
PD2/INT016
PD3/INT117
PD4/OC1B18
PD5/OC1A19
PD6/ICP20
PD7/OC221
AVCC30
AREF32
U1
ATMEGA32
A02
B018
A13
B117
A24
B216
A35
B315
A46
B414
A57
B513
A68
B612
A79
B711
CE19
AB/BA1
U2
74HC244
Vc
c 5
NOTE:should you do parallel R1 and connected to the bitween micro vcc pin and buffer vcc
Vcc
GND
GND
VCC
R1 100 K100k
20
10
11
10
Figure 11,12��
� �
���111111111111111111111111112!�- Bascom
�Z� s ������ =��������� ��Z� s �����GK��D�-�� ���� ��AVR�����������<V=��A���V ���
� �-���� Z)��Z� s ������ ����� Basic�������<V=��PV��9�����V8��
����G=��Basic��0� MG=������������� �������A� � ������ �������
=��������V+�����V� �� �������������G=����Y; _��f��-�� 1��� ���
�4��0 �G���� ������� 1���� ���� G�������� 1��0 �G����Z� s �����
�VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV����
������ 1��� ����n� ��������� �-����Basic����.����<=��HEX�
��TK�:� _� =��������� ������� ������ ����
��=�� �� =���� 1�������,�+����<Z� _�� ��������AVR�
����������� ����
��=������� ���������G�;��AVR�, �����Bascom-AVR������V���
���=�����, �����Bascom-8051���:.�������<=��0�����G4�������������� Figure 8��� �
=��������� 1��AVR�� ����P��-���� ����4��0� MG=����=�� �� =����������������-�
�C������ ������Figure 9��
��
�� ��!��!�� ��� ��regfile = "m32def.dat"
�crystal = 1000000
Config Portd = Output
Config Adc = Single , Prescaler = Auto , Reference = Avcc
Dim W As Word
Dim M As Word
Declare Sub Gas(byval W As Word )
Declare Sub Motion(byval M As Word )
Start Adc
��Do
���W = Getadc(0)
���Call Gas(w)
���M = Getadc(1)
Call Motion(m)
���Set Portd.5
���Waitms 500
���Reset Portd.5
���Waitms 600
�Loop
End
Sub Motion(m As Word )
�If M > 600 Then
�����Set Portd.6
����� Waitms 200
�����Reset Portd.6
�Else
�����Reset Portd.6
�End If
End Sub
Sub Gas(w As Word )
If W > 300 Then
�����Set Portd.6
Wait 3
���Else
�����Reset Portd.6
���End If
End Sub
���3��$ �!�� �
�F Q��� ����)��������0����9���� ������������*C� (���E�K�:X���, R���-��l�k'��<;�
�����_����� 1�d�- �����������J��<;����(��0� ���G�=�����- ��������� ����D�
���������)�0��A��
��
Figure 13,14��
��