SlideShare una empresa de Scribd logo
1 de 18
Intelligent Control Laboratory, Dept. of Engineering Science, National Cheng Kung University
Advisor : Prof. Teh-Lu Liao
Student : Zheng-De Liu
Intelligent Control Laboratory, Dept. of Engineering Science,
National Cheng Kung University
 Motivation
 Block Diagram
 Framework Diagram
 Arduino Introduction
 Device Description
 Flow Diagram
 Master Code & Slave Code
 Performance
2
Intelligent Control Laboratory, Dept. of Engineering Science,
National Cheng Kung University
3
Schematic View
Rain Sensor
Humidity and
Temperature Sensor
Control
Control
LCM
Screen
Bluetooth
Intelligent Control Laboratory, Dept. of Engineering Science,
National Cheng Kung University
4
Intelligent Control Laboratory, Dept. of Engineering Science,
National Cheng Kung University
5
Microprocessor
Rain Sensor
Temprature and
Humidity Sensor
Wireless
Transceiver
Uart
Host
Debug
Uart
I/O
I/O
Microprocessor
Light and
Buzzer
LCM
Screen
Wireless
Transceiver
Uart
Uart
Host
Debug
I/O
IIC
Central Node Sensor Node
Intelligent Control Laboratory, Dept. of Engineering Science,
National Cheng Kung University
6
Arduino-
ATMEGA2560
YL-83
DHT-11
HC-05
Uart
Serial
Monitor
Uart
I/O
I/O
Arduino-
ATMEGA2560
Light and
Buzzer
LCM
1602
HC-05
Uart
Uart
Serial
Monitor
I/O
IIC
Central Node Sensor Node
Intelligent Control Laboratory, Dept. of Engineering Science,
National Cheng Kung University
 Arduino is an open-source
electronics prototyping
platformbased on flexible,
easy-to-use hardware and
software.
7
Intelligent Control Laboratory, Dept. of Engineering Science,
National Cheng Kung University
8
Rain Sensor : YL-83
Sensitivity: 0~5V
Humidity and Temperature
Sensor : DHT11
Sensitivity:0~50 oC
20~90%RH
Bluetooth : HC-05
LCM : 1602
8-Channels Relay DIY Extension Cord
Intelligent Control Laboratory, Dept. of Engineering Science,
National Cheng Kung University
9
Arduino-1
LCM
Extension
cord
Relay
Bizzer
Bluetooth
Light
Intelligent Control Laboratory, Dept. of Engineering Science,
National Cheng Kung University
10
Rain
Sensor
Humidity and Tempture
Sensor
Bluetoooth
Arduino-2
Intelligent Control Laboratory, Dept. of Engineering Science,
National Cheng Kung University
11
HC-05
Slave
Slave
Slave
Master
Intelligent Control Laboratory, Dept. of Engineering Science,
National Cheng Kung University
 The Bluetooth module has two work modes:
