Background: I change the job and in the new company you need to pay pizza for the whole team if you forget to lock your screen :-)

I want it to be automated: I walk away and the screen should lock. No additional action should be required. Keyboard shortcuts, special mouse movements or unplugging devices from USB are not valid solutions.

How could this be solved (with or without arduino)?

Please write slowly, I never worked with sensors or arduino before :-)

I need this for Mac and Ubuntu.

  • 10
    Windows 10 has something called Dynamic Lock, where the PC lock when your paired mobile phone gets out of range. You might be able to replicate that for Mac/Linux. Or having one of those BLE key chaines (like Tile). When it's out of range, (or the RSSI is low enough), lock the computer.
    – Gerben
    Commented Dec 19, 2019 at 15:47
  • 6
    How many times have you bought pizza so far?
    – CrossRoads
    Commented Dec 19, 2019 at 15:48
  • 3
    It would be wise to elaborate more specifically on the circumstances that you consider should engage this automation. For example, you might wheel your chair over to talk to your next door neighbour, or stand up to get the attention of someone at the other end of the office: are these acceptable triggers to lock your screen? Both false positives and false negatives in this system have the potential to have annoying consequences, so if you insist on using automation to recognise these criteria minimal ambiguity is key.
    – Will
    Commented Dec 19, 2019 at 23:00
  • 4
    @Mawg This is a technical problem: The company (sensibly) doesn't want other people accessing private data on an unlocked computer. Nobody cares about how this is achieved, just that it is. The whole idea behind these policies is to get people to start taking security serious in a nicer manner than having to talk with a manager.
    – Voo
    Commented Dec 20, 2019 at 10:23
  • 3
    Hard to understand why you want to create another solution to a quick Windows+L keypress ....
    – eagle275
    Commented Dec 20, 2019 at 13:26

9 Answers 9


Sorry, no Arduino required, but you probably already have a web cam on your desktop. If you don't mind being observed like Schrodinger's Cat, you can use a small utility like YawCam in Windows or Motion on Linux to trigger the screen lock when you are no longer visible at your console.

  • 3
    Overall this is a good suggestion, but "you probably already have a web cam on your desktop" seems like a pretty bold assumption. Webcams may be standard equipment on laptops these days, but I can count on one hand the number of desktop computers I've encountered in a business environment that had one installed.
    – jmbpiano
    Commented Dec 21, 2019 at 16:34
  • @jmbpiano , how about now that we've all spent 2 years shut up in our home offices Zooming?
    – Codex24
    Commented Dec 2, 2022 at 16:30


In the same vein as Gerben's comment, it is quite easy to use your phone for this, assuming that both your PC and your phone have bluetooth (and you take your phone with you, when you leave your seat). Moreover, if your PC does not have BT, cheap BT dongle will solve this.

Next step is writing a script that gets a list of all nearby/found BT devices and if your phone is not on that list, it just sends system call to lock.

As I have actually tried this once (although with a WIN PC), I can say it works more reliably than I would have initially expected (YMMV, obviously).

