Translate

Menampilkan Longitude dan Latitude GPS Neo 6M Ublox ke LCD OLED ARDUINO

Menampilkan Longitude dan Latitude GPS Neo 6M Ublox ke LCD OLED ARDUINO

         Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang bisa mendeteksi lokasi menggunakan modul GPS Neo Ublok 6M yang ditampilkan ke lcd OLED berupa latitude dan longitudenya. untuk lebih jelasnya berikut adalah komponen dan programnya.


a. Komponen yang dipakai



b. Program Arduino IDE

 //vcc pada GPS modul adalah 3,3 volt
/*********************
 *10 to GPS Module TX*
 *09 to GPS Module RX*
 *********************/

#include <Wire.h>  // i2C Conection Library
#include <SoftwareSerial.h>
#include <TinyGPS.h>
#include "Adafruit_GFX.h"
#include "OakOLED.h"

SoftwareSerial mySerial(10, 11);
TinyGPS gps;

OakOLED oled;

int dataadc;
long lat, lon;
float flat, flon;
unsigned long age, date, time, chars;
int year;
byte month, day, hour, minute, second, hundredths;
unsigned short sentences, failed;

void gpsdump(TinyGPS &gps);
void printFloat(double f, int digits = 2);

void setup()
{
    oled.begin();
    oled.display();
    
   // Oploen serial communications and wait for port to open:
  Serial.begin(9600);
  // set the data rate for the SoftwareSerial port
  mySerial.begin(9600);
  delay(1000);
  Serial.println("uBlox Neo 6M");
  Serial.print("Testing TinyGPS library v. "); Serial.println(TinyGPS::library_version());
  Serial.println("by Mikal Hart");
  Serial.println();
  Serial.print("Sizeof(gpsobject) = ");
  Serial.println(sizeof(TinyGPS));
  Serial.println();
}

void loop() // run over and over
{

  dataadc = analogRead(A0);
 
  bool newdata = false;
  unsigned long start = millis();
  // Every 5 seconds we print an update
  while (millis() - start < 5000)
  {
    if (mySerial.available())
    {
      char c = mySerial.read();
      //Serial.print(c);  // uncomment to see raw GPS data
      if (gps.encode(c))
      {
        newdata = true;
        break;  // uncomment to print new data immediately!
      }
    }
  }
  if (newdata)
  {
    Serial.println("Acquired Data");
    Serial.println("-------------");
    gpsdump(gps);
    Serial.println("-------------");
    Serial.println();
  }
}

void gpsdump(TinyGPS &gps)
{
 
  gps.get_position(&lat, &lon, &age);
  Serial.print("Lat/Long(10^-5 deg): "); Serial.print(lat); Serial.print(", "); Serial.print(lon);
  Serial.print(" Fix age: "); Serial.print(age); Serial.println("ms.");
  gps.f_get_position(&flat, &flon, &age);
  Serial.print("Lat/Long(float): "); printFloat(flat, 5); Serial.print(", "); printFloat(flon, 5);
  Serial.print(" Fix age: "); Serial.print(age); Serial.println("ms.");

  //oled.clearDisplay();
  oled.setTextSize(1);
  oled.setTextColor(1);
  oled.setCursor(0, 0);
  oled.print("LAT: ");
  oled.println(flat, 5);

  oled.setTextSize(1);
  oled.setTextColor(1);
  oled.setCursor(0, 16);
  oled.print("LONG: ");
  oled.println(flon, 5);

  oled.setTextSize(1);
  oled.setTextColor(1);
  oled.setCursor(0, 32);
  oled.print("HUM: ");
  oled.println(dataadc);
  oled.display();

}

void printFloat(double number, int digits)
{
  // Handle negative numbers
  if (number < 0.0)
  {
     Serial.print('-');
     number = -number;
  }

  // Round correctly so that print(1.999, 2) prints as "2.00"
  double rounding = 0.5;
  for (uint8_t i=0; i<digits; ++i)
  rounding /= 10.0;
  number += rounding;

  // Extract the integer part of the number and print it
  unsigned long int_part = (unsigned long)number;
  double remainder = number - (double)int_part;
  Serial.print(int_part);

  // Print the decimal point, but only if there are digits beyond
  if (digits > 0)
    Serial.print(".");

  // Extract digits from the remainder one at a time
  while (digits-- > 0)
  {
    remainder *= 10.0;
    int toPrint = int(remainder);
    Serial.print(toPrint);
    remainder -= toPrint;
  }
}



c. VIDEO HASILNYA



 

DETEKSI LAMPU PLN ON/OFF LALU HIDUPKAN RELAY ON/OFF