Commands response mode and auto connection mode.
Ex: AT+ROLE=1 (Enter) Can change from M to S .
AT+BIND=12,3,287044 (Enter) Binding address.
12
Intelligent Control Laboratory, Dept. of Engineering Science,
National Cheng Kung University
13
Start
BT
match?
Finding
Slave?
Raining?
Set AT-command
LCM show
DHT11-Sensor
Reading DHT11
Form BT
LCM show
YL-83-Sensor
Reading YL-83
Form BT
Switch
on?
Buzzer call
& Light on
Y
N
N
Y
N
Y
N
Y
LCM show
standby
LCM show
standby
LCM show
standby
Rain
stopped?
End
Y
N
Intelligent Control Laboratory, Dept. of Engineering Science,
National Cheng Kung University
14
Intelligent Control Laboratory, Dept. of Engineering Science,
National Cheng Kung University
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <SoftwareSerial.h>
#define Bizzer 44
#define Switch4 A0
#define Relay_Ch1 45
#define Master_Tx 13
#define Master_Rx 12
#define I2C_ADDR 0x20
#define BACKLIGHT_PIN 7
#define En_pin 4
#define Rw_pin 5
#define Rs_pin 6
#define D4_pin 0
#define D5_pin 1
#define D6_pin 2
#define D7_pin 3
#define BACKLIGHT_FLAG NEGATIVE
LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_p
in,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);
SoftwareSerial BT(Master_Rx, Master_Tx);
15
char i,j;
int s;
void LCD_init()
{
lcd.begin (20,4);
lcd.setBacklightPin(BACKLIGHT_
PIN,BACKLIGHT_FLAG);
lcd.setBacklight(1);
lcd.clear();
delay(100);
}
void setup()
{
pinMode(Bizzer,OUTPUT);
pinMode(Switch4,INPUT);
pinMode(Relay_Ch1,OUTPUT);
LCD_init();
BT.begin(9600);
Serial.begin(9600);
lcd.setCursor(0,0);
lcd.print("Standby!!");
}
void loop()
{
char str[5];
delay(900);
for(i=0;i<5;i++)
{
if(BT.available()>0)
{
str[i]= BT.read();
Serial.println(str[i]);
delay(100);
}
}
s=analogRead(Switch4);
Serial.println(s);
if(s>600)
{
digitalWrite(Bizzer,LOW);
digitalWrite(Relay_Ch1,LOW);
LCD_init();
lcd.setCursor(0,0);
lcd.print("Standby!!");
str[0]=str[1]=str[2]=str[3]=str[4]='X';
delay(7500);
}
if(str[0]=='d'||str[0]=='h'||str[0]=='t')
{
digitalWrite(Bizzer,HIGH);
digitalWrite(Relay_Ch1,HIGH);
if(str[0]=='d')
{
lcd.setCursor(7,2);
lcd.print("level-1");
}
if(str[0]=='h')
{
lcd.setCursor(7,2);
lcd.print("level-2");
}
if(str[0]=='t')
{
lcd.setCursor(7,2);
lcd.print("level-3");
}
lcd.setCursor(0,0);
lcd.print("warning!!");
lcd.setCursor(0,1);
lcd.print("YL-83 DHT11 Sensor");
lcd.setCursor(0,2);
lcd.print("state: ");
}
if(str[0]=='n')
{
digitalWrite(Bizzer,LOW);
digitalWrite(Relay_Ch1,LO
W);
LCD_init();
lcd.setCursor(0,0);
lcd.print("Standby!!");
}
lcd.setCursor(0,3);
lcd.print("H:");
lcd.setCursor(4,3);
lcd.print("(%) ; T:");
lcd.setCursor(14,3);
lcd.print("(oC)");
lcd.setCursor(2,3);
lcd.print(str[1]);
lcd.setCursor(3,3);
lcd.print(str[2]);
lcd.setCursor(12,3);
lcd.print(str[3]);
lcd.setCursor(13,3);
lcd.print(str[4]);
}
Intelligent Control Laboratory, Dept. of Engineering Science,
National Cheng Kung University
#include <SoftwareSerial.h>
#include <dht11.h>
#define Slave_TxPin 11
#define Slave_RxPin 10
#define Temp_sensor 22
int rain_AO=A0;
SoftwareSerial BT(Slave_RxPin, Slave_TxPin);
dht11 DHT11;
void BT_init()
{
int i;
BT.write("ATrn");
delay(200);
BT.write("AT+ROLE=1rn");
delay(200);
BT.write("AT+INITrn");
delay(200);
BT.write("AT+BIND=12,3,287044rn");
delay(200);
BT.write("AT+CMODE=0rn");
delay(200);
}
16
void setup()
{
Serial.begin(9600);
BT.begin(9600);
pinMode(rain_AO,INPUT);
// BT_init();
}
void loop()
{
char Humidity_tens;
char Humidity_units;
char Temperature_tens;
char Temperature_units;
int chk = DHT11.read(Temp_sensor);
int a = DHT11.humidity;
int b = DHT11.temperature;
char table[]="0123456789";
int i,k;
i=analogRead(rain_AO);
if(i<1000)
{
if(i>500 && i<1000)
{
BT.print('d');
Serial.println('d');
}
if(i>300 && i<500)
{
BT.print('h');
Serial.println('h');;
}
if(i>50 && i<300)
{
BT.print('t');
Serial.println('t');;
}
delay(100);
}
else if(i>=1000)
{
BT.print('n');
Serial.println('n');
delay(100);
}
Humidity_tens = table[a/10];
Humidity_units = table[a%10];
Serial.println(Humidity_tens);
Serial.println(Humidity_units);
Temperature_tens = table[b/10];
Temperature_units = table[b%10];
Serial.println(Temperature_tens);
Serial.println(Temperature_units);
BT.print(Humidity_tens);
delay(100);
BT.print(Humidity_units);
delay(100);
BT.print(Temperature_tens);
delay(100);
BT.print(Temperature_units);
delay(100);
delay(1000);
}
Intelligent Control Laboratory, Dept. of Engineering Science,
National Cheng Kung University
17
Intelligent Control Laboratory, Dept. of Engineering Science,
National Cheng Kung University
Thank you for your attention.
18

