Magicbit
Published

Privacy Mode with Magicbit (ESP32)

In this tutorial we learn about how to close a window in your laptop when someone open the door using Magicbit

IntermediateProtip325
Privacy Mode with Magicbit (ESP32)

Things used in this project

Hardware components

Magicbit
×1
Proximity Sensor
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Code

Privacy Mode with Magicbit

Arduino
/**
 * This example turns the ESP32 into a Bluetooth LE keyboard that writes the words, presses Enter, presses a media key and then Ctrl+Alt+Delete
 */
#include <BleKeyboard.h>

BleKeyboard bleKeyboard;

void setup() {
  Serial.begin(115200);
  Serial.println("Starting BLE work!");
  pinMode(16,OUTPUT);//Check Bluetooth connection between Magicbit andcomputer
  pinMode(18,OUTPUT); //Check Proximity Sensor
  bleKeyboard.begin();
}

void loop() {
  if(bleKeyboard.isConnected()) {
    digitalWrite(18,!digitalRead(18));
    Serial.println("Sending 'Hello world'...");
Serial.println(analogRead(39));
Serial.println(analogRead(32));
     
    if(analogRead(32)>analogRead(39)){
    bleKeyboard.press(KEY_LEFT_ALT); //bluetooth key board left_Alt_key
    bleKeyboard.press(KEY_F4); //bluetooth key board F4_key
    digitalWrite(16,LOW);
    }
    digitalWrite(16,HIGH);
    bleKeyboard.releaseAll(); //press Alt+F4 Key
  }
  if(analogRead(32)>analogRead(39)){

    digitalWrite(16,LOW);
    }
  Serial.println("Waiting 5 seconds...");
  delay(1000);
}

Credits

Magicbit
57 projects • 35 followers
Magicbit is an integrated development platform based on ESP32 for learning, prototyping, coding, electronics, robotics, IoT and more.

Comments