DETEKSI LAMPU PLN ON/OFF LALU HIDUPKAN RELAY ON/OFF

         Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang dapat mendeteksi tegangan PLN 220v yang mana jika nanti listrik PLN off maka akan menghidupkan relay, lalu dari relay tersebut dapat dihubungkan ke lampu emergency atau genset. untuk lebih jelasnya berikut adalah koding dan komponenya.

 

a. Komponen yang dipakai


 

b. Program Arduino IDE

#include <PZEM004Tv30.h>
#include <Wire.h>  
#include <LiquidCrystal_I2C.h>  
PZEM004Tv30 pzem(2, 3);
LiquidCrystal_I2C lcd(0x27, 16, 2);

int relay1 = 4;
int voltage;

int tegangan;
int arus;
int daya;
int kwh;

void setup() {
  Serial.begin(9600);
  lcd.begin();
  lcd.clear();
  lcd.noCursor();
  pinMode(relay1,OUTPUT);
  digitalWrite(relay1,HIGH); //off
}

void loop() {

  voltage = pzem.voltage();

  lcd.setCursor(0, 0);
  lcd.print("V: ");
  lcd.print(voltage);
  lcd.print("   ");

if(voltage >= 100){
  digitalWrite(relay1,HIGH); //off
}

if(voltage <= 100){
  digitalWrite(relay1,LOW); //on
}


delay(1000);
}

 

 

c. VIDEO HASILNYA


Monitor Suhu Kelembaban ONLINE 2 Node ESP8266 Thingspeak Penampil DMD P10 Arduino

Monitor Suhu Kelembaban ONLINE 2 Node ESP8266 Thingspeak Penampil DMD P10 Arduino

         Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang dapat memonitor 2 ruangan yang jaraknya berjauhan,  parameter yang dimonitor adalah suhu dan kelembaban ruangan, tampilan angka berada di ruang kontrol yang jaraknya juga berjauhan dengan ruangan yang dimonitor untuk itu project ini menggunakan internet dan server Thingspeak untuk transfer datanya. untuk lebih jelasnya berikut adalah koding dan komponennya.

 

a. Komponen yang dipakai


b. Program Receiver Arduino Uno

#include <Wire.h>
#include <Keypad.h>
#include <SPI.h>        //SPI.h must be included as DMD is written by SPI (the IDE complains otherwise)
#include <DMD.h>        //Library DMD yang menyediakan fungsi penampilan teks, gambar dsb
#include <TimerOne.h>   //Library peripheral Timer1 untuk menjalankan prosedur pindai panel DMD
#include <Time.h>     //Library waktu yang menyediakan tipe data, struktur, dan obyek waktu
#include "Arial_black_16.h"
#include "Arial_Black_16_ISO_8859_1.h"
#include "Arial14.h"
#include "DejaVuSans9.h"
#include "Droid_Sans_12.h"
#include "Droid_Sans_16.h"
#include "DejaVuSansItalic9.h"
#include "Mono5x7.h"
#include "SystemFont5x7.h"
#include <DS3231.h>
#include <LiquidCrystal_I2C.h>  
LiquidCrystal_I2C lcd(0x27, 16, 2);

#define WAKTU_TAMPIL_JAM      10    //detik
#define WAKTU_TAMPIL_KALENDAR 5     //detik

//Isi dengan jumlah panel DMD yang di susun dalam kolom dan baris
#define DISPLAY_COLUMN_COUNT  4
#define DISPLAY_ROW_COUNT     1

#define PIXELS_PER_COLUMN    32
#define PIXELS_PER_ROW       16

DMD dmd(DISPLAY_COLUMN_COUNT, DISPLAY_ROW_COUNT);
unsigned char show = 0;

char lineBuff[20];
char lineBuff2[20];
 
char customKey;
const byte ROWS = 4;
const byte COLS = 4;

char keys[ROWS][COLS] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};

byte rowPins[ROWS] = {A3,A2,A1,A0}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {5,4,3,2}; //connect to the column pinouts of the keypad

//initialize an instance of class NewKeypad
Keypad customKeypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS);

long batasmaxtemp;
long batasmaxtemp2;
long batasmintemp;
long batasmintemp2;

long batashum;
int suhu1;
int kelembaban1;
int suhu2;
int kelembaban2;

int savesuhu1;
int savekelembaban1;
int savesuhu2;
int savekelembaban2;

String dataIn;
String dt[10];
int i;
boolean parsing=false;
int datain1;
int datain2;
int datain3;
int datain4;
int relay = 10;
int relay2 = 12;
char lineBuffx1[20];
char lineBuffx2[20];
char lineBuffz1[20];
char lineBuffz2[20];

DS3231  rtc(SDA, SCL);
Time  t;

void ScanDMD()
{
  dmd.scanDisplayBySPI();
}

