Pages: [1]   Go Down
Author Topic: from Arduino to PC  (Read 857 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 40
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Copenhagen / Denmark
Offline Offline
Edison Member
*
Karma: 6
Posts: 2360
Do it !
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

http://www.mikmo.dk/gobetwino.html

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

0
Offline Offline
Newbie
*
Karma: 0
Posts: 40
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Copenhagen / Denmark
Offline Offline
Edison Member
*
Karma: 6
Posts: 2360
Do it !
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

You can definitively do that with GoBetwino.

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

0
Offline Offline
Newbie
*
Karma: 0
Posts: 36
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 smiley



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

But, it´s working smiley




Code:
/* 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:

Code:
::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
http://www.thenewhobbyist.com/2010/12/arduino-powered-haunted-mansion-halloween/

The ping))) skript is inside the arduino software as an example.
« Last Edit: September 21, 2011, 09:27:45 am by nocheinAndi » Logged

Pages: [1]   Go Up
Jump to: