Reading Requirement:
-
Register (Geeknesia)
-
Create Project (Geeknesia)
-
Create Gateway (Geeknesia)
- Create device (Geeknesia)
Pada tutorial ini akan dijelaskan cara menghubungkan Arduino + SIM800L ke Geeknesia, dengan menggunakan Sim Card, anda bisa menghubungkan device ke Geeknesia.
Alat dan Bahan yang diperlukan:
- Arduino.
- SIM800L.
- SIM Card (Bebas).
- Kabel Jumper.
- Baterai 3.7v.
Arduino
|
SIM800L
|
Kabel Jumper
|
Baterai
|
Tahap 1
Pastikan anda sudah membuat Project,Gateway dan Device pada akun Geeknsia anda,mengenai project ini.
Tahap2
Setelah menyiapkan alat dan bahan, sekarang kita coba untuk menghubungkan Arduino ke SIM800L, ikuti gambar wiring dibawah ini:
Jangan lupa masukan SIM Card anda seperti gambar di bawah ini:
Gunakan Micro SIM Card.Gambar Hardware/Device
Tahap 3
Setelah komponen dirangkaikan, buatlah script/code pada arduino seperti contoh code dibawah ini:
Code:
#include <AltSoftSerial.h> AltSoftSerial m2m_gprs; int8_t answer; int onModulePin = 2; char aux_str[100]; char pin[] = ""; //isi jika ada settingan Pin pada SIM Card char apn[] = "3data"; //Isi Apn sesuai SIM Card yang dipakai char user_name[] = "3data"; //Isi Username sesuai SIM Card yang dipakai char password[] = "3data"; //Isi Password sesuai SIM Card yang dipakai char IP_address[] = "geeknesia.com"; char port[] = "80"; //Port Geeknesia int arah_angin, nilai_ppm; float kecepatan_angin, suhu_udara, kelembaban_udara, tegangan_backup, curah_hujan; long tekanan_udara; char arah_angin_Ar[10]; char kecepatan_angin_Ar[10]; char nilai_ppm_Ar[10]; char tekanan_udara_Ar[10]; char suhu_udara_Ar[10]; char kelembaban_udara_Ar[10]; char tegangan_backup_Ar[10]; char curah_hujan_Ar[10]; void setup() { Serial.begin(9600); m2m_gprs.begin(9600); m2m_gprs.println("Starting..."); delay(3000); snprintf(aux_str, sizeof(aux_str), "AT+CPIN=%s", pin); sendATcommand(aux_str, "OK", 2000); delay(3000); m2m_gprs.println("Connecting to the network..."); while ( sendATcommand2("AT+CREG?", "+CREG: 0,1", "+CREG: 0,5", 1000) == 0 ); } void loop() { nilai_ppm = 123; //dummy suhu_udara = 123.0; //dummy dtostrf(suhu_udara, 5, 2, suhu_udara_Ar); update(); delay(2000); } void update() { if (sendATcommand2("AT+CIPMUX=0", "OK", "ERROR", 1000) == 1) { while (sendATcommand("AT+CIPSTATUS", "INITIAL", 500) == 0 ); delay(5000); snprintf(aux_str, sizeof(aux_str), "AT+CSTT=\"%s\",\"%s\",\"%s\"", apn, user_name, password); if (sendATcommand2(aux_str, "OK", "ERROR", 30000) == 1) { while (sendATcommand("AT+CIPSTATUS", "START", 500) == 0 ); delay(5000); if (sendATcommand2("AT+CIICR", "OK", "ERROR", 30000) == 1) { while (sendATcommand("AT+CIPSTATUS", "GPRSACT", 500) == 0 ); delay(5000); if (sendATcommand2("AT+CIFSR", ".", "ERROR", 10000) == 1) { while (sendATcommand("AT+CIPSTATUS", "IP STATUS", 500) == 0 ); delay(5000); m2m_gprs.println("Opening TCP"); snprintf(aux_str, sizeof(aux_str), "AT+CIPSTART=\"TCP\",\"%s\",\"%s\"", IP_address, port); if (sendATcommand2(aux_str, "CONNECT OK", "CONNECT FAIL", 30000) == 1) { m2m_gprs.println("Connected"); String ip_data = "GET /api/data?api_key=dbabcff8c257480ae6b251cee02xxxxx&attributes={"; ip_data += "\"PPM\":" + String(nilai_ppm) + ","; ip_data += "\"Suhu\":" + String(suhu_udara_Ar); ip_data += "}"; ip_data += "\r\n\r\n"; sprintf(aux_str, "AT+CIPSEND=%d", ip_data.length()); if (sendATcommand2(aux_str, ">", "ERROR", 10000) == 1) { m2m_gprs.print(ip_data); delay(5000); } sendATcommand2("AT+CIPCLOSE", "CLOSE OK", "ERROR", 10000); } else { m2m_gprs.println("Error opening the connection"); } } else { m2m_gprs.println("Error getting the IP address"); } } else { m2m_gprs.println("Error bring up wireless connection"); } } else { m2m_gprs.println("Error setting the APN"); } } else { m2m_gprs.println("Error setting the single connection"); } sendATcommand2("AT+CIPSHUT", "OK", "ERROR", 10000); delay(10000); } int8_t sendATcommand(char* ATcommand, char* expected_answer, unsigned int timeout) { uint8_t x = 0, answer = 0; char response[100]; unsigned long previous; memset(response, '\0', 100); delay(100); while ( m2m_gprs.available() > 0) m2m_gprs.read(); m2m_gprs.println(ATcommand); x = 0; previous = millis(); do { if (m2m_gprs.available() != 0) { response[x] = m2m_gprs.read(); x++; if (strstr(response, expected_answer) != NULL) { answer = 1; } } } while ((answer == 0) && ((millis() - previous) < timeout)); return answer; } int8_t sendATcommand2(char* ATcommand, char* expected_answer1, char* expected_answer2, unsigned int timeout) { uint8_t x = 0, answer = 0; char response[100]; unsigned long previous; memset(response, '\0', 100); delay(100); while ( m2m_gprs.available() > 0) m2m_gprs.read(); m2m_gprs.println(ATcommand); x = 0; previous = millis(); do { if (m2m_gprs.available() != 0) { response[x] = m2m_gprs.read(); x++; if (strstr(response, expected_answer1) != NULL) { answer = 1; } else if (strstr(response, expected_answer2) != NULL) { answer = 2; } } } while ((answer == 0) && ((millis() - previous) < timeout)); return answer; }
Untuk settingan SIM Card, sesuaikan dengan SIM Card yang anda gunakan, untuk melihat settingan SIM Card bisa dilihat lewat handphone atau cari informasi lewat media internet.
Upload code yang telah dibuat ke arduino.
Tahap 4
Kemudian buka kembali Project yang telah dibuat pada akun Geeknesia anda.