You are on page 1of 50

TABLE OF CONTENTS

FIGURES.......................................................................................................................iii
LIST OF ABBREVIATIONS.......................................................................................iv
CHAP 1: TOPIC OVERVIEW.....................................................................................1
1.1 Purpose of implementing the topic........................................................................1
1.2 Topic requirements.................................................................................................2
1.3 Research subjects...................................................................................................2
1.4 Implementation ideas.............................................................................................2
1.5 Expected results.....................................................................................................3
CHAP 2: THEORETICAL BASIS...............................................................................4
2.1 PIC mirocontroller.................................................................................................4
2.2 Rain sensor.............................................................................................................6
2.3 Motor......................................................................................................................7
CHAP 3: DESIGN AND CONSTRUCTION OF MODELS......................................8
3.1 Block diagram........................................................................................................8
3.1.1 Source block....................................................................................................9
3.1.2 Sensor block..................................................................................................10
3.1.4 Motor block...................................................................................................14
3.1.5 Display block................................................................................................19
3.2 Designed on Proteus simulation software............................................................22
3.3 Model design........................................................................................................24
CHAP 4: ALGORITHM AND CONTROL...............................................................27
4.1 Operating system..................................................................................................27
4.2 Algorithmic flow chart.........................................................................................27
CHAP 5: PRACTICE..................................................................................................28
5.1 Experimental process...........................................................................................28

1
5.2 Results..................................................................................................................28
5.3 Conclusion...........................................................................................................30
CHAP 6: CONCLUSIONS..........................................................................................31
6.1 Advantages...........................................................................................................31
6.2 Disadvantages......................................................................................................31
6.3 Development........................................................................................................31
REFERENCES.............................................................................................................32
CODE............................................................................................................................33

2
FIGURES
Figure 1.1 Drying rice paper............................................................................................1
Figure 1.2 Clothesline......................................................................................................1
Figure 2.1 Microcontroller (PIC16F877A) [Nagar, J. (2019, May 31)]..........................4
Figure 2.2 PIC 16F877A pins [Nagar, J. (2019, May 31)]...............................................5
Figure 2.3 Rain sensor.....................................................................................................6
Figure 2.4 IC L293D........................................................................................................7
Figure 3.1 Block diagram.................................................................................................8
Figure 3.2 Components in the block................................................................................9
Figure 3.3 DC adapter....................................................................................................10
Figure 3.4 Rain sensor....................................................................................................11
Figure 3.5 PIC 16F877A................................................................................................13
Figure 3.6 PIC 16F877A pins........................................................................................13
Figure 3.7 GA12-N20....................................................................................................15
Figure 3.8 IC L293D......................................................................................................16
Figure 3.9 L293D pins...................................................................................................17
Figure 3.10 Schematic diagram of L293D.....................................................................17
Figure 3.11 LCD 1602...................................................................................................20
Figure 3.12 Presents the simulation steps on Proteus8.13.............................................22
Figure 3.13 Layout of the diagram shows the system's wiring......................................23
Figure 3.14 Present 3D perspective...............................................................................23
Figure 3.15 Printed circuit processing...........................................................................24
Figure 3.16 PCB (behind side).......................................................................................24
Figure 3.17 PCB (infront of side)..................................................................................25
Figure 3.18 PCB (infront of side)..................................................................................25
Figure 3.19 The model is nearly complete.....................................................................26
Figure 3.20 Completed model........................................................................................26
Figure 4.1 Algorithmic flow chart..................................................................................27
Figure 5.1 Door closes when rainfall >40%..................................................................29
Figure 5.2 Operates in manual mode.............................................................................29
Figure 5.3 Door opens when power is applied...............................................................30

3
LIST OF ABBREVIATIONS
AC Alternating Current

ADC Analog-to-Digital Converter

DC Direct Current

IC Intergrated Circuit

LCD Liquid Crystal Display

PCB Printed Circuit Board

PIC Programmable Intelligent Computer

4
EMBEDED SYSTEM PROJECT
Page 1

