Hackster is hosting Hackster Holidays, Ep. 6: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Monday!Stream Hackster Holidays, Ep. 6 on Monday!
Najad
Published © GPL3+

Tripwire Automatically Minimizes Tabs When Someone Walks By

Do you always slack off on your computer and worry about getting busted? Not anymore!

IntermediateWork in progress8,152

Things used in this project

Hardware components

Arduino Pro Mini 328 - 5V/16MHz
SparkFun Arduino Pro Mini 328 - 5V/16MHz
×1
Pro Micro - 5V/16MHz
SparkFun Pro Micro - 5V/16MHz
×1
nRF24 Module (Generic)
×1
IR Infrared Obstacle Avoidance Sensor Module
×1

Story

Read more

Custom parts and enclosures

Gerber File

Schematics

Tx

Rx

Code

Tx

C/C++
/*
   www.diyusthad.com
   www.youtube.com/c/diyusthad
*/

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>

#define ir 3

RF24 radio(5, 8); // CE, CSN

const byte address[6] = "00001";
boolean irState = HIGH;
boolean preIrState = HIGH;

void setup() {
  radio.begin();
  radio.openWritingPipe(address);
  radio.setPALevel(RF24_PA_MIN);
  radio.stopListening();

  pinMode(ir,INPUT_PULLUP);

  Serial.begin(9600);
}

void loop() {
  const int trigger = 1;

  irState = digitalRead(ir);

 if(preIrState != irState)
 {
    Serial.println("detected");
    radio.write(&trigger, sizeof(trigger));
    preIrState = irState;
   
 }
  
}

Rx

C/C++
/*
  by Mohamed Najad, www.diyusthad.com
  www.youtube.com/c/diyusthad

*/

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <Keyboard.h>

RF24 radio(5, 3); // CE, CSN

const byte address[6] = "00001";

int os = 1; //osx = 1, windows = 2, linux = 3
int function = 3; //lock the computer = 1, minimize active window = 2 , show desktop = 3, custom script = 4

void setup() {
  Serial.begin(9600);
  radio.begin();
  radio.openReadingPipe(0, address);
  radio.setPALevel(RF24_PA_MIN);
  radio.startListening();
  Keyboard.begin();
}

void loop() {
  if (radio.available()) {
    int trigger;
    radio.read(&trigger, sizeof(trigger));

    if (trigger == 1)
    {
      switch (os)
      {
        case 1: //osx
          switch (function)
          {
            case 1://lock computer
              Keyboard.press(KEY_LEFT_GUI);
              Keyboard.press(KEY_RIGHT_CTRL);
              Keyboard.press('q');
              delay(100);
              Keyboard.releaseAll();
              Serial.println(trigger);
              while (1);


            case 2: //minimize active window
              Keyboard.press(KEY_LEFT_GUI);
              Keyboard.press('m');
              delay(100);
              Keyboard.releaseAll();
              Serial.println(trigger);
              while (1);


            case 3: //show desktop
              Keyboard.press(KEY_F11);
              Keyboard.press('m');
              delay(100);
              Keyboard.releaseAll();
              Serial.println(trigger);
              while (1);


            case 4: //custome script
              while (1);


          }

        case 2: //windows
          switch (function)
          {
            case 1: //lock
              Keyboard.press(KEY_LEFT_GUI);
              Keyboard.press('l');
              delay(100);
              Keyboard.releaseAll();
              Serial.println(trigger);
              while (1);


            case 2: //minimize active window
              Keyboard.press(KEY_LEFT_GUI);
              Keyboard.press('m');
              delay(100);
              Keyboard.releaseAll();
              Serial.println(trigger);
              while (1);


            case 3: // show desktop
              Keyboard.press(KEY_LEFT_GUI);
              Keyboard.press('d');
              delay(100);
              Keyboard.releaseAll();
              Serial.println(trigger);
              while (1);


            case 4: //custome script
              while (1);


          }

        case 3: //linux
          switch (function)
          {
            case 1:
              while (1);


            case 2:
              while (1);


            case 3:
              while (1);


            case 4:
              while (1);


          }

        case 4: //custom
        
          while (1);

      }

    }
  }
}

Credits

Najad

Najad

30 projects • 97 followers
Just crazy stuff​

Comments