The great thing is that you (potentially) do not need any extra hardware, just a bit of code.

  • 1
    This works well - I used to do it many years ago. The good thing about writing your own script is that you can customise it for your situation: eg. set the signal strength threshold that will lock/unlock (you don't want to go help out a workmate behind you and not have your auto-lock script trigger!)
    – Aaron F
    Commented Dec 20, 2019 at 23:06

RFID (NFC) might be the way to go. Have an RFID tag in a wristband and an RFID reader by the side of (or under) your keyboard. As long as you keep your hands close to the keyboard the RFID reader should detect your wristband. When it doesn't sense it for a pre-defined period of time send a signal to the PC to trigger it to lock. It could then trigger the unlock when your wristband is back in range again.

  • The usual range of RFID/NFC will probably make that quite awkward. Using RFID/NFC, I see only two options: either you have a card with a lanyard, and whenever you leave your desk, the card must come with you, or the card and reader are somewhere that moves less that your arms e.g. the tag on your belt and the reader somewhere on the chair.
    – jcaron
    Commented Dec 20, 2019 at 13:29
  • It may be easier to have a flexible NFC tag sticker type thing on a piece of paper in your back pocket, and a reader under the seat, perhaps?
    – QuickishFM
    Commented Dec 22, 2019 at 12:40

If you chair has a gas cylinder to adjust height, it sinks a bit when sat in. My dip is about a centimeter. That's more than enough for a beam-interruption or reflection sensor, a hall effect sensor, or even a dead-simple magnetic reed switch, like those used by home alarms to monitor windows.

You could have the reed switch turn on/wake up a micro like an ESP8266, which uses ESP-NOW to talk to another ESP plugged into a usb serial on the desktop. Once the message is sent, the micro can go into deep sleep. The desktop's serial port is read by the lang of your choice; node.js, python, c#, etc, and runs a command or fires a key combo to lock the workstation.

  • 4
    Which has the downside of locking your screen every time you shift in your seat. Was my first idea as well, though. I think you need some delay on it, like if it's longer than 3 seconds or so.
    – SQB
    Commented Dec 20, 2019 at 9:02
  • 2
    This also has the disadvantage of wire trailing from your chair to computer - wheeling your chair around could end up bringing your computer with you (added benefit of you not being 'away' from the computer I guess...). Commented Dec 20, 2019 at 10:54
  • If you have a busted cylinder, like many of us do, you'll always be at the lowest point, so you won't see any sink. Or if you constantly raise your seat and it lowers over time, like mine, it could register as occupied, even though it's just failed to support you. Commented Dec 20, 2019 at 17:09

At a previous job we also had the rule that the screen had to be locked (usually done by pressing Win+L).

However, there was no pizza; instead, the computer was used to send mass e-mails to colleagues. The topics of the e-mails was as varied as the imaginations of people:

  • invitations to various events;
  • invitations to various celebrations at the desk of the not locked computer;
  • selling of expensive items for very low prices, providing whatever reasons;
  • etc etc

Many times, the content of the e-mail was the result of team-work.

The only limit was that the messages should use a decent language and not be (very) offensive. Also, I have never heard of e-mails sent in order to really harm the forgetful person (e.g. termination notice, offensive language to bosses or cutomers...).

The easiest and cheapest method is to just use Win+L. After you buy pizza for everybody for a few times, and have to endure their jokes / sarcasm at the same time, you will never forget to lock it again.

It is like learning to not pee in the bed during the night. It happens a few times, until you get it right.

For a technical solution, the sky is the limit.

As an (impractical) joke, you may want to have a look at the OMGWTF and the winners.

Example: configure the screensaver to kick in and lock the screen after ~ 5 seconds of inactivity (that is roughly the time you need to stand up and walk away, before any colleague has a chance to start typing without you noticing). It will create some trouble for you also, but you are sure that the computer will never remain unlocked. No additional software, hardware or work required - besides moving the mouse and hitting buttons on the keyboard. At the same time, you will become the most productive employee in the company. :)

On a more serious note, the purpose of that rule is to make people more aware of the security needs, and the need of them being involved in the process. Usually, locking the screen is the least one can do towards security, even before choosing good passwords - screen not locked, password not needed at all.

