a wireless application of the rain, humidity and temperature sensors based on arduino and bluetooth

18
Intelligent Control Laboratory, Dept. of Engineering Science, National Cheng Kung University A Wireless Application of The Rain, Humidity and Temperature Sensors Based on Arduino and Bluetooth Advisor : Prof. Teh-Lu Liao Student : Zheng-De Liu

Upload: -

Post on 14-May-2015

636 views

Category:

Documents


0 download

TRANSCRIPT

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

Intelligent Control Laboratory, Dept. of Engineering Science, National Cheng Kung University

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

Advisor : Prof. Teh-Lu Liao Student : Zheng-De Liu

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

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

Outline

2

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

Intelligent Control Laboratory, Dept. of Engineering Science, National Cheng Kung University

Motivation (1/2)

3

Schematic View

Rain Sensor

Humidity and Temperature Sensor

Control

Control

LCMScreen

Bluetooth

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

Intelligent Control Laboratory, Dept. of Engineering Science, National Cheng Kung University

Motivation (2/2)

4

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

Intelligent Control Laboratory, Dept. of Engineering Science, National Cheng Kung University

5

Microprocessor

Rain Sensor

Temprature and Humidity Sensor

WirelessTransceiver

Uart

Host Debug

Uart

I/O

I/O

Microprocessor

Light and Buzzer

LCMScreen

WirelessTransceiver

Uart

Uart

Host Debug

I/O

IIC

Central Node Sensor Node

Block Diagram

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

Intelligent Control Laboratory, Dept. of Engineering Science, National Cheng Kung University

6

Framework Diagram

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

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

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.

Arduino Introduction

7

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

Intelligent Control Laboratory, Dept. of Engineering Science, National Cheng Kung University

Device Description (1/5)

8

Rain Sensor : YL-83Sensitivity: 0~5V

Humidity and Temperature Sensor : DHT11Sensitivity:0~50 oC 20~90%RH

Bluetooth : HC-05

LCM : 1602

8-Channels Relay DIY Extension Cord

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

Intelligent Control Laboratory, Dept. of Engineering Science, National Cheng Kung University

Device Description (2/5) Central Node based on Master Bluetooth

9

Arduino-1

LCM

Extension cord

Relay

Bizzer

Bluetooth

Light

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

Intelligent Control Laboratory, Dept. of Engineering Science, National Cheng Kung University

10

Rain Sensor

Humidity and TemptureSensor

Bluetoooth

Arduino-2

Device Description (3/5) Sensor Node based on Slave Bluetooth

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

Intelligent Control Laboratory, Dept. of Engineering Science, National Cheng Kung University

Device Description (4/5)

11

HC-05

Slave

Slave

Slave

Master

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

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.

Device Description (5/5)

12

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

Intelligent Control Laboratory, Dept. of Engineering Science, National Cheng Kung University

Flow Diagram

13

Start

BT match

?

Finding Slave?

Raining?

Set AT-commandLCM show

DHT11-Sensor

Reading DHT11Form BT

LCM show YL-83-Sensor

Reading YL-83Form 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

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

Intelligent Control Laboratory, Dept. of Engineering Science, National Cheng Kung University

Master Code & Slave Code

14

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

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,LOW); 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]); }

Master Code

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

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("AT\r\n");

delay(200);

BT.write("AT+ROLE=1\r\n");

delay(200);

BT.write("AT+INIT\r\n");

delay(200);

BT.write("AT+BIND=12,3,287044\r\n");

delay(200);

BT.write("AT+CMODE=0\r\n");

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);}

Slave Code

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

Intelligent Control Laboratory, Dept. of Engineering Science, National Cheng Kung University

Performance

17

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

Intelligent Control Laboratory, Dept. of Engineering Science, National Cheng Kung University

Thank you for your attention.

18