Más contenido relacionado

La actualidad más candente

Digital clock presentation
Digital clock presentationDigital clock presentation
Digital clock presentationAditya Jha ✅
 
Nrf24l01 tutorial 0
Nrf24l01 tutorial 0Nrf24l01 tutorial 0
Nrf24l01 tutorial 0Khanh Le
 
8051-mazidi-solution
8051-mazidi-solution8051-mazidi-solution
8051-mazidi-solutionZunAib Ali
 
INTERRUPT DRIVEN MULTIPLEXED 7 SEGMENT DIGITAL CLOCK
INTERRUPT DRIVEN MULTIPLEXED 7 SEGMENT DIGITAL CLOCKINTERRUPT DRIVEN MULTIPLEXED 7 SEGMENT DIGITAL CLOCK
INTERRUPT DRIVEN MULTIPLEXED 7 SEGMENT DIGITAL CLOCKSantanu Chatterjee
 
Physical prototyping lab3-serious_serial
Physical prototyping lab3-serious_serialPhysical prototyping lab3-serious_serial
Physical prototyping lab3-serious_serialTony Olsson.
 
Distance measurement using Ultrasonic sensor on Arduino Uno
Distance measurement using Ultrasonic sensor on Arduino UnoDistance measurement using Ultrasonic sensor on Arduino Uno
Distance measurement using Ultrasonic sensor on Arduino UnoAswin KP
 
Using Ready-for-PIC and SDR Libraries
Using Ready-for-PIC and SDR LibrariesUsing Ready-for-PIC and SDR Libraries
Using Ready-for-PIC and SDR LibrariesCorrado Santoro
 
Project report on the Digital clock using RTC and microcontroller 8051
Project report on the Digital clock using RTC and microcontroller 8051Project report on the Digital clock using RTC and microcontroller 8051
Project report on the Digital clock using RTC and microcontroller 8051Maulik Sanchela
 
Presentation mia transistors
Presentation mia transistorsPresentation mia transistors
Presentation mia transistorsmiaabida
 
Interfacing to the analog world
Interfacing to the analog worldInterfacing to the analog world
Interfacing to the analog worldIslam Samir
 
Physical prototyping lab2-analog_digital
Physical prototyping lab2-analog_digitalPhysical prototyping lab2-analog_digital
Physical prototyping lab2-analog_digitalTony Olsson.
 
PowerMate15 Technical Specification
PowerMate15 Technical SpecificationPowerMate15 Technical Specification
PowerMate15 Technical SpecificationRimsky Cheng
 
a project on automatic traffic control using IC 555
a project on automatic traffic control using IC 555a project on automatic traffic control using IC 555
a project on automatic traffic control using IC 555jack990315
 
