from Arduino to PC

Greetings,

Here is my plan; Motion sensor (NC or NO) -> Arduino -> USB connection ->PC -> PC runs a small script and execute a command when motion sensor is triggered.

Do you guys have any example that will come close ?

Many thanks,
Marian

Depending on what you want the PC side "script" to do, GoBetwino can probably do it for you.

The rest should be simple, depending on the switch you have.

MikMo thank you very much.

When the motion sensor triggers I want the PC to run a small program with an argument (initiate video recording from one of the security cameras)

I will take a look at your link.

Thank you,
Marian

You can definitively do that with GoBetwino.

There are example code in the download to do something similar.

I´ve done it a little bit different:

I´m using an Arduino with the PING))) sensor, and 4 switches on the board:

Depending on how the switches are, they send 0 and 1 to the computer as one number, followed by a space.

On the PC, there are basically 2 programms running:

aackeys (which is redirecting all seriall input as keyboard input)
AutoHotKey (this is reading what you type, and on certain inputs a makro is running)

So, basically, with the switches I can decide what makro on the PC will run.

The sketch will send the code to the PC (1000 , 1100 , 1110 , (just examples) to the PC.

The makros just do call VLC, with the video as parameter.

VLC is set to allow only one instance, run in FullScreen when Video is playing, making PAUSE after Playlist is finished, and new videos clear the old playlist.

So, after first run on the computer, vlc is in fullscreen and remains there.

Furthermore, after sending some data to the computer, the arduino will do nothing for 5 minutes.

Oh, important, only if the distance is <70cm the codes are sent to the PC, because I want the people to get close to the sensor :slight_smile:

I think the sketch is realy ugly, it is my first one :slight_smile:

But, it´s working :slight_smile:

/* Ping))) Sensor

   The circuit:
	* +V connection of the PING))) attached to +5V
	* GND connection of the PING))) attached to ground
	* SIG connection of the PING))) attached to digital pin 7

 */

const int pingPin = 7;

const int Schalter1Pin = 9;
const int Schalter2Pin = 10;
const int Schalter3Pin = 11;
const int Schalter4Pin = 12;

int Schalter1, Schalter2, Schalter3, Schalter4;


void setup() 
{
  // initialize serial communication:
  Serial.begin(9600);
  
  // Die vier Schalter werden als Input definiert
  pinMode(Schalter1Pin, INPUT);
  pinMode(Schalter2Pin, INPUT);
  pinMode(Schalter3Pin, INPUT);
  pinMode(Schalter4Pin, INPUT);
  delay(200000); //waiting some time for the PC getting ready
}

void loop()
{
   
  int Schalter1 = digitalRead(Schalter1Pin);
  int Schalter2 = digitalRead(Schalter2Pin);
  int Schalter3 = digitalRead(Schalter3Pin);
  int Schalter4 = digitalRead(Schalter4Pin);
  
  // establish variables for duration of the ping, 
  // and the distance result in inches and centimeters:
  long duration, inches, cm;

//have no Idea why I need this, if i don´t do it, I often get messages to the PC with a distance of 0
cm=200;

  // The PING))) is triggered by a HIGH pulse of 2 or more microseconds.
  // Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
  pinMode(pingPin, OUTPUT);
  digitalWrite(pingPin, LOW);
  delayMicroseconds(2);
  digitalWrite(pingPin, HIGH);
  delayMicroseconds(5);
  digitalWrite(pingPin, LOW);

  // The same pin is used to read the signal from the PING))): a HIGH
  // pulse whose duration is the time (in microseconds) from the sending
  // of the ping to the reception of its echo off of an object.
  pinMode(pingPin, INPUT);
  duration = pulseIn(pingPin, HIGH);

  // convert the time into a distance
  inches = microsecondsToInches(duration);
  cm = microsecondsToCentimeters(duration);
if (cm < 70) {
  Serial.print(Schalter1, DEC);
  Serial.print(Schalter2, DEC);
  Serial.print(Schalter3, DEC);
  Serial.print(Schalter4, DEC);
  Serial.println(" ");
  
  //die folgenden Zeilen später löschen
  //Serial.print("Entfernung ");
  //Serial.print(cm);
  //Serial.print("cm");
  //Serial.println();
  delay(300000); //this line keeps the arduino quiet for 5 minutes, so the video isn´t played over and over as long as somebody is standing in the front
  }
  delay(1000); //if I delete this line, I do also get lots of false messages with a distance of 0 on the computer
 

}

long microsecondsToInches(long microseconds)
{
  return microseconds / 74 / 2;
}

long microsecondsToCentimeters(long microseconds)
{
  return microseconds / 29 / 2;
 
//Serial.print("Test"); 
}

This it is.

The code for AutoHotKey looks like this:

::1000::
Run, c:\Programme\VideoLAN\VLC\vlc.exe c:\video1.wmv
return

If a "1000 " (don´t forget the space on the serial output) is received, vlc will play video.wmv1 from c:\

I´m just triggering 1000, 1100, 1110 and 1111 on the PC, so I put AACKEYS in the autostart, also the 4 little makros as EXE Files.

Oh, after calling aackeys, the arduino performs a reset I think. So propably the 200000 delay could be shortened to 100000 or more.

Hope it helps...

I´ve got the idea from

The ping))) skript is inside the arduino software as an example.