This challenge is inspired by Blink the CAPS LOCK by zeppelin.

Most webcams feature a small integrated LED light, indicating if the webcam is in use, as controlled by a hardware mechanism to prevent spying.

Your task is to blink it:

  1. Turn it on.
  2. Wait for 0.5 (±0.1) seconds.
  3. Turn it off again.
  4. Wait for 0.5 (±0.1) seconds;
  5. Repeat.

Please include a GIF or video of the webcam blinking, if possible. If an answer doesn't have the GIF, please add a GIF of the program running.


  • If your language is missing a subsecond sleep command, your program may use a 1 second delay instead, at a penalty of an additional byte. (replacing .5 with 1)
    • If your language, for some reason, doesn't support .5, your penalty is 2 bytes. (replacing 0.5 with 1)
  • Your program must loop unless halted by the user.
  • Your LED can start either on or off; whichever is more beneficial can be used.
  • If your LED has a turning-off delay, then it doesn't have to be taken into account, unless if you want to provide an additional version.


This is , which means the shortest answer in bytes wins.

  • 2
    \$\begingroup\$ My laptop's webcam LED takes a while (around 0.3 seconds, it seems) to turn off after the video device stops being accessed. Does this have to be taken into account? \$\endgroup\$
    – Doorknob
    Feb 26, 2017 at 17:40
  • \$\begingroup\$ @Doorknob No, but you can provide a version that takes it into account if you'd like. \$\endgroup\$ Feb 26, 2017 at 17:42
  • 1
    \$\begingroup\$ The penalty should only be 1 byte, since you can just use .5 \$\endgroup\$
    – Moonchild
    Mar 1, 2017 at 0:46
  • \$\begingroup\$ @Elronnd I was going to add that, but I forgot. \$\endgroup\$ Mar 1, 2017 at 2:10

4 Answers 4


MATLAB, 40 bytes

while 1;w=webcam;pause(.5);delete(w);end

Creates an infinite while loop and each time through the loop, a webcam object is initialized (turns on the webcam), the script is paused for 0.5 seconds using pause, and then the webcam object is deleted (turning the webcam off).

enter image description here

  • 2
    \$\begingroup\$ The delay between each blink is more than 0.5 \$\endgroup\$ Feb 26, 2017 at 23:25
  • 2
    \$\begingroup\$ @haykam The directions (and comments) indicate that inaccuracies due to the hardware are acceptable unless I'm misreading them. \$\endgroup\$
    – Suever
    Feb 26, 2017 at 23:30
  • \$\begingroup\$ Ok... do you mind maybe adding an additional golf that does it so it looks like 0.5s? \$\endgroup\$ Feb 26, 2017 at 23:31
  • 4
    \$\begingroup\$ @haykam It's impossible, it's a limitation of MATLAB (and maybe the hardware itself). I am already showing it being turned off and back on as fast as possible. \$\endgroup\$
    – Suever
    Feb 26, 2017 at 23:32
  • \$\begingroup\$ Last beep was good \$\endgroup\$ Feb 27, 2017 at 1:52

Python, 82 bytes

(Uses OpenCV for accessing the webcam.)

import cv2,time
while 1:w=cv2.VideoCapture(0);s(.5);w.release();s(.5)

enter image description here


Javascript (ES6), 100 bytes


During my testing, I saw a delay between the camera being activated and the LED turning on, so the timing may not be perfect. It also must run on an https:// page.

  • \$\begingroup\$ @haykam thanks for the edit, but for some reason this script doesn't work inside the snippet iframe sandbox \$\endgroup\$
    – nderscore
    Feb 27, 2017 at 21:36

Scratch in scratchblocks2, 61 bytes

when gf clicked
turn video[on v
turn video[off v

Sorry about the absolutely terrible video. My LED has a slight turning-on delay, it is very faint, and the GIF is 18 MB.


  • \$\begingroup\$ @JonathanFrech I've taken a look at some Scratch answers and they all seem to use scratchblocks2. Secondly, I was doing what the challenge required? \$\endgroup\$
    – W. K.
    Nov 19, 2018 at 12:05
  • \$\begingroup\$ "Please include a GIF or video of the webcam blinking, if possible. If an answer doesn't have the GIF, please add a GIF of the program running." I included everything else above it. \$\endgroup\$
    – W. K.
    Nov 20, 2018 at 1:27
  • \$\begingroup\$ You are right. I seldom see a Scratch answer but it appears that your answer satisfies both the current byte count consensus and challenge-specific rules. Sorry for my partially uninformed critique. \$\endgroup\$ Nov 20, 2018 at 12:49

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.