PIR to activate virtual keystroke

I am new to arduino and I am looking to have a pir activate a pre fined key combo. So when the PIR is activated a virtual key combo is launched on the computer.
Can anybody help. I have the PIR working as I have turning an LED on and off
Looking for any help on the sketch or any specific wiring diagrams etc

Thanks in advance

Welcome :slight_smile:

Look at the bottom of this page, it may help you wiring and coding

http://www.ladyada.net/learn/sensors/pir.html

For the keystroke I suppose you will have to use Serial.write and also write your own key simulation library, shouldn't be too hard, but I don't know, I'm also a beginner :slight_smile:

You might also want to look into GoBetwino, if you are using Windows. It runs on the PC, and reads data from the serial port, sending data to windows apps based on process ID.

PaulS:
You might also want to look into GoBetwino, if you are using Windows. It runs on the PC, and reads data from the serial port, sending data to windows apps based on process ID.

Wow thanks, it will be useful for me too :slight_smile:

The other possibility is to use a Leonardo and use the keyboard emulation to behave like a keyboard. That way you can send any combination of key strokes to the PC without installing separate software on the it.

I took your advice and picked up a leonardo and got the keys to type if I short across D3 to 5v as per a sketch i found online.
See sketch below

/*
Keyboard Button test

Sends a text string when a button is pressed.

The circuit:

  • pushbutton attached from pin 3 to +5V
  • 10-kilohm resistor attached from pin 3 to ground

created 24 Oct 2011
by Tom Igoe

This example code is in the public domain.

*/

// Set the input to be the Hall-effect sensor
const int buttonPin = 3; // input pin for pushbutton

int previousButtonState = HIGH; // for checking the state of a pushButton
int counter = 0; // button push counter

void setup() {
// make the pushButton pin an input:
pinMode(buttonPin, INPUT);
}

void loop() {

// Read the StealthDuino! Hall-effect sensor, or just pin3 on an ordinary board
int buttonState = digitalRead(buttonPin);

// if the button state has changed,
if ((buttonState != previousButtonState)
// and it's currently pressed:
&& (buttonState == HIGH)) {
// increment the button counter
counter++;

// type out a message
// First function types a capital "Y" (ACSCII code 89)

Keyboard.write(89);
Keyboard.print("ou pressed the button: ");
Keyboard.print(counter);
Keyboard.println(" times.");
Keyboard.println("");

}

// save the current button state for comparison next time:
previousButtonState = buttonState;

}

i want to switch this so that the activation is via a pir not shorting across pins. How would I need to adjust this sketch

Also i want to activate a function key one time and then reset it to look for motion again and trigger the function key only when motion is sensed

how would that sketch be implemented

thanks in advance for all the help

i want to switch this so that the activation is via a pir not shorting across pins.

What is your PIR doing? The ones I know are exactly doing that: closing a circuit over a relays. If you connect that to the pins it's shortening them.

For the function key use:

Keyboard.press(KEY_F1);
Keyboard.release(KEY_F1);