CHAP 1: TOPIC OVERVIEW


1.1 Purpose of implementing the topic
Nowadays, many households have traditional occupations that work with
products that require sunlight and avoid exposure to rainwater. Or family members are
busy with work and don't pay attention to the weather, leading to drying clothes outside
and getting wet in the rain. Therefore, based on the above situation, design a drying
rack system that automatically opens/closes when it rains.

Figure 1.1 Drying rice paper

A Rain-Detecting Circuit
For Door Opening And Closing
EMBEDED SYSTEM PROJECT
Page 2

Figure 1.2 Clothesline

1.2 Topic requirements


Design a model capable of detecting rain or snow and then display the amount of rain
on the screen. If the amount of rain exceeds the allowed level, the door will
automatically close (open). The system has the ability to adjust between two modes:
automatic or manual.

1.3 Research subjects


The microcontroller has the function of reading the sensor and processing it to display
it on the screen and then control the motor to close or open the door according to the
request.

The rain sensor detects rain or snow falling on the sensor board and then sends a signal
to the microcontroller for processing.

The LCD screen has the function of displaying the amount of rain after the
microcontroller processes the rain sensor and the system's operating mode.

The motor has the function of receiving control signals from the microcontroller and
then operating.

1.4 Implementation ideas


Components include PIC 16F877A, rain sensor, LCD 1602, IC L293D, DC gear
motor. Use the rain sensor to measure then display the rain percentage on the LCD then
set a certain rain level to control the rotary motor to close the door when it is equal to
or greater than the set rain percentage. The system has two modes: automatic or
manual. In manual mode, if you want to control the opening and closing of the door,
use the button.

A Rain-Detecting Circuit
For Door Opening And Closing
EMBEDED SYSTEM PROJECT
Page 3

1.5 Expected results


When it rains, the percentage of rain will be displayed on the LCD. If the rain
amount is more than 40%, the door will automatically close in 6 seconds or if less, the
door will automatically open. We can use the push button to open/close the door when
needed.

A Rain-Detecting Circuit
For Door Opening And Closing
EMBEDED SYSTEM PROJECT
Page 4

CHAP 2: THEORETICAL BASIS


2.1 PIC mirocontroller
PIC is the abbreviation for Programmable Intelligence Computer and is a type
of microcontroller manufactured by Microchip Technology company (Figure 2.1
introduce about PIC 16F877A). Nowadays, PICs are developed strongly and widely
because they have many functions integrated into them. PICs are very popular with
users because they are very flexible and can perform user-programmed tasks, helping
to save costs and work efficiently.

Figure 2.3 Microcontroller (PIC16F877A) [Nagar, J. (2019, May 31)]

A Rain-Detecting Circuit
For Door Opening And Closing
EMBEDED SYSTEM PROJECT
Page 5

Figure 2.4 PIC 16F877A pins [Nagar, J. (2019, May 31)]

PIC application:

 It is commonly used in medical devices for health measurement, data reading,


display and operation.
 Microcontrollers are installed in automobile control devices such as starting
control systems, engines, and safety for users.
 In agriculture, microcontrollers are used in devices that measure humidity, water
quantity, and temperature for farming systems.
 It is installed in smart homes to control the home's lighting, temperature, and
security system. [Dũng, T. N. (2023)]
 Therefore, microcontrollers are crucial to the operation of many systems
and devices in the current world. PIC is a frequently used device with a lot of
potential for the future. It is small, easy to use, and packed with useful functionality.

A Rain-Detecting Circuit
For Door Opening And Closing
EMBEDED SYSTEM PROJECT
Page 6

2.2 Rain sensor


When the weather is rainy and sudden, if you do not have time to bring the
items into the house or if the items are drying outside have not yet been brought in, the
rain will get wet, affecting the quality of the product, causing a loss in price. treat. treat.
However, the rain sensor will signal to help us in those cases.

Rain sensors (Figure 2.3) are widely used to warn of rain or snowfall and will
send an alert to the tracking device to request the door to be closed or opened. They are
most commonly used in automatic drying racks.

