Matthew Solc
Published

Motion Detected Homework Opener

Your homework automatically opens when motion is sensed to hide anything that you shouldn't be doing on your computer.

BeginnerShowcase (no instructions)2
Motion Detected Homework Opener

Things used in this project

Hardware components

PIR Motion Sensor (generic)
PIR Motion Sensor (generic)
×1
Photon 2
Particle Photon 2
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Breadboard (generic)
Breadboard (generic)
×1
USB Cable, Micro USB Type B Plug
USB Cable, Micro USB Type B Plug
×1

Software apps and online services

Particle Build Web IDE
Particle Build Web IDE
nodejs
ngrok
AutoHotkey

Hand tools and fabrication machines

Tape, Clear
Tape, Clear

Story

Read more

Code

Photon 2 Side Code

C/C++
This is the code in the Photon 2 for this project. It reads the input from the motion sensor, and once motion is sensed, it sends a webhook request.
#include "Particle.h"

int motionSensor = 6;
int lastMotionState = LOW;

void setup()
{
	pinMode(motionSensor, INPUT);
	Serial.begin(9600);
}

void loop()
{

	int motionState = digitalRead(motionSensor);
	

	if (motionState == HIGH && lastMotionState == LOW)
	{
	    Particle.publish("switchTabs1");
	    Serial.println("Motion sensed");

	}
	
	lastMotionState = motionState;
	

}

Computer Side Code

JavaScript
This is the code that, once my computer receives the webhook, triggers the AutoHotkey script
const { exec } = require("child_process");
const express = require("express");
const bodyParser = require("body-parser");

const app = express();
app.use(bodyParser.json());

// Webhook endpoint
app.post("/motion", (req, res) => {
    console.log("Webhook received:", req.body);

    console.log("Launching AHK script...");

    // Run AutoHotkey Script + error feedback
    exec('"C:\\Program Files\\AutoHotkey\\v2\\AutoHotkey.exe" "C:\\scripts\\switchTabs.ahk"', 
    (error, stdout, stderr) => {
        if (error) console.error("Error running AHK:", error);
        if (stderr) console.error("AHK stderr:", stderr);
        if (stdout) console.log("AHK stdout:", stdout);
        else console.log("AHK script executed (no stdout).");
    });


    res.send("OK");
});

// Start server
const PORT = 3000;
app.listen(PORT, () => console.log(`Server running on http://localhost:${PORT}`));

AutoHotkey Script

AutoHotKey
This is the script that is ran by AutoHotkey once triggered to open up a google classroom tab
Run("chrome.exe")
Sleep(100)
Send("https://classroom.google.com/u/2/" "{enter}")

Credits

Matthew Solc
1 project • 0 followers

Comments