void setup(){
 
lcd.begin();
lcd.noCursor();
lcd.clear();
Serial.begin(9600);
dataIn="";

pinMode(relay,OUTPUT);
digitalWrite(relay,HIGH);
pinMode(12,OUTPUT);
digitalWrite(12,HIGH);

dmd.clearScreen( true );   //true is normal (all pixels off), false is negative (all pixels on)

//initialize TimerOne's interrupt/CPU usage used to scan and refresh the display
Timer1.initialize( 1000 );           //period in microseconds to call ScanDMD. Anything longer than 5000 (5ms) and you can see flicker.
Timer1.attachInterrupt( ScanDMD );   //attach the Timer1 interrupt to ScanDMD which goes to dmd.scanDisplayBySPI()
 
//clear/init the DMD pixels held in RAM
dmd.clearScreen( true );
//clear/init the DMD pixels held in RAM
dmd.clearScreen( true );
rtc.begin();
//rtc.setDOW(FRIDAY);     // Set Day-of-Week to SUNDAY
//rtc.setTime(15, 17, 0);     // Set the time to 12:00:00 (24hr format)
//rtc.setDate(20, 1, 2022);    
}


void loop(){
t = rtc.getTime();

customKey = customKeypad.getKey();

if(customKey == 'A'){
lcd.clear();
delay(200);
batasmaxtemp = 0;
batasmintemp = 0;
inputbatasmaxsuhu();
inputbatasminsuhu();
}

if(customKey == 'B'){
lcd.clear();
delay(200);
batasmaxtemp2 = 0;
batasmintemp2 = 0;
inputbatasmaxsuhu2();
inputbatasminsuhu2();
}

 while(Serial.available()>0) {
//   dataIn="";
    char inChar = (char)Serial.read();
    dataIn += inChar;
    if (inChar == '\n') {
    parsing = true;
  }
}

if(parsing){
  parsingData();
}

lcd.setCursor(0,0);
lcd.print("S1:");
lcd.print(savesuhu1);
lcd.print("/");
lcd.print(savekelembaban1);
lcd.print(" ");
lcd.print(batasmintemp);
lcd.print("/");
lcd.print(batasmaxtemp);

lcd.setCursor(0,1);
lcd.print("S2:");
lcd.print(savesuhu2);
lcd.print("/");
lcd.print(savekelembaban2);
lcd.print(" ");
lcd.print(batasmintemp2);
lcd.print("/");
lcd.print(batasmaxtemp2);

sprintf(lineBuff2, "%d:%d ", savesuhu1, savekelembaban1);
dmd.selectFont(Droid_Sans_12);
dmd.drawString( 3,  3, lineBuff2, strlen(lineBuff2), GRAPHICS_NORMAL);

sprintf(lineBuff, "%d:%d ", savesuhu2, savekelembaban2);
dmd.selectFont(Droid_Sans_12);
dmd.drawString( 37,  3, lineBuff, strlen(lineBuff), GRAPHICS_NORMAL);  

sprintf(lineBuffx1, "%d:%d", t.hour, t.min);
sprintf(lineBuffx2, "%d ", t.sec);

dmd.selectFont(DejaVuSans9);
dmd.selectFont(Mono5x7);
dmd.drawString( 65,  1, lineBuffx1, strlen(lineBuffx1), GRAPHICS_NORMAL);  
dmd.drawString( 75,  8, lineBuffx2, strlen(lineBuffx2), GRAPHICS_NORMAL);

sprintf(lineBuffz1,"RUANG");
sprintf(lineBuffz2,"OBAT");
dmd.selectFont(DejaVuSans9);
dmd.selectFont(Mono5x7);
dmd.drawString( 95,  1, lineBuffz1, strlen(lineBuffz1), GRAPHICS_NORMAL);  
dmd.drawString( 95,  8, lineBuffz2, strlen(lineBuffz2), GRAPHICS_NORMAL);  

 
if((savesuhu1 > batasmaxtemp)&&(batasmaxtemp > 0)){
  digitalWrite(relay,LOW);
}

if((savesuhu1 < batasmintemp)&&(batasmintemp > 0)){
  digitalWrite(relay,LOW);
}

if((savesuhu2 > batasmaxtemp2)&&(batasmaxtemp2 > 0)){
  digitalWrite(relay,LOW);
}

if((savesuhu2 < batasmintemp2)&&(batasmintemp2 > 0)){
  digitalWrite(relay,LOW);
}

if((savesuhu1 > batasmintemp)&&(savesuhu1 < batasmaxtemp)&&(savesuhu2 > batasmintemp2)&&(savesuhu2 < batasmaxtemp2)){
  digitalWrite(relay,HIGH);
}

delay(1000);
//dmd.clearScreen( true );   //true is normal (all pixels off), false is negative (all pixels on)

}


