External Sensor — ESP32 Project 4.0
Halo semua! Balik lagi minggu ini sama gue lagi. Minggu ini gue mau ngomongin tentang external sensor. Karena juga kebetulan external sensor yang gue punya baru ada barometer aja, jadi kali ini kita bakal coba deteksi suhu, ketinggian dari permukaan laut, sama tekanan udara.
Untuk percobaan ini, alat-alat yang diperluin adalah :
- ESP32
- Kabel Jumper
- Breadboard
- Barometer(in my case BMP180 4 kaki)
- Arduino IDE
Kalo misalkan ini percobaan pertama kalian pake barometer ataupun sensor apapun, kita perlu install beberapa library dulu sebelom mulai.
Sketch > Include Library > Manage Libraries dan search “Adafruit Unified Sensor” terus install
abis itu, search juga “Adafruit BMP085” dan install library seperti di bawah (tergantung jenis barometer yang dipake):
Oke, set up library buat eksperimen sensor udah kelar.
Rangkaian
Nah, terus kalo buat rangkaiannya bisa sambungin masing-masing pin sesuai tabel di bawah ini,
atau bisa nyontoh kaya gambar di bawah ini :
Code
Selanjutnya, buat kodenya sendiri, kita bisa langsung masuk ke code-nya. File > Examples > Adafruit BMP180 library > bmp180 test. Bakal kebuka page baru dengan code di bawah ini :
#include <Adafruit_BMP085.h>/***************************************************
This is an example for the BMP085 Barometric Pressure & Temp SensorDesigned specifically to work with the Adafruit BMP085 Breakout
----> https://www.adafruit.com/products/391These pressure and temperature sensors use I2C to communicate, 2 pins
are required to interface
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!Written by Limor Fried/Ladyada for Adafruit Industries.
BSD license, all text above must be included in any redistribution
****************************************************/// Connect VCC of the BMP085 sensor to 3.3V (NOT 5.0V!)
// Connect GND to Ground
// Connect SCL to i2c clock - on '168/'328 Arduino Uno/Duemilanove/etc thats Analog 5
// Connect SDA to i2c data - on '168/'328 Arduino Uno/Duemilanove/etc thats Analog 4
// EOC is not used, it signifies an end of conversion
// XCLR is a reset pin, also not used hereAdafruit_BMP085 bmp;
void setup() {
Serial.begin(9600);
if (!bmp.begin()) {
Serial.println("Could not find a valid BMP085 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(101500));
Serial.println(" meters");
Serial.println();
delay(500);
}
Demo
Buat demonstrasinya, bisa dibuka Serial Monitor dan mulai diamatin bacaan yang dideteksi sama si barometer.
Contoh :
Sekian buat eksperimen ESP32 kali ini, thank you yang udah mau baca dan belajar bareng. Semoga ini bisa berguna, bye for now!