PROJECT 4: EXPERIMENT WITH SENSOR SYSTEM
Hai gais, kali ini aku bakal nyobain pakai bmp180 buat ngecek suhu, tekanan, sama ketinggian di tempat nyobainnya (cek Kota Malang). Pertama kita bakal butuh
- NodeMCU-32S ( esp32 dalam kondisi terpasang di breadboard)
- Empat (4) kabel jumper male to male
- Satu (1) sensor bmp180
- Kabel USB yang berfungsiii (lupa difoto tp tau la yaa)
Rakit biar jadi kayak gambar dibawah, ternyata sensor bmpnya g usah di solder jg work gaes. Gw uda takut duluan soalnya g punya solder kwkwkwk
Awalnya program g jalan, jadi aku curiga kalo sensornya g kedetect akhirnya aku coba dulu tes ini sensor ke detect ato ga pake kode dibawah ini
#include <Wire.h>
void setup() {
Wire.begin(21,22); //ini aslinya g ada tapi kalo g dikasi di serial //monitornya sensor g kedetect mulu
Serial.begin(115200);
Serial.println(“\nI2C Scanner”);
}
void loop() {
byte error, address;
int nDevices;
Serial.println(“Scanning…”);
nDevices = 0;
for(address = 1; address < 127; address++ ) {
Wire.beginTransmission(address);
error = Wire.endTransmission();
if (error == 0) {
Serial.print(“I2C device found at address 0x”);
if (address<16) {
Serial.print(“0”);
}
Serial.println(address,HEX);
nDevices++;
}
else if (error==4) {
Serial.print(“Unknow error at address 0x”);
if (address<16) {
Serial.print(“0”);
}
Serial.println(address,HEX);
}
}
if (nDevices == 0) {
Serial.println(“No I2C devices found\n”);
}
else {
Serial.println(“done\n”);
}
delay(5000);
}
Waktu g diselipin line ini
Wire.begin(21,22);
Serial monitornya kayak gini
Untungnya habis ditambahin line tadi sensornya kedetect deh
Jadi 0x77 itu nantinya bakal kepake di kode program buat mastiin klo address GPIO yang ngasih fasilitas i2c udah bener, secara default GPIO22 konek ke SCL dan GPIO21 konek ke SDA.
Jadi setelah yakin kalo si sensor konek, langsung copas aja kode dibawah ini dan masukin ke Arduino IDE kalian, Perhatikan 0x77 tadi kepake di
if(!bmp.begin(0x77)) (...)
Ini kalimat pemisah aja biar jelas :)
#include <Wire.h>
#include <Adafruit_BMP085.h>
Adafruit_BMP085 bmp;
void setup() {
Serial.begin(9600);
if (!bmp.begin(0x77)) {
Serial.println("Could not find a valid BMP085/BMP180 sensor, check wiring!");
while (1) {}
}
}
void loop() {
Serial.print("Temperature = ");
Serial.print(bmp.readTemperature());
Serial.println(" *C");
Serial.print("Pressure = ");
Serial.print(bmp.readPressure());
Serial.println(" Pa");
// Calculate altitude assuming 'standard' barometric
// pressure of 1013.25 millibar = 101325 Pascal
Serial.print("Altitude = ");
Serial.print(bmp.readAltitude());
Serial.println(" meters");
Serial.print("Pressure at sealevel (calculated) = ");
Serial.print(bmp.readSealevelPressure());
Serial.println(" Pa");
// you can get a more precise measurement of altitude
// if you know the current sea level pressure which will
// vary with weather and such. If it is 1015 millibars
// that is equal to 101500 Pascals.
Serial.print("Real altitude = ");
Serial.print(bmp.readAltitude(102000));
Serial.println(" meters");
Serial.println();
delay(500);
}
Langsung aja upload ke NodeMCU-32S terus aku buka serial monitornya, jangan lupa di kode diatas aku pake badu 9600. G aku bikin videonya soalnya screenshot aja udah cukup jelas menurutku wkwk.