Using a Keyboard button to turn Pin 13 LED on and off.

I am working on a home automation project and I want to use a laptop to open and close various relays on and off. Thereby turning various outlets and lights on and off.

I would like to use a single key on my laptop where if pressed once the light relay will digitalwrite high and pressed again digitalwrite low. However using two keys for the to digitalwrite high and low would be fine.

I'd like to start by simply turning the LED on the Arduino UNO on and off.

Can I use my Arduino UNO along with a keystroke to digitalwrite high and low?

If so what how and what commands should be used?

(If you have a similar program, I would enjoy looking at it.) :slight_smile:

Can't see the connection between a laptop and Arduino for the basic version of this task.

In particular, you need some program - perhaps Python - running on the laptop - to catch keystrokes. in which case if you simply connect a USB-to-parallel port adapter, you can use the eight output bits of that to control your relays. In fact, if you only wanted two control lines, you could get them from the DTS and RTS lines of one of the dirt cheap USB to serial modules.

The question really is - what do you want the interface on your laptop to look like? Do you want to have "hotkeys" that activate the controls by pressing a key no matter what program presently has focus? Or a specific program which responds to keypresses in its particular window?

Now if you propose to dedicate an Arduino to the control task, so that it maintains the control status while the laptop is turned off or otherwise not connected, then your simplest program consists of using serial read commands to receive data from the serial monitor or another "terminal" program on the laptop, and using "case" statements to perform actions accordingly. The problem with the serial monitor is that it does not send single keypresses, but sends a line of text (which may be empty) when you hit Enter or click "Send".