10 12 2011 lab wiring
10 12 2011 lab wiring10 12 2011 lab wiring
10 12 2011 lab wiringThanasan Bk
 
Digital clock
Digital clockDigital clock
Digital clockAbi Malik
 
8085 interrupts
8085 interrupts8085 interrupts
8085 interruptsIsha Negi
 
A Robust UART Architecture Based on Recursive Running Sum Filter for Better N...
A Robust UART Architecture Based on Recursive Running Sum Filter for Better N...A Robust UART Architecture Based on Recursive Running Sum Filter for Better N...
A Robust UART Architecture Based on Recursive Running Sum Filter for Better N...Kevin Mathew
 

La actualidad más candente (20)

Digital clock presentation
Digital clock presentationDigital clock presentation
Digital clock presentation
 
Nrf24l01 tutorial 0
Nrf24l01 tutorial 0Nrf24l01 tutorial 0
Nrf24l01 tutorial 0
 
8051-mazidi-solution
8051-mazidi-solution8051-mazidi-solution
8051-mazidi-solution
 
INTERRUPT DRIVEN MULTIPLEXED 7 SEGMENT DIGITAL CLOCK
INTERRUPT DRIVEN MULTIPLEXED 7 SEGMENT DIGITAL CLOCKINTERRUPT DRIVEN MULTIPLEXED 7 SEGMENT DIGITAL CLOCK
INTERRUPT DRIVEN MULTIPLEXED 7 SEGMENT DIGITAL CLOCK
 
Physical prototyping lab3-serious_serial
Physical prototyping lab3-serious_serialPhysical prototyping lab3-serious_serial
Physical prototyping lab3-serious_serial
 
Digital stop watch
Digital stop watchDigital stop watch
Digital stop watch
 
Módulo adc 18f4550
Módulo adc   18f4550Módulo adc   18f4550
Módulo adc 18f4550
 
Distance measurement using Ultrasonic sensor on Arduino Uno
Distance measurement using Ultrasonic sensor on Arduino UnoDistance measurement using Ultrasonic sensor on Arduino Uno
Distance measurement using Ultrasonic sensor on Arduino Uno
 
Using Ready-for-PIC and SDR Libraries
Using Ready-for-PIC and SDR LibrariesUsing Ready-for-PIC and SDR Libraries
Using Ready-for-PIC and SDR Libraries
 
Project report on the Digital clock using RTC and microcontroller 8051
Project report on the Digital clock using RTC and microcontroller 8051Project report on the Digital clock using RTC and microcontroller 8051
Project report on the Digital clock using RTC and microcontroller 8051
 
Presentation mia transistors
Presentation mia transistorsPresentation mia transistors
Presentation mia transistors
 
Interfacing to the analog world
Interfacing to the analog worldInterfacing to the analog world
Interfacing to the analog world
 
Physical prototyping lab2-analog_digital
Physical prototyping lab2-analog_digitalPhysical prototyping lab2-analog_digital
Physical prototyping lab2-analog_digital
 
PowerMate15 Technical Specification
PowerMate15 Technical SpecificationPowerMate15 Technical Specification
PowerMate15 Technical Specification
 
a project on automatic traffic control using IC 555
a project on automatic traffic control using IC 555a project on automatic traffic control using IC 555
a project on automatic traffic control using IC 555
 
10 12 2011 lab wiring
10 12 2011 lab wiring10 12 2011 lab wiring
10 12 2011 lab wiring
 
Digital clock
Digital clockDigital clock
Digital clock
 
8085 interrupts
8085 interrupts8085 interrupts
8085 interrupts
 
RF ID_toll2
RF ID_toll2RF ID_toll2
RF ID_toll2
 
A Robust UART Architecture Based on Recursive Running Sum Filter for Better N...
A Robust UART Architecture Based on Recursive Running Sum Filter for Better N...A Robust UART Architecture Based on Recursive Running Sum Filter for Better N...
A Robust UART Architecture Based on Recursive Running Sum Filter for Better N...
 

