Data sensor arduino
Sensor adalah instrumen atau komponen yang mampu mendeteksi perubahan kondisi objek dalam jangkauannya. Pengukuran besaran perubahan tersebut harus diubah dahulu menjadi bentuk digital sehingga dapat diproses oleh perangkat digital lainnya.
Data variabel ini bisa dimonitoring secara lokal melalui layar monitor maupun global melalui internet.
Hal yang mendukung keandalan sistem monitoring :
- realtime, yaitu data yang ditampilkan merupakan kondisi masa yang singkat, misalnya di perbarui setiap 1 detik.
- Data memiliki identitas seperti lokasi, waktu.
- Data yang diterima memiliki mekanisme penyaringan sehingga data yang ditampilkan terjamin.
Sensor detektor kebakaran
Terdapat beberapa Indikasi kebakaran yaitu :
- Api dideteksi dengan sensor flame
- Suhu dibaca dengan sensor suhu
- Asap dibaca dengan sensor asap (smoke detector)
Dalam hal pencegahan kebakaran, ketiga variabel ini terus menerus dimonitoring secara lokal.
Monitoring detektor kebakaran ini secara global juga diperlukan untuk memberikan informasi kepada pihak terkait.
Dalam contoh ini ketiga (modul) sensor ini digunakan bersama arduino dan akan dikirimkan ke mysql server.
Akses informasi sensor dengan codeIgniter
Informasi data saat ini dapat dengan mudah diakses dimanapun, namun dengan menggunakan codeIgniter diperoleh beberapa keuntungan yaitu :
- Pengembangan lebih mudah dengan baris program yang dapat disederhanakan.
- Aksesibilitas dapat dengan mudah dikontrol.
- Perlindungan terhadap server terutama server data lebih terjamin.
Skema Monitoring detektor kebakaran dengan codeIgniter
Komponen yang digunakan :
- Arduino Uno
- ESP8266
- Flame detector
- Sensor asap MQ7
- Sensor suhu dht11
- Relay
- Buzzer
Sketch / koding monitoring detektor kebakaran esp8266 – WebServer.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 | #include "WiFiEsp.h" #include <SoftwareSerial.h> #include "DHT.h" char ssid[] = "****" ; // Isi dengan nama profil Wifi char pass[] = "********" ; // password wifi char server[] = "x.x.x.x" ; long waktuMintaData = 1000; //minta data setiap 1000ms #define pinFlame A0 #define pinMQ A1 #define pinDHT A2 #define pinBuzzer 8 #define pinRelay 9 float setSuhu = 31.0; String Respon = "" ; long waktuMulai; bool responDariServer = false ; bool prosesKirimDataKeServer = false ; WiFiEspClient client; int status = WL_IDLE_STATUS; SoftwareSerial wifi(2,3); DHT dht(pinDHT, DHT11); void setup() { pinMode(pinFlame, INPUT_PULLUP); pinMode(pinMQ, INPUT_PULLUP); pinMode(pinDHT, INPUT_PULLUP); pinMode(pinBuzzer, OUTPUT); digitalWrite(pinRelay, HIGH); pinMode(pinRelay, OUTPUT); Serial.begin(115200); wifi.begin(115200); WiFi.init(&wifi); // check for the presence of the shield if (WiFi.status() == WL_NO_SHIELD) { Serial.println( "WiFi shield not present" ); // don't continue while ( true ); } // attempt to connect to WiFi network while ( status != WL_CONNECTED) { Serial.print( "Attempting to connect to WPA SSID: " ); Serial.println(ssid); // Connect to WPA/WPA2 network status = WiFi.begin(ssid, pass); } // you're connected now, so print out the data Serial.println( "You're connected to the network" ); printWifiStatus(); dht.begin(); waktuMulai = millis(); } void loop() { float suhu = dht.readTemperature(); //print status Serial.println(); Serial.print( "Api = " ); Serial.println(digitalRead(pinFlame)); Serial.print( "Asap = " ); Serial.println(digitalRead(pinMQ)); Serial.print( "suhu = " ); Serial.println(suhu); if (!digitalRead(pinFlame) && !digitalRead(pinMQ) && (suhu < setSuhu)) { digitalWrite(pinRelay, HIGH); digitalWrite(pinBuzzer, LOW); } if (digitalRead(pinFlame)) { digitalWrite(pinRelay, LOW); digitalWrite(pinBuzzer, HIGH); } if (digitalRead(pinMQ)) { digitalWrite(pinRelay, LOW); digitalWrite(pinBuzzer, HIGH); } if (suhu >= setSuhu) { digitalWrite(pinBuzzer, HIGH); } //kirim data if (waktuMintaData < millis() - waktuMulai) { waktuMulai = millis(); prosesKirimDataKeServer = kirimDataKeServer(); } while (client.available()) { char c = client.read(); Respon += c; } Serial.print( "prosesKirimDataKeServer = " ); Serial.println(prosesKirimDataKeServer); if (!client.connected() && prosesKirimDataKeServer) { Serial.println( "Disconnecting from server..." ); client.stop(); responDariServer = true ; prosesKirimDataKeServer = false ; } // penanganan data yang diterima dari server if (responDariServer) { responDariServer = false ; Serial.println(Respon); int posisiData = Respon.indexOf( "\r\n\r\n" ); String Data = Respon.substring(posisiData+4); Data.trim(); String variabel; String nilai; Serial.println( "Data dari server" ); posisiData = Data.indexOf( '=' ); if (posisiData > 0) { variabel = Data.substring(0,posisiData); nilai = Data.substring(posisiData+1); //===========Penanganan respon disini if (variabel == "setSuhu" ) { setSuhu = nilai.toFloat(); } // Serial.print(variabel); // Serial.print(" = "); // Serial.println(nilai); } Respon = "" ; } } bool kirimDataKeServer() { Serial.println(); Serial.println( "Starting connection to server..." ); // if you get a connection, report back via serial if (client.connect(server, 80)) { Serial.println( "Connected to server" ); // Make a HTTP request client.print( "GET /index.php/databaseArduino/dariArduino" ); client.print( "?Api=" ); client.print(digitalRead(pinFlame)); client.print( "&Asap=" ); client.print(digitalRead(pinMQ)); client.print( "&Suhu=" ); client.print(dht.readTemperature()); client.println( " HTTP/1.1" ); client.print( "Host: " ); client.println(server); client.println( "Connection: close" ); client.println(); return true ; } return false ; } void printWifiStatus() { // print the SSID of the network you're attached to Serial.print( "SSID: " ); Serial.println(WiFi.SSID()); // print your WiFi shield's IP address IPAddress ip = WiFi.localIP(); Serial.print( "IP Address: " ); Serial.println(ip); // print the received signal strength long rssi = WiFi.RSSI(); Serial.print( "Signal strength (RSSI):" ); Serial.print(rssi); Serial.println( " dBm" ); IPAddress gateway = WiFi.gatewayIP(); Serial.print( "gateway:" ); Serial.print(gateway); Serial.println( " " ); } |
program codeIgniter untuk monitoring data sensor arduino:
databaseArduino.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | <?php class databaseArduino extends CI_Controller { public function __construct() { parent::__construct(); } public function dariBrowser() { $this ->load->model( 'Model_databaseArduino' ); $this ->Model_databaseArduino->salinDataDariBrowser(); $data [ 'dataSensor' ] = $this ->Model_databaseArduino->ambilDataDariArduino(); $data [ 'dataParameter' ] = $this ->Model_databaseArduino->ambilDataDariBrowser(); $this ->load->view( "data_sensor" , $data ); } public function dariArduino() { $this ->load->model( 'Model_databaseArduino' ); $this ->Model_databaseArduino->salinDataDariArduino(); $data [ 'dataParameter' ] = $this ->Model_databaseArduino->ambilDataDariBrowser(); $this ->load->view( "data_parameter" , $data ); } } ?> |
Model_databaseArduino.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | <?php class Model_databaseArduino extends CI_Model { public $title ; public $content ; public $date ; public function ambilDataDariArduino() { $this ->load->database(); $query = $this ->db->query("SELECT * FROM ( SELECT * FROM `data_sensor` ORDER BY `nomor` DESC LIMIT 10 ) sub ORDER BY `nomor` ASC"); $this ->db->close(); return $query ->result(); } public function salinDataDariArduino() { date_default_timezone_set( 'Asia/Jakarta' ); # add your city to set local time zone $now = date ( 'Y-m-d H:i:s' ); $this ->load->database(); $this ->db->set( 'waktu' , $now ); $this ->db->set( 'api' , $this ->input->get( 'Api' )); $this ->db->set( 'asap' , $this ->input->get( 'Asap' )); $this ->db->set( 'suhu' , $this ->input->get( 'Suhu' )); $this ->db->insert( 'data_sensor' ); $this ->db->close(); } public function ambilDataDariBrowser() { $this ->load->database(); $query = $this ->db->query( "SELECT * FROM `data_parameter` ORDER BY `nomor` DESC LIMIT 1" ); $this ->db->close(); return $query ->row(); } public function salinDataDariBrowser() { date_default_timezone_set( 'Asia/Jakarta' ); # add your city to set local time zone $now = date ( 'Y-m-d H:i:s' ); $this ->load->database(); $this ->db->set( 'waktu' , $now ); $this ->db->set( 'setSuhu' , $this ->input->post( 'setSuhu' )); $this ->db->insert( 'data_parameter' ); $this ->db->close(); } } ?> |
data_sensor.php
1 2 3 4 5 6 7 8 9 | <?php defined( 'BASEPATH' ) OR exit ( 'No direct script access allowed' ); if (isset( $dataParameter )) { echo "setSuhu=" ; echo $dataParameter ->setSuhu; } ?> |
data_parameter.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 | <?php defined( 'BASEPATH' ) OR exit ( 'No direct script access allowed' ); ?> <!DOCTYPE html> <html lang= "en" > <head> <meta charset= "utf-8" > <title>Welcome to CodeIgniter</title> <style type= "text/css" > ::selection { background-color: #E13300; color: white; } ::-moz-selection { background-color: #E13300; color: white; } body { background-color: #fff; margin: 40px; font: 13px/20px normal Helvetica, Arial, sans-serif; color: #4F5155; } a { color: #003399; background-color: transparent; font-weight: normal; } h1 { color: #444; background-color: transparent; border-bottom: 1px solid #D0D0D0; font-size: 19px; font-weight: normal; margin: 0 0 14px 0; padding: 14px 15px 10px 15px; } code { font-family: Consolas, Monaco, Courier New, Courier, monospace; font-size: 12px; background-color: #f9f9f9; border: 1px solid #D0D0D0; color: #002166; display: block; margin: 14px 0 14px 0; padding: 12px 10px 12px 10px; } #body { margin: 0 15px 0 15px; } p.footer { text-align: right; font-size: 11px; border-top: 1px solid #D0D0D0; line-height: 32px; padding: 0 10px 0 10px; margin: 20px 0 0 0; } #container { margin: 10px; border: 1px solid #D0D0D0; box-shadow: 0 0 8px #D0D0D0; } </style> </head> <body> <!-- <form action= "/form/data_submitted" method= "get" > User Name: <input type= "text" name= "u_name" placeholder= "Please Enter User Name" class = "input_box" > <br> User email: <input type= "text" name= "u_email" placeholder= "Please Enter Email Address" class = "input_box" > <input type= "submit" value= "Submit" class = "submit" > </form> --> <?php // echo $this->input->post('setSuhu'); echo form_open( 'databaseArduino/dariBrowser' ); if (isset( $dataParameter ->setSuhu)) { echo form_input( 'setSuhu' , $dataParameter ->setSuhu); } else { echo form_input( 'setSuhu' , '30.0' ); } echo form_submit( 'suhuSubmit' , 'Set Temperatur' ); echo form_close(); echo "<br>" ; echo "<strong>Data pembacaan sensor</strong>" ; echo "<br>" ; echo "<table>" ; echo "<tr>" ; echo "<td width='50'>Nomor</td>" ; echo "<td width='200'>Waktu</td>" ; echo "<td width='50'>Api</td>" ; echo "<td width='50'>Asap</td>" ; echo "<td width='50'>Suhu</td>" ; echo "</tr>" ; foreach ( $dataSensor as $row ) { echo "<tr>" ; echo "<td>" . $row ->nomor. "</td>" ; echo "<td>" . $row ->waktu. "</td>" ; echo "<td>" . $row ->api. "</td>" ; echo "<td>" . $row ->asap. "</td>" ; echo "<td>" . $row ->suhu. "</td>" ; echo "</tr>" ; } echo "</table>" ; ?> </body> </html> |
file server : htdocs.zip