Figure 2.5 Rain sensor

Rain sensor uses in real life:

 In agricultural activities, rain sensors help save water when detecting rainy
weather to save irrigation water costs.
 Installed in the car's wiper system, it detects the amount of water and then the
system wipes the windshield to help the driver's visibility not be affected.

A Rain-Detecting Circuit
For Door Opening And Closing
EMBEDED SYSTEM PROJECT
Page 7

 In the internal skylight system, rain sensors are incorporated. Knowing the
weather allows the house to remain airy during sunny days and damp during
rainy ones.
 Smart clothes drying racks can collect clothes when it rains to prevent clothes
from getting wet.

[Brindley, K. (2011)]

2.3 Motor
All DC and AC motors can rotate in both directions. However, today DC motors
are more widely used and popular due to their high efficiency. IC l293D ( Figure 2.4)
has been invented with the ability to rotate in two directions in a simple way. Besides,
other functions can operate quickly used in robots, cars, etc…

Figure 2.6 IC L293D

A Rain-Detecting Circuit
For Door Opening And Closing
EMBEDED SYSTEM PROJECT
Page 8

CHAP 3: DESIGN AND CONSTRUCTION OF MODELS


3.1 Block diagram
The block diagram (Figure 3.1) briefly shows how the system works of rain-
detecting circuit for door opening and closing.

Sensor Block

Source Block Control Block Motor Block

Display Block

Figure 3.7 Block diagram

The power block supplies power to the three sensor, control and display blocks.
The sensor block will receive signals from the outside and then send them to the
control block. The control block processes information and controls the operation of
the motor block and display block.

A Rain-Detecting Circuit
For Door Opening And Closing
EMBEDED SYSTEM PROJECT
Page 9

Figure 3.8 Components in the block

3.1.1 Source block


Requires power supply for the system to operate during implementation.

Recommended: 5V 2A power adapter.

Specifications:

Input: 100-240VAC ~ 0.5A 50/60Hz

Output: DC 5V 2A

A Rain-Detecting Circuit
For Door Opening And Closing
EMBEDED SYSTEM PROJECT
Page 10

Figure 3.9 DC adapter

3.1.2 Sensor block


The rain sensor is responsible for detecting rain or snowfall, which can come
into contact with water. They are often placed outdoors such as roofs.

Recommended: Rain sensor.

The rain sensor consists of two parts:

 Sensing pad: It is placed outdoors such as the roof, and is responsible for
detecting rain when water falls on the Sensing pad.
 The electronic module includes four pins:
- VCC: connected to power. (5V)
- GND: connected to ground. (0V)

A Rain-Detecting Circuit
For Door Opening And Closing
EMBEDED SYSTEM PROJECT
Page 11

- A0: output is analog signal.


- D0: output is digital signal.

Specifications:

Voltage used: 5VDC

Size of rain sensor plate: 54 x 40mm

PCB board size: 30 x 16mm

LED lights up when there is no rain, high output, when there is rain, low output LED
turns off.

Figure 3.10 Rain sensor

A Rain-Detecting Circuit
For Door Opening And Closing
EMBEDED SYSTEM PROJECT
Page 12

3.1.3 Control block

The task is to receive signals from the sensor when powered and control the
motor based on the sensor signal.

Recommended: PIC 16F877A

Specifications:

CPU 8-bit PIC


Number of pins 40
Operating voltage 2 to 5.5V
Number of I/O pins 35
Module ADC 14 channels, 10bit
Timer module 8-bit, 16-bit
Comparator 2
Communication Peripherals UART, SPI, I2C, MSSP(SPI/I2C)
External oscillation Up to 20MHz
Internal Oscillation 8MHz to 32MHz
Bytes of RAM 368
EEPROM data 265
[Nagar, J. (2019, May 31)]

A Rain-Detecting Circuit
For Door Opening And Closing
EMBEDED SYSTEM PROJECT
Page 13

Figure 3.11 PIC 16F877A

Figure 3.12 PIC 16F877A pins

