Konfigurasi pin :
Pin SDA dihubungkan ke pin D2
Pin SCL dihubungkan ke pin D1
GND dihubungkan ke GND
VCC dihubungkan ke VU atau dihubungkan ke supply eksternal
Dalam proyek ini, Anda akan menghubungkan esP8266 ke komputer lain dan mempelajari cara memprogramnya menggunakan WEB SERVICE .
Dengan Menggunakan ARDUINO IDE pemrograman tampilan sangat mudah hanya beberapa baris kode.
partikan sdh menginstall library bh1750 dan lcd i2c
#include <ESP8266WiFi.h>const char* ssid = "Stri-X";const char* password = "111111";float suhu;WiFiServer server(80);#include <Wire.h>#include <LiquidCrystal_I2C.h>// Set the LCD address to 0x27 for a 16 chars and 2 line displayLiquidCrystal_I2C lcd(0x27, 16, 2);#include <BH1750_WE.h>#define BH1750_ADDRESS 0x23BH1750_WE myBH1750(BH1750_ADDRESS);// You may also pass a TwoWire object like wire2// BH1750_WE myBH1750(&wire2, BH1750_ADDRESS);void setup(){Serial.begin(9600);Wire.begin();myBH1750.init(); // sets default values: mode = CHM, measuring time factor = 1.0// myBH1750.setMode(CLM); // uncomment if you want to change the default values// myBH1750.setMeasuringTimeFactor(0.45); // uncomment for selection of value between 0.45 and 3.68lcd.begin();lcd.clear();lcd.backlight();lcd.setCursor(3, 0);lcd.print("LUX meter");delay(1000);lcd.clear();// Connect ti WiFi netwworkSerial.println();Serial.println();Serial.print("Connecting to ");Serial.println(ssid);WiFi.begin(ssid, password);while (WiFi.status() != WL_CONNECTED) {delay(500);Serial.print(".");}Serial.println("");Serial.println("WiFi Connected");// Start the serverserver.begin();Serial.println("Server Started");// Print the IP addressSerial.print("Use this URL to Connect: ");Serial.print("http://");Serial.print(WiFi.localIP());Serial.println("/");}void loop(){WiFiClient client = server.available();if (!client) {return;}// Wait until the client sends some dataSerial.println("new client");while(!client.available()){delay(1);}// Read the first line of the requestString request = client.readStringUntil('\r');Serial.println(request);client.flush();float lightIntensity = myBH1750.getLux();Serial.print(F("Light intensity: "));Serial.print(lightIntensity);Serial.println(F(" Lux"));lcd.setCursor(0,0);lcd.print(lightIntensity);lcd.print(" ");lcd.setCursor(11,0);lcd.print(" LX");delay(50);client.println("HTTP/1.1 200 OK");client.println("Content-Type: text/html");client.println("Refresh: 1");client.println(""); // do not forget this oneclient.println("<!DOCTYPE HTML>");client.println("<html>");client.println("<center>");client.println("<h1>");client.println("Monitoring LUX");client.println("</h1>");client.println("<br>");client.println("<br>");client.println("<h3>");client.println("LuxMeter = ");client.println(lightIntensity);client.println(" LX ");client.println("<br>");client.println("</h3>");client.println("</center>");client.println("</html>");delay(1);Serial.println("Client disconnected");Serial.println("");delay(500);}PEMBAHASAN PROGRAM
const char* ssid = "Stri-X";const char* password = "111111";Merupakan ssid wifi punyamu atau hotspot portablemu agar esp8266 terhubung dengan wifi
float lightIntensity = myBH1750.getLux();Merupakan list mengambil data lux dari sensor
0 Comments