Project 4: External Sensors
LADS AND GENTS!! I’m going back home to Surabaya *which is an IMPORTANT news,,,* so there’s probably some changes in the setup but anyyywwway we’re here in the fourth week of ESP32 exploration! Last week was our moment with Internal Sensors, External Sensors are waiting to be tried on this week.
Today we bring in BMP280 Barometric Sensor to the house. Cable jumper (male-to-female), our mighty couple esp32 & breadboard. Before setting the circuit up, there are some library we need to prepare for the Arduino IDE.
go to Tools → Manage Library, find BMP280 and press install. A pop up will ask if we wanted to install Adafruit Unified Sensor package also. Choose install all.
After installing and setting up the sensor’s environment we can start to arrange the circuit like this. To be simple so that nothing gets messed up here’s where should we connect the jumper to (exactly).
ESP32 Pin & BMP280 Sensor Matches
- 3v3 + VCC
- GND + GND
- GPIO21 + SDA
- GPIO22 + SCL
Be careful and precise on connecting them.
Next, find the address of sensor we’re using by compiling this code.
#include <Wire.h>
void setup() {
Wire.begin();
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);
}
*wow ms gurl finally knows how to paste codes to medium*
Here we can see that our address is 0x76
Now we compile the real program to run our sensor. Open the serial monitor to check if the sensor is working.