void parsingData(){
int j=0;

//kirim data yang telah diterima sebelumnya
//Serial.print("data masuk : ");
//Serial.print(dataIn);
//Serial.print("\n");

//inisialisasi variabel, (reset isi variabel)
dt[j]="";
//proses parsing data
for(i=1;i<dataIn.length();i++){
//pengecekan tiap karakter dengan karakter (#) dan (,)
if ((dataIn[i] == '#') || (dataIn[i] == ','))
{
//increment variabel j, digunakan untuk merubah index array penampung
j++;
dt[j]="";       //inisialisasi variabel array dt[j]
}
else
{
//proses tampung data saat pengecekan karakter selesai.
dt[j] = dt[j] + dataIn[i];
}
}

datain1 = dt[0].toInt();
datain2 = dt[1].toInt();
datain3 = dt[2].toInt();
datain4 = dt[3].toInt();

/*
//kirim data hasil parsing
Serial.print("data 1 : ");
Serial.print(datain1);
Serial.print("\n");
Serial.print("data 2 : ");
Serial.print(datain2);
Serial.print("\n");
Serial.print("data 3 : ");
Serial.print(datain3);
Serial.print("\n");
Serial.print("data 4 : ");
Serial.print(datain4);
Serial.print("\n");
*/

suhu1 = datain1 / 1;
kelembaban1 = datain2 / 1;
suhu2 = datain3 / 1;
kelembaban2 = datain4 / 1;

if(suhu1 > 0){
  savesuhu1 = suhu1;
}

if(kelembaban1 > 0){
  savekelembaban1 = kelembaban1;
}

if(suhu2 > 0){
  savesuhu2 = suhu2;
}

if(kelembaban2 > 0){
  savekelembaban2 = kelembaban2;
}

 
}



void inputbatasmaxsuhu(){
 
lcd.setCursor(0,0);
lcd.print("MAX Suhu 1:");
        
customKey = customKeypad.getKey();

if(customKey >= '0' && customKey <= '9')
  {
      batasmaxtemp = batasmaxtemp * 10 + (customKey - '0');
      lcd.setCursor(0,1);
      lcd.print(batasmaxtemp);
  }

if(customKey == 'D'){
lcd.clear();
delay(200);  
return;
}

if(customKey == 'C'){
lcd.clear();
delay(200);
batasmaxtemp = 0;
}
 
delay(200);
   
inputbatasmaxsuhu();  
}


void inputbatasminsuhu(){
 
lcd.setCursor(0,0);
lcd.print("MIN Suhu 1:");
        
customKey = customKeypad.getKey();

if(customKey >= '0' && customKey <= '9')
  {
      batasmintemp = batasmintemp * 10 + (customKey - '0');
      lcd.setCursor(0,1);
      lcd.print(batasmintemp);
  }

if(customKey == 'D'){
lcd.clear();
delay(200);  
return;
}

if(customKey == 'C'){
lcd.clear();
delay(200);
batasmintemp = 0;
}

delay(200);
   
inputbatasminsuhu();  
}


void inputbatasmaxsuhu2(){
 
lcd.setCursor(0,0);
lcd.print("MAX Suhu 2:");
        
customKey = customKeypad.getKey();

if(customKey >= '0' && customKey <= '9')
  {
      batasmaxtemp2 = batasmaxtemp2 * 10 + (customKey - '0');
      lcd.setCursor(0,1);
      lcd.print(batasmaxtemp2);
  }

if(customKey == 'D'){
lcd.clear();
delay(200);  
return;
}

if(customKey == 'C'){
lcd.clear();
delay(200);
batasmaxtemp2 = 0;
}
 
delay(200);
   
inputbatasmaxsuhu2();  
}


void inputbatasminsuhu2(){
 
lcd.setCursor(0,0);
lcd.print("MIN Suhu 2:");
        
customKey = customKeypad.getKey();

if(customKey >= '0' && customKey <= '9')
  {
      batasmintemp2 = batasmintemp2 * 10 + (customKey - '0');
      lcd.setCursor(0,1);
      lcd.print(batasmintemp2);
  }

if(customKey == 'D'){
lcd.clear();
delay(200);  
return;
}

if(customKey == 'C'){
lcd.clear();
delay(200);
batasmintemp2 = 0;
}
 
delay(200);
   
inputbatasminsuhu2();  
}
 


c. Program Receiver Nodemcu ESP8266

#include <Wire.h>
#include "ThingSpeak.h"
#include <ESP8266WiFi.h>
#include <LiquidCrystal_I2C.h>  
LiquidCrystal_I2C lcd(0x27, 16, 2);

unsigned long channel = 1740399;

String apiKey = "76HGJHE437KJLH98H";     
const char* resource = "/update?api_key=";

const char *ssid =  "wifikujoss";     
const char *pass =  "123456789";
const char* server = "api.thingspeak.com";

int suhu1;
int kelembaban1;
int suhu2;
int kelembaban2;