A Rain-Detecting Circuit
For Door Opening And Closing
EMBEDED SYSTEM PROJECT
Page 14

3.1.4 Motor block


The main task is to perform the actions set by the control block.

Recommended: DC gear motor GA12-N20

Specifications:

Gear ratio: 1:97.

Voltage used: 1.5 ~ 12VDC

Motor diameter: 12mm.

Motor length: 34mm.

Shaft diameter: 3mm (D-shaped shaft).

Shaft length: 10mm

Speed through gearbox: 96rpm ~ 241rpm.

[Lowe, D. (2022)]

A Rain-Detecting Circuit
For Door Opening And Closing
EMBEDED SYSTEM PROJECT
Page 15

Figure 3.13 GA12-N20

Use IC L293D to control the motor:

Using this L293D motor driver IC is very simple. The IC works on the principle
of Half H-Bridge, let's not go too deep into what H-Bridge means, just know that H
Bridge is a setup used to run the motor both in clockwise direction clockwise and
counterclockwise. As said earlier, this IC is capable of running two motors in any
direction at the same time, the circuit to do this is as below.

A Rain-Detecting Circuit
For Door Opening And Closing
EMBEDED SYSTEM PROJECT
Page 16

Figure 3.14 IC L293D

Specifications:

Can control speed and direction

Motor voltage Vcc2 (Vs): 4.5V to 36V

Maximum peak motor current: 1.2A

Maximum continuous motor current: 600mA

Supply voltage for Vcc1 (vss): 4.5V to 7V

Transition time: 300ns (at 5V and 24V) [7]

A Rain-Detecting Circuit
For Door Opening And Closing
EMBEDED SYSTEM PROJECT
Page 17

Figure 3.15 L293D pins

Figure 3.16 Schematic diagram of L293D

A Rain-Detecting Circuit
For Door Opening And Closing
EMBEDED SYSTEM PROJECT
Page 18

Input 1 Directly control Output 1 pin. Controlled by digital circuit


Output 1 Directly controls Output pin 1. Controlled by digital circuit Connected to
one end of motor 1
Ground The ground pin is connected to ground of the circuit (0V).
Ground The ground pin is connected to ground of the circuit (0V).
Output 2 Connected to another end of motor 1
Input 2 Direct control of Output pin 2. Controlled by digital circuit
Vcc2 (Vs) Connect to voltage pin to run motor (4.5V to 36V)
Enable This pin turns on input pins Input 3 (10) and Input 4 (15).
3,4
Input 3 Direct control of Output pin 3. Controlled by digital circuit
Output 3 Connected to one end of motor 2
Ground The ground pin is connected to ground of the circuit (0V).
Ground The ground pin is connected to ground of the circuit (0V).
Output 4 Connected to another end of motor 2
Input 4 Directly controls Output pin 4. Controlled by digital circuit
Vcc2 Connect to +5V to enable IC function
(Vss)
[Lowe, D. (2022)]

A Rain-Detecting Circuit
For Door Opening And Closing
EMBEDED SYSTEM PROJECT
Page 19

3.1.5 Display block


This is where rainfall percentage information is displayed and whether the
system operates automatically or manually.

Recommended: LCD 1602

Specifications:

MAX voltage: 7V

MIN voltage: - 0.3V

Stable operation: 2.7-5.5V

High output voltage: > 2.4

Low output voltage: <0.4V

Power supply current: 350uA - 600uA

Operating temperature: - 30 - 75 degrees Celsius

A Rain-Detecting Circuit
For Door Opening And Closing
EMBEDED SYSTEM PROJECT
Page 20

Figure 3.17 LCD 1602

Function of each LCD 1602 pin:

 Pin number 1 – VSS: LCD ground pin.


 Pin number 2 - VDD: power supply pin for LCD, connected to VCC=5V of the
control circuit.
 Pin number 3 - VE: adjusts the contrast of the LCD.
- Digital pin 4 - RS: register select pin, connected to logic "0" or logic "1":