Similar a A Wireless Application of The Rain, Humidity and Temperature Sensors Based on Arduino and Bluetooth

ARDUINO BASED TIME AND TEMPERATURE DISPLAY
ARDUINO BASED TIME AND TEMPERATURE DISPLAY ARDUINO BASED TIME AND TEMPERATURE DISPLAY
ARDUINO BASED TIME AND TEMPERATURE DISPLAY ajit kumar singh
 
Fire Fighting Robot
Fire Fighting RobotFire Fighting Robot
Fire Fighting RobotSaadullah74
 
IMPLEMENTING A DIGITAL MULTIMETER
IMPLEMENTING A DIGITAL MULTIMETERIMPLEMENTING A DIGITAL MULTIMETER
IMPLEMENTING A DIGITAL MULTIMETERVijay Elavunkal
 
Scada plc by PANKAJ CHAUDHARY
Scada plc by PANKAJ CHAUDHARYScada plc by PANKAJ CHAUDHARY
Scada plc by PANKAJ CHAUDHARYPANKAJRANJANA143
 
Xbee Wireless Throttle Position Sensor And Control
Xbee Wireless Throttle Position Sensor  And ControlXbee Wireless Throttle Position Sensor  And Control
Xbee Wireless Throttle Position Sensor And Controlkians64
 
RESUME__SUMER SAILI
RESUME__SUMER SAILIRESUME__SUMER SAILI
RESUME__SUMER SAILISumer Saili
 
Major_project_b.tech_sem8_may_2018
Major_project_b.tech_sem8_may_2018Major_project_b.tech_sem8_may_2018
Major_project_b.tech_sem8_may_2018Dipen Kantariya
 
Logic gate tester for IC's ( Digital Electronics and Logic deisgn EE3114 )
Logic gate tester for IC's ( Digital Electronics and Logic deisgn EE3114 )Logic gate tester for IC's ( Digital Electronics and Logic deisgn EE3114 )
Logic gate tester for IC's ( Digital Electronics and Logic deisgn EE3114 )Jikrul Sayeed
 
Design of all digital phase locked loop (d pll) with fast acquisition time
Design of all digital phase locked loop (d pll) with fast acquisition timeDesign of all digital phase locked loop (d pll) with fast acquisition time
Design of all digital phase locked loop (d pll) with fast acquisition timeeSAT Journals
 
IRJET- Explosive Ordinanace Disposal Robot
IRJET- Explosive Ordinanace Disposal RobotIRJET- Explosive Ordinanace Disposal Robot
IRJET- Explosive Ordinanace Disposal RobotIRJET Journal
 
BUILD DC TIME DELAY RELAY USING PUT ON ZERO (0) PCB .pptx
BUILD DC TIME DELAY RELAY USING PUT ON ZERO (0) PCB .pptxBUILD DC TIME DELAY RELAY USING PUT ON ZERO (0) PCB .pptx
BUILD DC TIME DELAY RELAY USING PUT ON ZERO (0) PCB .pptxAshish Sadavarti
 
REAL TIME AUTOMATION FOR COLLEGES
REAL TIME AUTOMATION  FOR COLLEGESREAL TIME AUTOMATION  FOR COLLEGES
REAL TIME AUTOMATION FOR COLLEGESNishmi Suresh
 

Similar a A Wireless Application of The Rain, Humidity and Temperature Sensors Based on Arduino and Bluetooth (20)

ARDUINO BASED TIME AND TEMPERATURE DISPLAY
ARDUINO BASED TIME AND TEMPERATURE DISPLAY ARDUINO BASED TIME AND TEMPERATURE DISPLAY
ARDUINO BASED TIME AND TEMPERATURE DISPLAY
 
Fire Fighting Robot
Fire Fighting RobotFire Fighting Robot
Fire Fighting Robot
 
Anup2
Anup2Anup2
Anup2
 