WiFiClient client;


void setup(){
 
lcd.begin();
lcd.noCursor();
lcd.clear();
Serial.begin(9600);

// Connect to WiFi network
  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);

  WiFi.begin(ssid, pass);

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");

while (WiFi.status() != WL_CONNECTED)
     {
            delay(500);
            Serial.print(".");
     }
      Serial.println("");
      Serial.println("WiFi connected");
      delay(100);

Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
Serial.print("Netmask: ");
Serial.println(WiFi.subnetMask());
Serial.print("Gateway: ");
Serial.println(WiFi.gatewayIP());
ThingSpeak.begin(client);
}


void loop(){

suhu1 = ThingSpeak.readFloatField(channel, 1);
kelembaban1 = ThingSpeak.readFloatField(channel, 2);
suhu2 = ThingSpeak.readFloatField(channel, 3);
kelembaban2 = ThingSpeak.readFloatField(channel, 4);

Serial.print("*");
Serial.print(suhu1);
Serial.print(",");
Serial.print(kelembaban1);
Serial.print(",");
Serial.print(suhu2);
Serial.print(",");
Serial.print(kelembaban2);
Serial.println("#");

delay(1000);  
}


 

d. Program Transmitter Ruangan 1

#include <Wire.h>
#include "ThingSpeak.h"
#include "DHT.h"
#include <ESP8266WiFi.h>
#include <LiquidCrystal_I2C.h>

#define DHTPIN 0         // PIN D3 (GPIO 0) dari NodeMCU terhubung dengan PIN Data dari DHT22
#define DHTTYPE DHT22     // Kita menggunakan tipe DHT22
DHT dht(DHTPIN, DHTTYPE); // Inisialisasi DHT22

LiquidCrystal_I2C lcd(0x27,16,2);

unsigned long channel = 1233456;

String apiKey = "76HGJHE437KJLH98H";     //  Enter your Write API key from ThingSpeak
const char* resource = "/update?api_key=";

const char *ssid =  "wifikujoss";     // replace with your wifi ssid and wpa2 key
const char *pass =  "123456789";
const char* server = "api.thingspeak.com";

float h;
float t;

WiFiClient client;

void setup(){

Serial.begin(115200);
delay(10);
lcd.begin(); //set lcd i2c
lcd.noCursor(); //biar gak ada cursor di lcd
lcd.clear(); //clear lcd
dht.begin();

       Serial.println("Connecting to ");
       Serial.println(ssid);

// Connect to WiFi network
  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);

  WiFi.begin(ssid, pass);

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");

while (WiFi.status() != WL_CONNECTED)
     {
            delay(500);
            Serial.print(".");
     }
      Serial.println("");
      Serial.println("WiFi connected");
      delay(100);

Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
Serial.print("Netmask: ");
Serial.println(WiFi.subnetMask());
Serial.print("Gateway: ");
Serial.println(WiFi.gatewayIP());
ThingSpeak.begin(client);
}



void loop(){

  h = dht.readHumidity();
  t = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit

lcd.setCursor(0, 0);
lcd.print("Temp: ");
lcd.print(t);
lcd.print(" C   ");
lcd.setCursor(0, 1);
lcd.print("Humi: ");
lcd.print(h);
lcd.print(" %   ");

  if (isnan(h) || isnan(t)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }


if (client.connect(server,80))   //   "184.106.153.149" or api.thingspeak.com
{
                            
                             String postStr = apiKey;
                             postStr +="&field1=";
                             postStr += String(t);
                             postStr += "\r\n\r\n";

                             client.print(String("GET ") + resource + apiKey + "&field1=" + t + "&field2=" + h + " HTTP/1.1\r\n" + "Host: " + server + "\r\n" + "Connection: close\r\n\r\n");
                             //client.print(String("GET ") + resource + apiKey + "&field1=" + t + " HTTP/1.1\r\n" + "Host: " + server + "\r\n" + "Connection: close\r\n\r\n");                             
                                        
                             client.print("Host: api.thingspeak.com\n");
                             client.print("Connection: close\n");
                             client.print("X-THINGSPEAKAPIKEY: "+apiKey+"\n");
                             client.print("Content-Type: application/x-www-form-urlencoded\n");
                             client.print("Content-Length: ");
                             client.print(postStr.length());
                             client.print("\n\n");
                             client.print(postStr);
                             
                             Serial.print("Temperature: ");
                             Serial.print(t);
                             Serial.print(" humidity: ");
                             Serial.print(h);
                             Serial.println(". Send to Thingspeak.");
                        }
                        
          client.stop();

          Serial.println("Waiting...");
// thingspeak needs minimum 15 sec delay between updates, i've set it to 30 seconds
  delay(5000);

}



e. Program Transmitter Ruangan 2