+Logic “0”: Bus DB0 - DB7 will connect to the LCD's IR command register (in
"write" mode) or connect to the LCD's address counter (in "read" mode).

A Rain-Detecting Circuit
For Door Opening And Closing
EMBEDED SYSTEM PROJECT
Page 21

+Logic “1”: Bus DB0 - DB7 will connect to the DR data register inside the
LCD.

 Pin number 5 - R/W: read/write mode selection pin (Read/Write), connected to


logic "0" to write or connected to logic "1" to read.
 Pin number 6 - E: enable pin (Enable). After signals are placed on the DB0-DB7
bus, commands are only accepted when there is an enable pulse of this pin as
follows:

+ In write mode: Data on the bus will be transferred to the internal register by
the LCD when detecting a pulse (high-to-low transition) of the E pin signal.

+ In read mode: Data will be output to DB0-DB7 by LCD when detecting a


rising edge (low-to-high transition) at pin E and kept by LCD on the bus until
pin E goes low.

 Pins 7 to 14 - D0 to D7: 8 lines of the data bus used to exchange information


with the MPU. There are 2 modes using these 8 bus lines: 8-bit mode (data is
transmitted on all 8 lines, with the MSB bit being bit DB7) and 4-bit mode (data
is transmitted on 4 lines from DB4 to DB7 , MSB bit is DB7).
 Pin 15 - A: positive source for backlight.
 Digital pin 16 - K: negative source for backlight.

A Rain-Detecting Circuit
For Door Opening And Closing
EMBEDED SYSTEM PROJECT
Page 22

3.2 Designed on Proteus simulation software


Draw and simulate the system on Proteus software:

Figure 3.18 Presents the simulation steps on Proteus8.13

A Rain-Detecting Circuit
For Door Opening And Closing
EMBEDED SYSTEM PROJECT
Page 23

Layout on Proteus: simulate the lines connecting components

Figure 3.19 Layout of the diagram shows the system's wiring

3D simulation of the implemented model

Figure 3.20 Present 3D perspective

A Rain-Detecting Circuit
For Door Opening And Closing
EMBEDED SYSTEM PROJECT
Page 24

3.3 Model design


Circuit model: front and back of printed circuit board

Figure 3.21 Printed circuit processing

A Rain-Detecting Circuit
For Door Opening And Closing
EMBEDED SYSTEM PROJECT
Page 25

Figure 3.22 PCB (behind side)

Solder components onto hard circuits

A Rain-Detecting Circuit
For Door Opening And Closing
EMBEDED SYSTEM PROJECT
Page 26

Figure 3.23 PCB (infront of side)

A Rain-Detecting Circuit
For Door Opening And Closing
EMBEDED SYSTEM PROJECT
Page 27

Figure 3.24 PCB (infront of side)

Nearly complete model including all components

A Rain-Detecting Circuit
For Door Opening And Closing
EMBEDED SYSTEM PROJECT
Page 28

Figure 3.25 The model is nearly complete

Full model of all components and parts to complete:

A Rain-Detecting Circuit
For Door Opening And Closing
EMBEDED SYSTEM PROJECT
Page 29

Figure 3.26 Completed model

A Rain-Detecting Circuit
For Door Opening And Closing
EMBEDED SYSTEM PROJECT
Page 30

CHAP 4: ALGORITHM AND CONTROL


4.1 Operating system
After powering the system, the LCD screen displays the amount of rain based
on the sensor and the system is operating in automatic mode. Currently the door will
open (for 6 seconds) because there is no rain on the sensor. After the sensor is exposed
to an amount of water greater than 40%, the door will close until it touches the travel
sensor. If you want to change the operating state of the system, you can use the push
button to switch from automatic state to manual operation.

4.2 Algorithmic flow chart


Present how the system works using an algorithm flow chart

A Rain-Detecting Circuit
For Door Opening And Closing
EMBEDED SYSTEM PROJECT
Page 31

Figure 4.27 Algorithmic flow chart

CHAP 5: PRACTICE
5.1 Experimental process
Step 1: Supply 5V power to the system.