Bidirect visitor counter
Bidirect visitor counterBidirect visitor counter
Bidirect visitor counter
 
IMPLEMENTING A DIGITAL MULTIMETER
IMPLEMENTING A DIGITAL MULTIMETERIMPLEMENTING A DIGITAL MULTIMETER
IMPLEMENTING A DIGITAL MULTIMETER
 
Minor_project.ppt.pdf
Minor_project.ppt.pdfMinor_project.ppt.pdf
Minor_project.ppt.pdf
 
Scada plc by PANKAJ CHAUDHARY
Scada plc by PANKAJ CHAUDHARYScada plc by PANKAJ CHAUDHARY
Scada plc by PANKAJ CHAUDHARY
 
Xbee Wireless Throttle Position Sensor And Control
Xbee Wireless Throttle Position Sensor  And ControlXbee Wireless Throttle Position Sensor  And Control
Xbee Wireless Throttle Position Sensor And Control
 
RESUME__SUMER SAILI
RESUME__SUMER SAILIRESUME__SUMER SAILI
RESUME__SUMER SAILI
 
Major_project_b.tech_sem8_may_2018
Major_project_b.tech_sem8_may_2018Major_project_b.tech_sem8_may_2018
Major_project_b.tech_sem8_may_2018
 
project 3 full report
project 3 full reportproject 3 full report
project 3 full report
 
Logic gate tester for IC's ( Digital Electronics and Logic deisgn EE3114 )
Logic gate tester for IC's ( Digital Electronics and Logic deisgn EE3114 )Logic gate tester for IC's ( Digital Electronics and Logic deisgn EE3114 )
Logic gate tester for IC's ( Digital Electronics and Logic deisgn EE3114 )
 
Design of all digital phase locked loop (d pll) with fast acquisition time
Design of all digital phase locked loop (d pll) with fast acquisition timeDesign of all digital phase locked loop (d pll) with fast acquisition time
Design of all digital phase locked loop (d pll) with fast acquisition time
 
IRJET- Explosive Ordinanace Disposal Robot
IRJET- Explosive Ordinanace Disposal RobotIRJET- Explosive Ordinanace Disposal Robot
IRJET- Explosive Ordinanace Disposal Robot
 
BUILD DC TIME DELAY RELAY USING PUT ON ZERO (0) PCB .pptx
BUILD DC TIME DELAY RELAY USING PUT ON ZERO (0) PCB .pptxBUILD DC TIME DELAY RELAY USING PUT ON ZERO (0) PCB .pptx
BUILD DC TIME DELAY RELAY USING PUT ON ZERO (0) PCB .pptx
 
Spark
SparkSpark
Spark
 
Project Report
Project ReportProject Report
Project Report
 
Ctara report
Ctara reportCtara report
Ctara report
 
REAL TIME AUTOMATION FOR COLLEGES
REAL TIME AUTOMATION  FOR COLLEGESREAL TIME AUTOMATION  FOR COLLEGES
REAL TIME AUTOMATION FOR COLLEGES
 
water level edit.docx
water level edit.docxwater level edit.docx
water level edit.docx
 