If one fails to do even that (lock the computer screen when the computer remains unattended), then there is a big chance that the other security rules are not followed either.

  • +1 for "the purpose of that rule is to make people more aware of the security needs, and the need of them being involved in the process." Yes, people need to be consciously aware of security. Automated systems only work as well as the people setting them up, and all too often those people aren't very security minded or they are so security minded that people with a legit need to use something still can't do to overbearing procedures. Commented Dec 20, 2019 at 17:12
  • @computercarguy I had a boss once who had the same idea and insisted that people had to consciously install Windows updates instead of using GPOs to handle that automatically. You can guess how many PCs were rarely up to date. Humans are awful at doing things regularly without failing, I don't believe a single person who thinks they'd never forget to lock their PC (I do believe that they don't remember forgetting to lock though, absolutely)
    – Voo
    Commented Dec 20, 2019 at 19:16
  • @Voo,there's a difference between a simple key-combo to lock a computer and installing updates manually. I realize (security) people don't realize it, though. Updates should be automated, since they can be complicated and large amount of them, as well as an IT dept potentially managing them. Also, installing updates is likely not the employee's focus at work, so their time is better spent not managing updates. Not to mention that locking a computer is akin to locking the front door to a house or business when it's not occupied. Commented Dec 20, 2019 at 19:59
  • @computercarguy So you're saying you agree it's impossible for people to once a week type "check for upda" reliably, but it's trivial to remember to press win+L hundreds of times in a week without fail?
    – Voo
    Commented Dec 21, 2019 at 10:39
  • 2
    @Voo, yes, it is very different then checking OS updates. because to press the key combination is an automatic routine mechanical move, like for example switching the turn signal at driving a car
    – Juraj
    Commented Dec 24, 2019 at 21:51

A single distance sensor, properly placed, should be enough to detect when you leave. That's the arduino part.

With python you can then use the serial over USB to read the output from the arduino. And run the command to activate the screen lock, according to your reading.

  • 7
    Facing the chair might not be good enough, it should be faced 'over' the chair, because otherwise the back of the chair is measured, and you get a false positive when you move back like 8 inches. Commented Dec 19, 2019 at 14:53
  • arduino micro with keyboard library can send the key combination to lock the screen
    – Juraj
    Commented Dec 19, 2019 at 17:18

Place a ultrasonic distance sensor HC-05 close to your monitor, facing towards your chest. Check the distance measured against a defined threshold (potentiometer?) and send a key press to your PC to lock it if it is exceeded.

I can go into more details if wanted, it's actually a project I thought about implementing before.

Edit: Whoops, @Eduardo Trápani suggested it already, but I think I can add to that.

I would use a digispark-like chip that can emulate key presses (WIN + L), this won't get you into trouble for installing software on your PC.


Use an obscure window manager which other people don't know how to use.

I use i3 and like to deliberately leave my workstation unlocked, because it's funny when I come back and find people pressing various key combinations to try and activate the group chat window (sending a funny message in my name is how they would prove they've 'hacked me') which I put into a hidden buffer.

Two and a half years in this role and they still haven't figured it out...all they need to do is RTFM...

  • 2
    OP would still be buying pizza, as the screen would be unlocked. It also sounds more like security by obfuscation, no?
    – BruceWayne
    Commented Dec 21, 2019 at 14:39
  • 1
    @BruceWayne "security by obfuscation" yes, definitely. Though if OP's workplace's last line of security is the screen lock on OP's computer, then OP's company has bigger things to worry about ;-)
    – Aaron F
    Commented Dec 21, 2019 at 14:52
  • Since this isn't actually securing their PC, this is a bad suggestion. If others just need to RTFM to get around your suggestion, then it doesn't solve any problems, but rather creates new problems. Commented Dec 30, 2019 at 22:03

The simplest solution would be using a pressure sensor (pressure pad) in your seat. Or a pressure mat if you use a standing up desk.

Ideally, you can calibrate it with an Arduino and send a "Windows Key + L" or a "Ctrl + Cmd + Q" if it is an Apple.

I reckon no other solution can be simpler to implement nor to maintain.

If you want a slightly more refined solution you can connect a scale, tare it with your weight and set a weight threshold for the Arduino to send the signal.

Edit: In ubuntu, you can set up any key combination to lock the screen. But the rest of the answer stands.

  • What type of pressure sensor would you recommend?
    – dotancohen
    Commented Dec 22, 2019 at 14:49
  • Hello @dotancohen Manufacturing your own seems the best option tekscan.com/blog/flexiforce/how-create-pressure-sensor-pad Or this link instructables.com/id/…
    – AriasFco
    Commented Dec 23, 2019 at 16:51
  • Using a key-comb manually is simpler to implement and maintain, since it'll quickly become automatic. It doesn't require any coding, batteries, wires that break or get in the way, and doesn't have to be rewritten for different OSes. It also doesn't break some IT policies against attaching personal peripherals to a computer. Then there's the modification of the chair to accommodate the sensor, which might not be welcome. Also, using an off the shelf load cell is more reliable than a homemade version. Commented Dec 30, 2019 at 22:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.