Step 2: The door will open because the rain sensor has not been supplied with water.
After providing a certain amount of water to the rain sensor, it will display on the LCD
if the rain amount is greater than 40%, the door will close.

Step 3: Dry the water on the door sensor that will open.

Step 4: Change the system's operating status with a button.

Step 5: Turn off the power to turn off the system.

5.2 Results
 Door opening time is 1 second faster than expected.
 The engine speed is stable.
 Rainfall for opening and closing is in line with the set target.
 In manual mode, stable operation.

A Rain-Detecting Circuit
For Door Opening And Closing
EMBEDED SYSTEM PROJECT
Page 32

The system works when it rains:

Figure 5.28 Door closes when rainfall >40%

Manual operating status:

A Rain-Detecting Circuit
For Door Opening And Closing
EMBEDED SYSTEM PROJECT
Page 33

Figure 5.29 Operates in manual mode

Power supply for the operating system:

A Rain-Detecting Circuit
For Door Opening And Closing
EMBEDED SYSTEM PROJECT
Page 34

Figure 5.30 Door opens when power is applied

5.3 Conclusion
The system operates stably and quickly. However, the door opening time is
faster than the target, so the door opening and closing time should be improved to
increase the efficiency of the system.

A Rain-Detecting Circuit
For Door Opening And Closing
EMBEDED SYSTEM PROJECT
Page 35

CHAP 6: CONCLUSIONS
6.1 Advantages
 Cheap price, easy installation.
 The system is simple and easy to access and use.
 The rain sensor returns the value to the LCD quickly.

6.2 Disadvantages
 Opening and closing times are slow.
 If the rainfall is not greater than 40%, the door will still be open, affecting users.

6.3 Development
 The application adds a remote monitoring and control program on the phone
using wifi so users can control at a distance.

A Rain-Detecting Circuit
For Door Opening And Closing
EMBEDED SYSTEM PROJECT
Page 36

REFERENCES
Anh, T. T. (2018). Giáo Trình Vi Điều Khiển PIC Lý Thuyết Và Thực Hành. Hồ Chí
Minh: Hồng Ân.
Brindley, K. (2011). Starting Electronics. Oxford: Elsevier Science & Technology.
Dũng, T. N. (2023). IoT internet vạn vật - Kiến trúc IoT, IoT công nghiệp và công
nghiệp 4.0, IoT tổ ong. Hà Nội: NXB Thông tin và Truyền thông.
Karpan, A. (2021). The Internet of Things. New York: Greenhaven Publishing LLC.
Lowe, D. (2022). Electronics All-in-One For Dummies 3rd Edition. New York: John
Wiley & Sons Inc.
Nagar, J. (2019, May 31). Components 101. Retrieved from
https://components101.com/microcontrollers/pic16f887-microcontroller
ROBOTICS, C. T. (2020, January 22). Robocon. Retrieved from
https://robocon.vn/detail/ic55-ic-l293d-motor-driver.html
WatElectronics. (2021, August 8). WatElectronics. Retrieved from
https://www.watelectronics.com/lcd-16x2/

A Rain-Detecting Circuit
For Door Opening And Closing
EMBEDED SYSTEM PROJECT
Page 37

CODE
Anh, T. T. (2018)

#include <Main.h>

#fuses NOWDT,NOPROTECT,PUT,NOLVP,HS

#use delay(clock = 8000000) //Tan so thach anh 8MHz

#define LCD_ENABLE_PIN PIN_D2

#define LCD_RS_PIN PIN_D0

#define LCD_RW_PIN PIN_D1

#define LCD_DATA4 PIN_D7

#define LCD_DATA5 PIN_D6

#define LCD_DATA6 PIN_D5

#define LCD_DATA7 PIN_D4

#define SWITCHLIMIT PIN_E2

#define BTCONTROL PIN_E0

#define BTMODE PIN_E1

#define TIMEOPEN 6000

A Rain-Detecting Circuit
For Door Opening And Closing
EMBEDED SYSTEM PROJECT
Page 38

