-->

Program monitoring dht11 using arduino Pro mini to database mysql


Now, we continue to the next step. That is programming the arduino using Arduino IDE apps. If you do’nt have just download it here


In arduino sketch you can write this script :
For DHT11 library, click here
I hope you’re not lazy to write this program. If you’re lazy just scroll down and click the download file

#include <SoftwareSerial.h> // using library sofwareserial
#include <dht.h>   // using library DHT

#define DHT11_PIN 12  
SoftwareSerial wifi(11, 10 ); // RX, TX

dht sensor;
String ip_host ="192.168.137.103";  // your ip address
int nilai_1, nilai_2;
boolean parsing = false;

#define SSID_WIFI "XXXX" //your SSID name
#define PASSWORD_WIFI "triplemultiple" //your Wifi password

#define DEBUG true

void konek_ke_wifi() {
  String data = "AT+CWJAP=\"";
  data += SSID_WIFI;
  data += "\",\"";
  data += PASSWORD_WIFI;
  data += "\"";
  data += "\r\n";
  kirimPerintah(data, 10000, DEBUG);
}

void setup() {
  // put your setup code here, to run once:
  wifi.begin(9600);
  Serial.begin(9600);
  kirimPerintah("AT+RST\r\n", 2000, DEBUG);
  kirimPerintah("AT+CWMODE=3\r\n", 1000, DEBUG); // Set ke AP / Client
  konek_ke_wifi();
  kirimPerintah("AT+CIPMUX=2\r\n", 1000, DEBUG);
  kirimPerintah("AT+CIFSR\r\n", 500, DEBUG);
  Serial.println("Arduino Kontrol Wifi SIAP !!");
  int chk = sensor.read11(DHT11_PIN);
  nilai_1 = sensor.temperature;
  nilai_2 = sensor.humidity;
  
  pinMode(13, OUTPUT);
}

String data;

void loop() {
  Serial.print("Temperature = ");
  Serial.println(nilai_1 );
  Serial.print("Humidity = ");
  Serial.println(nilai_2);
  delay(2000);
  kirim_data();
}

String kirimPerintah(String perintah, const int waktu, boolean debug) {

  String respon = "";
  wifi.print(perintah);

  long time = millis();
  while ((time + waktu) > millis())
  {
    while (wifi.available())
    {
      char c = wifi.read();
      respon += c;
    }
  }

  if (debug) {
    Serial.print(respon);
  }
  return respon;
}

void kirim_data(){
  String cmd = "AT+CIPSTART=\"TCP\",\"";
  cmd += ip_host;
  cmd += "\",80";
  wifi.println(cmd);
  if (wifi.find("Error")) {
    Serial.println("Koneksi eror");
    return;
  }
  cmd = "GET /learning_php/index.php?temp1="; // sending data to mysql
  cmd += String (nilai_1);
  cmd += "&hum1=";
  cmd += String (nilai_2);

  cmd += "HTTP/1.0/1/\r\n";
  cmd += "\r\n";
  wifi.print("AT+CIPSEND=");
  wifi.println(cmd.length());
  if (wifi.find(">")) {
    Serial.print(">");
  } else {
    wifi.println("AT+CIPCLOSE");
    Serial.println("Koneksi Timeout");
    delay(5000);
    return;
  }
 kirimPerintah(cmd, 2000, DEBUG);
}


After writing that’s program you can upload the program to arduino hardware.
Don’t forget to change the SSID,Password wifi, ip adress, and host for upload your data.

The next step is making the php script for upload the data. Continue to Making connection arduino to mysql using php


Download the script in this link

this link program is access to folder learning_php and file of index,php. if you don't understand that's script is taken from this link

http://localhost/learning_php/index.php?temp1=28&hum1=80

cmd = "GET /learning_php/index.php?temp1="; // sending data to mysql
  cmd += String (nilai_1);
  cmd += "&hum1=";
  cmd += String (nilai_2);

Berlangganan update artikel terbaru via email:

0 Response to "Program monitoring dht11 using arduino Pro mini to database mysql"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel