Professional Documents
Culture Documents
A Rain-Detecting Circuit For Door Opening and Closing
A Rain-Detecting Circuit For Door Opening and Closing
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
DC Direct Current
IC Intergrated Circuit
4
EMBEDED SYSTEM PROJECT
Page 1
A Rain-Detecting Circuit
For Door Opening And Closing
EMBEDED SYSTEM PROJECT
Page 2
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.
A Rain-Detecting Circuit
For Door Opening And Closing
EMBEDED SYSTEM PROJECT
Page 3
A Rain-Detecting Circuit
For Door Opening And Closing
EMBEDED SYSTEM PROJECT
Page 4
A Rain-Detecting Circuit
For Door Opening And Closing
EMBEDED SYSTEM PROJECT
Page 5
PIC application:
A Rain-Detecting Circuit
For Door Opening And Closing
EMBEDED SYSTEM PROJECT
Page 6
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.
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…
A Rain-Detecting Circuit
For Door Opening And Closing
EMBEDED SYSTEM PROJECT
Page 8
Sensor Block
Display Block
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
Specifications:
Output: DC 5V 2A
A Rain-Detecting Circuit
For Door Opening And Closing
EMBEDED SYSTEM PROJECT
Page 10
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
Specifications:
LED lights up when there is no rain, high output, when there is rain, low output LED
turns off.
A Rain-Detecting Circuit
For Door Opening And Closing
EMBEDED SYSTEM PROJECT
Page 12
The task is to receive signals from the sensor when powered and control the
motor based on the sensor signal.
Specifications:
A Rain-Detecting Circuit
For Door Opening And Closing
EMBEDED SYSTEM PROJECT
Page 13
A Rain-Detecting Circuit
For Door Opening And Closing
EMBEDED SYSTEM PROJECT
Page 14
Specifications:
[Lowe, D. (2022)]
A Rain-Detecting Circuit
For Door Opening And Closing
EMBEDED SYSTEM PROJECT
Page 15
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
Specifications:
A Rain-Detecting Circuit
For Door Opening And Closing
EMBEDED SYSTEM PROJECT
Page 17
A Rain-Detecting Circuit
For Door Opening And Closing
EMBEDED SYSTEM PROJECT
Page 18
A Rain-Detecting Circuit
For Door Opening And Closing
EMBEDED SYSTEM PROJECT
Page 19
Specifications:
MAX voltage: 7V
A Rain-Detecting Circuit
For Door Opening And Closing
EMBEDED SYSTEM PROJECT
Page 20
+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.
+ 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.
A Rain-Detecting Circuit
For Door Opening And Closing
EMBEDED SYSTEM PROJECT
Page 22
A Rain-Detecting Circuit
For Door Opening And Closing
EMBEDED SYSTEM PROJECT
Page 23
A Rain-Detecting Circuit
For Door Opening And Closing
EMBEDED SYSTEM PROJECT
Page 24
A Rain-Detecting Circuit
For Door Opening And Closing
EMBEDED SYSTEM PROJECT
Page 25
A Rain-Detecting Circuit
For Door Opening And Closing
EMBEDED SYSTEM PROJECT
Page 26
A Rain-Detecting Circuit
For Door Opening And Closing
EMBEDED SYSTEM PROJECT
Page 27
A Rain-Detecting Circuit
For Door Opening And Closing
EMBEDED SYSTEM PROJECT
Page 28
A Rain-Detecting Circuit
For Door Opening And Closing
EMBEDED SYSTEM PROJECT
Page 29
A Rain-Detecting Circuit
For Door Opening And Closing
EMBEDED SYSTEM PROJECT
Page 30
A Rain-Detecting Circuit
For Door Opening And Closing
EMBEDED SYSTEM PROJECT
Page 31
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.
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
A Rain-Detecting Circuit
For Door Opening And Closing
EMBEDED SYSTEM PROJECT
Page 33
A Rain-Detecting Circuit
For Door Opening And Closing
EMBEDED SYSTEM PROJECT
Page 34
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
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>
int8 DoorStatus=CLOSE;
int8 Mode=AUTOMODE;
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()
SET_ADC_CHANNEL(0);
delay_ms(100);
ADCValue=READ_ADC();
RainValue=ADCValue*100/1023;
lcd_gotoxy(7,2);
lcd_putc(" ");
lcd_gotoxy(7,2);
else lcd_putc(RainValue/100+48);
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_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_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