Do you always slack off on your computer and worry about getting busted? Not anymore because today we are going to make a Tripwire which automatically minimizes your tabs when someone walks by.
Video
Before we going to the project let me thanks allpcb.com for sponsoring this project.
ALLPCB is an ultrafast PCB super factory as well as an Internet-based manufacturing company. We are committed to building an electronic collaborative manufacturing service platform. We serve enterprises related to consumer electronics, communication equipment, industrial control, instruments and apparatus, intelligent hardware, “Internet of Things” and “Industry 4.0” solutions, etc. We offer professional one-stop service, including PCB manufacturing, PCB assembly and components sourcing.
Theory
This project mainly contains two modules RECEIVER (Rx) and a TRANSMITTER (Tx). The Rx module is the one which we connect to the computer’s USB port which will receive a signal to execute the pre-written script whenever there is a trigger happens in the Tx module.
Features
Icons made by Pixel perfect from www.flaticon.com
Supported Platforms
Hardware Required
Components | AliExpress | DIY Usthad |
Arduino Pro Mini | ||
Arduino Pro Micro | ||
nRF24 Module x2 | ||
IR Obstacle sensor | ||
Li-ion Battery 3.7v | ||
Battery Charging module |
Schematic & PCB
Transmitter (TX)
Receiver (RX)
PCB
Transmitter (Tx)
Code
/* 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; } }
Receiver (Rx)
Code
/* 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); } } } }
Inspired by dekuNukem‘s daytripper.
Hi,
The project works only once, then i have to unplug receiver and transmitter every time, after re-plugging it works again for once only. I have to repeat this everytime to make it work.
Is there any fix for this?
Yes, I programmed it like that and yes, of course, you can change the code to achieve your target output.
just remove the
while(1)
and put some delay for 1 or 2 secondsHi Najad,
This is what the original code is:
case 3: // show desktop
Keyboard.press(KEY_LEFT_GUI);
Keyboard.press(‘d’);
delay(100);
Keyboard.releaseAll();
Serial.println(trigger);
while (1);
How should i change it? according to what you said above? just remove while (1); and add delay(1); in that place?
I tried but it is not working that way. Can you suggest another?
not delay(1) I told to use 1 or 2 seconds delay like delay(2000)
if still having an issue. tell me os you are using and the function you need (minimize tab or lock)?
Hi Najad,
Thanks for your reply, i tried again as you said adding a delay(2000) in Rx code still it works only once.
I am trying for OS: Windows and trying Function: Show Desktop.
Can you please guide?
let me check and will reply ASAP