#include <Wire.h>
#include "ThingSpeak.h"
#include "DHT.h"
#include <ESP8266WiFi.h>
#include <LiquidCrystal_I2C.h>

#define DHTPIN 0         // PIN D3 (GPIO 0) dari NodeMCU terhubung dengan PIN Data dari DHT22
#define DHTTYPE DHT22     // Kita menggunakan tipe DHT22
DHT dht(DHTPIN, DHTTYPE); // Inisialisasi DHT22

LiquidCrystal_I2C lcd(0x27,16,2);

unsigned long channel = 1233456;

String apiKey = "76HGJHE437KJLH98H";     //  Enter your Write API key from ThingSpeak
const char* resource = "/update?api_key=";

const char *ssid =  "wifikujoss";     // replace with your wifi ssid and wpa2 key
const char *pass =  "123456789";
const char* server = "api.thingspeak.com";

float h;
float t;

WiFiClient client;

void setup(){

Serial.begin(115200);
delay(10);
lcd.begin(); //set lcd i2c
lcd.noCursor(); //biar gak ada cursor di lcd
lcd.clear(); //clear lcd
dht.begin();

       Serial.println("Connecting to ");
       Serial.println(ssid);

// Connect to WiFi network
  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);

  WiFi.begin(ssid, pass);

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");

while (WiFi.status() != WL_CONNECTED)
     {
            delay(500);
            Serial.print(".");
     }
      Serial.println("");
      Serial.println("WiFi connected");
      delay(100);

Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
Serial.print("Netmask: ");
Serial.println(WiFi.subnetMask());
Serial.print("Gateway: ");
Serial.println(WiFi.gatewayIP());
ThingSpeak.begin(client);
}



void loop(){

  h = dht.readHumidity();
  t = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit

lcd.setCursor(0, 0);
lcd.print("Temp: ");
lcd.print(t);
lcd.print(" C   ");
lcd.setCursor(0, 1);
lcd.print("Humi: ");
lcd.print(h);
lcd.print(" %   ");

  if (isnan(h) || isnan(t)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }


if (client.connect(server,80))   //   "184.106.153.149" or api.thingspeak.com
{
                            
                             String postStr = apiKey;
                             postStr +="&field3=";
                             postStr += String(t);
                             postStr += "\r\n\r\n";

                             client.print(String("GET ") + resource + apiKey + "&field3=" + t + "&field4=" + h + " HTTP/1.1\r\n" + "Host: " + server + "\r\n" + "Connection: close\r\n\r\n");
                             //client.print(String("GET ") + resource + apiKey + "&field1=" + t + " HTTP/1.1\r\n" + "Host: " + server + "\r\n" + "Connection: close\r\n\r\n");                             
                                        
                             client.print("Host: api.thingspeak.com\n");
                             client.print("Connection: close\n");
                             client.print("X-THINGSPEAKAPIKEY: "+apiKey+"\n");
                             client.print("Content-Type: application/x-www-form-urlencoded\n");
                             client.print("Content-Length: ");
                             client.print(postStr.length());
                             client.print("\n\n");
                             client.print(postStr);
                             
                             Serial.print("Temperature: ");
                             Serial.print(t);
                             Serial.print(" humidity: ");
                             Serial.print(h);
                             Serial.println(". Send to Thingspeak.");
                        }
                        
          client.stop();

          Serial.println("Waiting...");
// thingspeak needs minimum 15 sec delay between updates, i've set it to 30 seconds
  delay(5000);

}


 

f. VIDEO HASILNYA



Alat Monitor Kecepatan Angin (Anemometer) dann Arus DC INA219 Arduino

Alat Monitor Kecepatan Angin  (Anemometer) dann Arus DC INA219 Arduino
 

        Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang dapat digunakan untuk memonitor kecepatan angin dan arus dc dengan menggunakan Arduino, sensor yang digunakan yaitu sensor kecepatan angin dan INA219 untuk arus DC.untuk lebih jelasnya berikut adalah program dan komponennya.
 
 
 
a. Komponen yang dipakai


 
 
b. Program arduino IDE

#include <Wire.h>  // i2C Conection Library
#include <LiquidCrystal_I2C.h>  //i2C LCD Library
#include <Adafruit_INA219.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);

const int INA_addr = 0x40;
Adafruit_INA219 ina219(INA_addr);

// anemometer parameters
volatile byte rpmcount; // count signals
volatile unsigned long last_micros;
unsigned long timeold;
unsigned long timemeasure = 2.00; // seconds
int timetoSleep = 1;               // minutes
unsigned long sleepTime = 15;      // minutes
unsigned long timeNow;
int countThing = 0;
int GPIO_pulse = 2; // Arduino = D2
float rpm, rps;     // frequencies
float radius = 0.1; // meters - measure of the lenght of each the anemometer wing
float velocity_kmh; // km/h
float velocity_ms;  //m/s
float omega = 0;    // rad/s
float calibration_value = 2.0;
int buzm = 11; //pin buzzer
float arusdc;


