LPG gas leak alarm
A kitchen gas sniffer that beeps and flashes the moment LPG levels climb.
Shop by category
Shop all componentsMeasure the angle between two surfaces by taking a reference reading on the first and then reading the second. Absolute angles are measured from the horizontal, but a carpenter usually wants the angle between two things, which is a relative measurement. Press the reference button against the first surface and its angle is stored; every reading after that is the difference from it. The arc drawn on screen makes the number tangible, and it is drawn with the same sin and cos work as the clock in Experiment 6.
The ESP32 is a 3.3V board: never connect a 5V signal straight to a GPIO pin.
Every part for this build comes in the Geekobot Titan Kit box, a Geekobot exclusive, together with the parts for all 120 projects, from a first blinking LED to a smart fan and a reaction game. The wiring below is the kit's own wiring.
Tick anything you already have and the total updates.
ESP32 DevKit V1 (38-pin): the brain of every Titan Kit project, with Wi-Fi and Bluetooth
Male-to-female and female-to-female leads for the modules
MPU6050 motion sensor: 3-axis accelerometer and gyroscope on I2C
ESP32 expansion board from the kit: every GPIO has its own S, V, G header
Follow the colours: red is power, dark grey is ground, blue is a signal.
titan_kit_068_digital_protractor.inoVerify & upload in Electrolark#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Adafruit_MPU6050.h>
#include <Adafruit_Sensor.h>
Adafruit_SSD1306 display(128, 64, &Wire, -1);
Adafruit_MPU6050 mpu;
int referenceButton = 12;
int holdButton = 14;
float angle = 0;
float reference = 0;
bool hasReference = false;
bool holding = false;
float heldAngle = 0;
float readAngle()
{
sensors_event_t a, g, temp;
mpu.getEvent(&a, &g, &temp);
return atan2(a.acceleration.y, a.acceleration.z) * 180.0 / PI;
}
void setup()
{
pinMode(referenceButton, INPUT_PULLUP);
pinMode(holdButton, INPUT_PULLUP);
Serial.begin(9600);
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { while (true) { } }
display.setTextColor(SSD1306_WHITE);
if (!mpu.begin())
{
display.clearDisplay();
display.setCursor(0, 28);
display.print("MPU6050 not found");
display.display();
while (true) { }
}
mpu.setAccelerometerRange(MPU6050_RANGE_2_G);
mpu.setFilterBandwidth(MPU6050_BAND_21_HZ);
}
void loop()
{
angle = angle * 0.85 + readAngle() * 0.15;
if (digitalRead(referenceButton) == LOW)
{
reference = angle;
hasReference = true;
Serial.print("Reference set at ");
Serial.println(reference, 1);
delay(400);
}
if (digitalRead(holdButton) == LOW)
{
holding = !holding;
if (holding)
{
heldAngle = angle;
}
delay(400);
}
float shown = holding ? heldAngle : angle;
float relative = shown - reference;
// Keep the answer in -180..180
while (relative > 180) relative = relative - 360;
while (relative < -180) relative = relative + 360;
display.clearDisplay();
display.setTextSize(1);
display.setCursor(0, 0);
display.print("PROTRACTOR");
if (holding)
{
display.setCursor(88, 0);
display.print("HELD");
}
display.setTextSize(3);
display.setCursor(0, 14);
display.print(abs(relative), 0);
display.setTextSize(1);
display.print((char)247);
display.setCursor(0, 42);
if (hasReference)
{
display.print("Ref ");
display.print(reference, 0);
display.print((char)247);
display.print(" abs ");
display.print(shown, 0);
display.print((char)247);
}
else
{
display.print("Press D3 on surface 1");
}
display.setCursor(0, 54);
display.print("D3 ref D4 hold");
// Draw the angle as an arc
int cx = 100;
int cy = 34;
display.drawLine(cx - 22, cy, cx + 22, cy, SSD1306_WHITE);
float radians = -relative * PI / 180.0;
display.drawLine(cx, cy,
cx + cos(radians) * 22,
cy + sin(radians) * 22, SSD1306_WHITE);
display.drawCircle(cx, cy, 2, SSD1306_WHITE);
display.display();
delay(40);
}
Use a micro-USB data cable (some cables only charge), install the CP210x or CH340 driver if no port appears, pick Tools > Board > ESP32 Dev Module and hold the BOOT button on the board until the upload starts.
The sketch uses INPUT_PULLUP, so one leg goes to the GPIO and the other to GND. Use two legs on opposite sides of the button.
Check SDA on GPIO21 and SCL on GPIO22, power from 3V3, and that the sketch uses address 0x3C (some boards are 0x3D).
Check SDA on GPIO21 and SCL on GPIO22 and power it from 3V3. The AD0 pin must stay unconnected (address 0x68).
Absolute angles are measured from the horizontal, but a carpenter usually wants the angle between two things, which is a relative measurement. Press the reference button against the first surface and its angle is stored; every reading after that is the difference from it. The arc drawn on screen makes the number tangible, and it is drawn with the same sin and cos work as the clock in Experiment 6.
Hold the board against one surface and press the first button to set the reference. Move it to the second surface: the angle between them appears in large digits. The arc on the right shows the angle graphically.
Yes. It is project 68 of 120 in the Geekobot Titan Kit, in level 11 (Motion and IMU). Every part on the list comes in the kit box, and you can also buy the parts one by one from the list above.
No. Every Titan Kit project is wired on the ESP32 expansion board and the breadboard with jumper wires.
8 parts: ESP32-WROOM-32 38-Pin Development Board, USB Cable, Solderless Breadboard, Dupont Jumper Wires (40 pcs), 2 × Tactile Push Button Switch, 0.96" OLED Display 128x64, GY-521 MPU6050 6-Axis Gyro and Accelerometer Module and ESP32 38-Pin Expansion Board. On this page you can tick the parts you already have and add only the rest to your cart.
It is a intermediate project and takes about 45 minutes. The build on this page has 6 steps.
No. This page has the complete, tested code (titan_kit_068_digital_protractor.ino).
About ₹1,000 for the parts at the prices on this page. Quantity price breaks lower the cost when you build several.
Relative angle computation; Reference-based measurement; Normalising an angle into a −180 to 180 range; Drawing an angle as an arc.
The ESP32 is a 3.3V board: never connect a 5V signal straight to a GPIO pin.
A kitchen gas sniffer that beeps and flashes the moment LPG levels climb.
See the smoke level live on a crisp screen and get a loud warning when it spikes.
An infrared eye that spots an open flame and raises the alarm.
Walk into the room and it sounds the alarm: the classic first security build.
Lessons are free to read. Maker (₹499/month) and Pro add quizzes, worked problems and certificates, paid with your Geekobot account. See plans
Learning project. Check every circuit and the datasheet of each part before you power it up.