#define OPEN 1

#define CLOSE 0

#define AUTOMODE 1

#define MANUALMODE 0

#include <lcd.c>

unsigned int32 TimeCount=0;

int8 DoorStatus=CLOSE;

int8 Mode=AUTOMODE;

unsigned int32 RainValue=0;

void Stop()

output_low(PIN_C0);

output_low(PIN_C1);

A Rain-Detecting Circuit
For Door Opening And Closing
EMBEDED SYSTEM PROJECT
Page 39

void CloseDoor()

output_high(PIN_C0);

output_low(PIN_C1);

while(input(SWITCHLIMIT)==1);

Stop();

DoorStatus=CLOSE;

void OpenDoor()

if(DoorStatus==CLOSE)

output_low(PIN_C0);

output_high(PIN_C1);

delay_ms(TIMEOPEN);

A Rain-Detecting Circuit
For Door Opening And Closing
EMBEDED SYSTEM PROJECT
Page 40

Stop();

DoorStatus=OPEN;

void DisplayRain()

unsigned int32 ADCValue=0;

SET_ADC_CHANNEL(0);

delay_ms(100);

ADCValue=READ_ADC();

RainValue=ADCValue*100/1023;

lcd_gotoxy(7,2);

lcd_putc(" ");

lcd_gotoxy(7,2);

if( RainValue<100) lcd_putc(' ');

else lcd_putc(RainValue/100+48);

if( RainValue<10) lcd_putc(' ');

A Rain-Detecting Circuit
For Door Opening And Closing
EMBEDED SYSTEM PROJECT
Page 41

else lcd_putc((RainValue%100)/10+48);

lcd_putc(RainValue%10+48);

void DisplayMode()

lcd_gotoxy(12,2);

if(Mode==AUTOMODE)

lcd_putc("AUTO");

else

lcd_putc("MAN ");

void DisplayMain()

A Rain-Detecting Circuit
For Door Opening And Closing
EMBEDED SYSTEM PROJECT
Page 42

lcd_putc("HT MAI CHE MUA");

lcd_gotoxy(1,2);

lcd_putc("L.MUA: % ");

void CheckButton()

if(Input(BTMODE)==0)

delay_ms(250);

while(Input(BTMODE)==0);

if(Mode==MANUALMODE)

Mode=AUTOMODE;

A Rain-Detecting Circuit
For Door Opening And Closing
EMBEDED SYSTEM PROJECT
Page 43

else

Mode=MANUALMODE;

DisplayMode();

if(Input(BTCONTROL)==0)

delay_ms(250);

while(Input(BTCONTROL)==0);

if(Mode==MANUALMODE)

if(DoorStatus==CLOSE)

OpenDoor();

else

A Rain-Detecting Circuit
For Door Opening And Closing
EMBEDED SYSTEM PROJECT
Page 44

CloseDoor();

void main()

SET_TRIS_C(0x80); // chan RX input con lai la output

SET_TRIS_D(0x00);

SET_TRIS_A(0xFF);

SET_TRIS_E(0xFF);

enable_interrupts(INT_RDA);

enable_interrupts(GLOBAL);

SETUP_ADC_PORTS(AN0);

SETUP_ADC(ADC_CLOCK_INTERNAL);

lcd_init();

A Rain-Detecting Circuit
For Door Opening And Closing
EMBEDED SYSTEM PROJECT
Page 45

DisplayMain();

DisplayRain();

DisplayMode();

TimeCount=0;

CloseDoor();

while(1)

CheckButton();

TimeCount++;

if(TimeCount>500)

TimeCount=0;

DisplayRain();

if(Mode==AUTOMODE)

if(RainValue<30&&DoorStatus==CLOSE)

OpenDoor();

A Rain-Detecting Circuit
For Door Opening And Closing
EMBEDED SYSTEM PROJECT
Page 46

else if(RainValue>40&&DoorStatus==OPEN)

CloseDoor();

delay_ms(1);

A Rain-Detecting Circuit
For Door Opening And Closing

You might also like