void setup() {

Serial.begin(9600);
lcd.begin();
lcd.clear();
lcd.noCursor();
ina219.begin();
pinMode(buzm,OUTPUT);
digitalWrite(buzm,LOW);
pinMode(GPIO_pulse, INPUT_PULLUP);
digitalWrite(GPIO_pulse, LOW);

  detachInterrupt(digitalPinToInterrupt(GPIO_pulse));                         // force to initiate Interrupt on zero
  attachInterrupt(digitalPinToInterrupt(GPIO_pulse), rpm_anemometer, RISING); //Initialize the intterrupt pin
  rpmcount = 0;
  rpm = 0;
  timeold = 0;
  timeNow = 0;
}


void loop()
{
  //Measure RPM
  if ((millis() - timeold) >= timemeasure * 1000)
  {
    //countThing++;
    detachInterrupt(digitalPinToInterrupt(GPIO_pulse)); // Disable interrupt when calculating
    rps = float(rpmcount) / float(timemeasure);         // rotations per second
    rpm = 60 * rps;                                     // rotations per minute
    omega = 2 * PI * rps;                               // rad/s
    velocity_ms = omega * radius * calibration_value;   // m/s
    velocity_kmh = velocity_ms * 3.6;                   // km/h
        
    timeold = millis();
    rpmcount = 0;
    attachInterrupt(digitalPinToInterrupt(GPIO_pulse), rpm_anemometer, RISING); // enable interrupt
  }

arusdc = ina219.getCurrent_mA();
arusdc = arusdc /1000.0;
    
  lcd.setCursor(0, 0);
  lcd.print("Kec=");
  lcd.print(velocity_ms);
  lcd.print(" m/s ");

  lcd.setCursor(0, 1);
  lcd.print("I=");
  lcd.print(arusdc);
  lcd.print(" mA ");
 
delay(200);
}

void rpm_anemometer()
{
  if (long(micros() - last_micros) >= 5000)
  { // time to debounce measures
    rpmcount++;
    last_micros = micros();
  }
}


 
c. VIDEO HASILNYA
 

 
 
 

Monitor Suhu Kelembaban dan Kendali Lampu IOT Thingspeak

Monitor Suhu Kelembaban dan Kendali Lampu IOT Thingspeak
 

         Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang dapat memonitor suhu dan kelembaban serta bisa mengendalikan lampu atau device lain melalui ONLINE dengan server Thingspeak. untuk lebih jelasnya berikut adalah program dan komponennya.
 
 
a. Komponen
 

 
 
b. Program Arduino IDE
 
#include <Wire.h>
#include "ThingSpeak.h"
#include "DHT.h"
#include <ESP8266WiFi.h>
#include <LiquidCrystal_I2C.h>

#define DHTPIN 0         // PIN D3 (GPIO 0) dari NodeMCU terhubung dengan PIN Data dari DHT22
#define DHTTYPE DHT22     // Kita menggunakan tipe DHT22
DHT dht(DHTPIN, DHTTYPE); // Inisialisasi DHT22

LiquidCrystal_I2C lcd(0x27,16,2);

//change your channel number here
unsigned long channel = 2233667;

String apiKey = "HGKJ67576HJF3HGFJ7H";     //  Enter your Write API key from ThingSpeak
const char* resource = "/update?api_key=";

const char *ssid =  "hotspothpku";     // replace with your wifi ssid and wpa2 key
const char *pass =  "123456789";
const char* server = "api.thingspeak.com";

//2,3 and 4 are channel fields in thingspeak.
unsigned int flampu1 = 3;
unsigned int flampu2 = 4;
unsigned int fpompa1 = 5;
unsigned int fpompa2 = 6;

float h;
float t;
int led_1;
int led_2;
int led_3;
int led_4;

WiFiClient client;

void setup(){

pinMode(12, OUTPUT);
pinMode(13, OUTPUT);
pinMode(16, OUTPUT);
pinMode(14, OUTPUT);

Serial.begin(115200);
delay(10);
lcd.begin(); //set lcd i2c
lcd.noCursor(); //biar gak ada cursor di lcd
lcd.clear(); //clear lcd
dht.begin();

       Serial.println("Connecting to ");
       Serial.println(ssid);

// Connect to WiFi network
  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);

  WiFi.begin(ssid, pass);

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");

while (WiFi.status() != WL_CONNECTED)
     {
            delay(500);
            Serial.print(".");
     }
      Serial.println("");
      Serial.println("WiFi connected");
      delay(100);

Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
Serial.print("Netmask: ");
Serial.println(WiFi.subnetMask());
Serial.print("Gateway: ");
Serial.println(WiFi.gatewayIP());
ThingSpeak.begin(client);
}

