Customer Question - Arduino telling my computer to take a photo

Hi, I want to be able to push a button (on my arduino) and for my arduino to tell the Laptop (a Mac) to take a photo with the built in camera. How do I do this?

Thanks!

On macOS Sierra (10.12) and some earlier versions, the Photo Booth app accepts command-enter as a shortcut to take a photo. This will work if Photo Booth is the active app. Downside is the three second delay. There’s no setting to change that as far as I can see. There are probably other apps that will take a photo without the delay.

The 32u4, Due, or Zero Arduino boards can act as a USB keyboard, so you can program them to send the command-enter key sequence. For more about the library needed, see;

https://www.arduino.cc/en/Reference/MouseKeyboard

The Teensy boards can also do this, see;

https://www.pjrc.com/teensy/td_keyboard.html

Instead of USB keyboard, you might use bluetooth keyboard, which is supported by every modern Mac. There are controller boards with a bluetooth peripheral on the board, such as this (sold out) one from Adafruit;

https://www.littlebirdelectronics.com.au/bluefruit-ez-key-12-input-bluetooth-hid-keyboard-c

So choose an app, choose a connection method (USB or bluetooth), and begin selecting parts.

If you’re into writing your own app on macOS, then you might also use one of the ESP32 or ESP8266 modules to trigger the camera over WiFi.

Fswebcam might be an option, I used it for a while with a logitec webcam, although I was setting it to take a picture every 5 minutes. I can’t see why sitting some code monitoring a usb serial line to trigger the event.

#!/bin/bash
##configure here
#type your username for the variable USER if you run with sudo, otherwise bash will use root.
#USER=pi
#put the path to this bash script here
#pathtoscript=/usr/local/bin/webcam.sh
bs=`lsusb | grep Logitech | cut -c5-7`
dve=`lsusb | grep Logitech | cut -c16-18`

cam() {
for n in {1..3}; do
fswebcam -c /usr/local/etc/fswebcam.conf
sleep 30
done
}
cam
sudo /usr/local/bin/usbreset /dev/bus/usb/$bs/$dve
#sudo $pathtoscript

You could use pyserial to monitor the usb port for a command from the arduino.
https://pyserial.readthedocs.io/en/latest/

Use OpenCV to control the webCam
https://opencv-python-tutroals.readthedocs.io/en/latest/index.html

I havn’t tried but the pieces requiredappear to be there. OpenCV mainly capturesvideo but you can caputre a single frame (picture) and process it with python.
Also OpenCV has many processing and detection functions available (face detection).

Cheers
Sean