A Wireless Application of The Rain, Humidity and Temperature Sensors Based on Arduino and Bluetooth

  • 1. Intelligent Control Laboratory, Dept. of Engineering Science, National Cheng Kung University Advisor : Prof. Teh-Lu Liao Student : Zheng-De Liu
  • 2. Intelligent Control Laboratory, Dept. of Engineering Science, National Cheng Kung University  Motivation  Block Diagram  Framework Diagram  Arduino Introduction  Device Description  Flow Diagram  Master Code & Slave Code  Performance 2
  • 3. Intelligent Control Laboratory, Dept. of Engineering Science, National Cheng Kung University 3 Schematic View Rain Sensor Humidity and Temperature Sensor Control Control LCM Screen Bluetooth
  • 4. Intelligent Control Laboratory, Dept. of Engineering Science, National Cheng Kung University 4
  • 5. Intelligent Control Laboratory, Dept. of Engineering Science, National Cheng Kung University 5 Microprocessor Rain Sensor Temprature and Humidity Sensor Wireless Transceiver Uart Host Debug Uart I/O I/O Microprocessor Light and Buzzer LCM Screen Wireless Transceiver Uart Uart Host Debug I/O IIC Central Node Sensor Node
  • 6. Intelligent Control Laboratory, Dept. of Engineering Science, National Cheng Kung University 6 Arduino- ATMEGA2560 YL-83 DHT-11 HC-05 Uart Serial Monitor Uart I/O I/O Arduino- ATMEGA2560 Light and Buzzer LCM 1602 HC-05 Uart Uart Serial Monitor I/O IIC Central Node Sensor Node
  • 7. Intelligent Control Laboratory, Dept. of Engineering Science, National Cheng Kung University  Arduino is an open-source electronics prototyping platformbased on flexible, easy-to-use hardware and software. 7
  • 8. Intelligent Control Laboratory, Dept. of Engineering Science, National Cheng Kung University 8 Rain Sensor : YL-83 Sensitivity: 0~5V Humidity and Temperature Sensor : DHT11 Sensitivity:0~50 oC 20~90%RH Bluetooth : HC-05 LCM : 1602 8-Channels Relay DIY Extension Cord
  • 9. Intelligent Control Laboratory, Dept. of Engineering Science, National Cheng Kung University 9 Arduino-1 LCM Extension cord Relay Bizzer Bluetooth Light
  • 10. Intelligent Control Laboratory, Dept. of Engineering Science, National Cheng Kung University 10 Rain Sensor Humidity and Tempture Sensor Bluetoooth Arduino-2
  • 11. Intelligent Control Laboratory, Dept. of Engineering Science, National Cheng Kung University 11 HC-05 Slave Slave Slave Master
  • 12. Intelligent Control Laboratory, Dept. of Engineering Science, National Cheng Kung University  The Bluetooth module has two work modes: Commands response mode and auto connection mode. Ex: AT+ROLE=1 (Enter) Can change from M to S . AT+BIND=12,3,287044 (Enter) Binding address. 12
  • 13. Intelligent Control Laboratory, Dept. of Engineering Science, National Cheng Kung University 13 Start BT match? Finding Slave? Raining? Set AT-command LCM show DHT11-Sensor Reading DHT11 Form BT LCM show YL-83-Sensor Reading YL-83 Form BT Switch on? Buzzer call & Light on Y N N Y N Y N Y LCM show standby LCM show standby LCM show standby Rain stopped? End Y N
  • 14. Intelligent Control Laboratory, Dept. of Engineering Science, National Cheng Kung University 14
  • 15. Intelligent Control Laboratory, Dept. of Engineering Science, National Cheng Kung University #include <Wire.h> #include <LiquidCrystal_I2C.h> #include <SoftwareSerial.h> #define Bizzer 44 #define Switch4 A0 #define Relay_Ch1 45 #define Master_Tx 13 #define Master_Rx 12 #define I2C_ADDR 0x20 #define BACKLIGHT_PIN 7 #define En_pin 4 #define Rw_pin 5 #define Rs_pin 6 #define D4_pin 0 #define D5_pin 1 #define D6_pin 2 #define D7_pin 3 #define BACKLIGHT_FLAG NEGATIVE LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_p in,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin); SoftwareSerial BT(Master_Rx, Master_Tx); 15 char i,j; int s; void LCD_init() { lcd.begin (20,4); lcd.setBacklightPin(BACKLIGHT_ PIN,BACKLIGHT_FLAG); lcd.setBacklight(1); lcd.clear(); delay(100); } void setup() { pinMode(Bizzer,OUTPUT); pinMode(Switch4,INPUT); pinMode(Relay_Ch1,OUTPUT); LCD_init(); BT.begin(9600); Serial.begin(9600); lcd.setCursor(0,0); lcd.print("Standby!!"); } void loop() { char str[5]; delay(900); for(i=0;i<5;i++) { if(BT.available()>0) { str[i]= BT.read(); Serial.println(str[i]); delay(100); } } s=analogRead(Switch4); Serial.println(s); if(s>600) { digitalWrite(Bizzer,LOW); digitalWrite(Relay_Ch1,LOW); LCD_init(); lcd.setCursor(0,0); lcd.print("Standby!!"); str[0]=str[1]=str[2]=str[3]=str[4]='X'; delay(7500); } if(str[0]=='d'||str[0]=='h'||str[0]=='t') { digitalWrite(Bizzer,HIGH); digitalWrite(Relay_Ch1,HIGH); if(str[0]=='d') { lcd.setCursor(7,2); lcd.print("level-1"); } if(str[0]=='h') { lcd.setCursor(7,2); lcd.print("level-2"); } if(str[0]=='t') { lcd.setCursor(7,2); lcd.print("level-3"); } lcd.setCursor(0,0); lcd.print("warning!!"); lcd.setCursor(0,1); lcd.print("YL-83 DHT11 Sensor"); lcd.setCursor(0,2); lcd.print("state: "); } if(str[0]=='n') { digitalWrite(Bizzer,LOW); digitalWrite(Relay_Ch1,LO W); LCD_init(); lcd.setCursor(0,0); lcd.print("Standby!!"); } lcd.setCursor(0,3); lcd.print("H:"); lcd.setCursor(4,3); lcd.print("(%) ; T:"); lcd.setCursor(14,3); lcd.print("(oC)"); lcd.setCursor(2,3); lcd.print(str[1]); lcd.setCursor(3,3); lcd.print(str[2]); lcd.setCursor(12,3); lcd.print(str[3]); lcd.setCursor(13,3); lcd.print(str[4]); }
  • 16. Intelligent Control Laboratory, Dept. of Engineering Science, National Cheng Kung University #include <SoftwareSerial.h> #include <dht11.h> #define Slave_TxPin 11 #define Slave_RxPin 10 #define Temp_sensor 22 int rain_AO=A0; SoftwareSerial BT(Slave_RxPin, Slave_TxPin); dht11 DHT11; void BT_init() { int i; BT.write("ATrn"); delay(200); BT.write("AT+ROLE=1rn"); delay(200); BT.write("AT+INITrn"); delay(200); BT.write("AT+BIND=12,3,287044rn"); delay(200); BT.write("AT+CMODE=0rn"); delay(200); } 16 void setup() { Serial.begin(9600); BT.begin(9600); pinMode(rain_AO,INPUT); // BT_init(); } void loop() { char Humidity_tens; char Humidity_units; char Temperature_tens; char Temperature_units; int chk = DHT11.read(Temp_sensor); int a = DHT11.humidity; int b = DHT11.temperature; char table[]="0123456789"; int i,k; i=analogRead(rain_AO); if(i<1000) { if(i>500 && i<1000) { BT.print('d'); Serial.println('d'); } if(i>300 && i<500) { BT.print('h'); Serial.println('h');; } if(i>50 && i<300) { BT.print('t'); Serial.println('t');; } delay(100); } else if(i>=1000) { BT.print('n'); Serial.println('n'); delay(100); } Humidity_tens = table[a/10]; Humidity_units = table[a%10]; Serial.println(Humidity_tens); Serial.println(Humidity_units); Temperature_tens = table[b/10]; Temperature_units = table[b%10]; Serial.println(Temperature_tens); Serial.println(Temperature_units); BT.print(Humidity_tens); delay(100); BT.print(Humidity_units); delay(100); BT.print(Temperature_tens); delay(100); BT.print(Temperature_units); delay(100); delay(1000); }
  • 17. Intelligent Control Laboratory, Dept. of Engineering Science, National Cheng Kung University 17
  • 18. Intelligent Control Laboratory, Dept. of Engineering Science, National Cheng Kung University Thank you for your attention. 18