void loop(){

  h = dht.readHumidity();
  t = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit

lcd.setCursor(0, 0);
lcd.print("Temp: ");
lcd.print(t);
lcd.print(" C   ");
lcd.setCursor(0, 1);
lcd.print("Humi: ");
lcd.print(h);
lcd.print(" %   ");

  if (isnan(h) || isnan(t)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }


if (client.connect(server,80))   //   "184.106.153.149" or api.thingspeak.com
{
                            
                             String postStr = apiKey;
                             postStr +="&field1=";
                             postStr += String(t);
                             postStr += "\r\n\r\n";

                             client.print(String("GET ") + resource + apiKey + "&field1=" + t + "&field2=" + h + " HTTP/1.1\r\n" + "Host: " + server + "\r\n" + "Connection: close\r\n\r\n");
                             //client.print(String("GET ") + resource + apiKey + "&field1=" + t + " HTTP/1.1\r\n" + "Host: " + server + "\r\n" + "Connection: close\r\n\r\n");                             
                                        
                             client.print("Host: api.thingspeak.com\n");
                             client.print("Connection: close\n");
                             client.print("X-THINGSPEAKAPIKEY: "+apiKey+"\n");
                             client.print("Content-Type: application/x-www-form-urlencoded\n");
                             client.print("Content-Length: ");
                             client.print(postStr.length());
                             client.print("\n\n");
                             client.print(postStr);
                             
                             Serial.print("Temperature: ");
                             Serial.print(t);
                             Serial.print(" humidity: ");
                             Serial.print(h);
                             Serial.println(". Send to Thingspeak.");
                        }
                        
          client.stop();

          Serial.println("Waiting...");
// thingspeak needs minimum 15 sec delay between updates, i've set it to 30 seconds
  delay(5000);

kendali();
delay(5000);
}


void kendali(){

  //get the last data of the fields
  led_1 = ThingSpeak.readFloatField(channel, 3);
  led_2 = ThingSpeak.readFloatField(channel, 4);
  led_3 = ThingSpeak.readFloatField(channel, 5);
  led_4 = ThingSpeak.readFloatField(channel, 6);
 
  if(led_1 == 1){
    digitalWrite(13,HIGH);
    Serial.println("lampu1 is On..!");
  }
  else if(led_1 == 0){
    digitalWrite(13,LOW);
    Serial.println("lampu1 is OFF");
  }

  if(led_2 == 1){
    digitalWrite(12,HIGH);
    Serial.println("lampu2 is On..!");
  }
  else if(led_2 == 0){
    digitalWrite(12,LOW);
    Serial.println("lampu2 is OFF");
  }

  if(led_3 == 1){
    digitalWrite(16,HIGH);
    Serial.println("POMPA1 is On..!");
  }
  else if(led_3 == 0){
    digitalWrite(16,LOW);
    Serial.println("POMPA1 is OFF");
  }

  if(led_4 == 1){
    digitalWrite(14,HIGH);
    Serial.println("POMPA2 is On..!");
  }
  else if(led_4 == 0){
    digitalWrite(14,LOW);
    Serial.println("POMPA2 is OFF");
  }
 
}



c. Tampilan Interface Web

d. Program index.php Website

<html>
<head>
<title>LED ON/OFF</title>
</head>
<body>

<p align="center">
<font size="8">

<b>LAMPU 1 = &nbsp <a href="https://api.thingspeak.com/update?api_key=HGKJ67576HJF3HGFJ7H&field3=1">ON </a></b> /
<b><a href="https://api.thingspeak.com/update?api_key=HGKJ67576HJF3HGFJ7H&field3=0">OFF</a></b>
<br>
<b>LAMPU 2 = &nbsp <a href="https://api.thingspeak.com/update?api_key=HGKJ67576HJF3HGFJ7H&field4=1">ON </a></b> /
<b><a href="https://api.thingspeak.com/update?api_key=HGKJ67576HJF3HGFJ7H&field4=0">OFF</a></b>
<br>
<b>POMPA 1 = &nbsp <a href="https://api.thingspeak.com/update?api_key=HGKJ67576HJF3HGFJ7H&field5=1">ON </a></b> /
<b><a href="https://api.thingspeak.com/update?api_key=HGKJ67576HJF3HGFJ7H&field5=0">OFF</a></b>
<br>
<b>POMPA 2 = &nbsp <a href="https://api.thingspeak.com/update?api_key=HGKJ67576HJF3HGFJ7H&field6=1">ON </a></b> /
<b><a href="https://api.thingspeak.com/update?api_key=HGKJ67576HJF3HGFJ7H&field6=0">OFF</a></b>
<br>

</font>
</p>

</body>
</html>



e. VIDEO HASILNYA