Help making a USB trigger, VB.NET coding, and interfacing the two in a wonderful harmony of code and circuits.

Hey fellas, got some questions for you about making a USB trigger and interfacing it with a VB.NET program.

Alright, so what I've got to do here is detect when a door is opened via a sensor (I've figured out that as far as practicality goes an ultrasonic or motion sensor would be the best, but I'm also considering a simple magnetic switch for the sake of simplicity and cost), and then play an audio file. I'd REALLY REALLY REALLY like to keep as much of the coding as possible done in VB.NET, and I don't want the end result to require the user to open five different programs, I want them to open the one .exe file, and that's it. My problem here is actually getting the trigger to talk to VB.NET, I've never done any peripherals with VB.NET, so I'm pretty clueless. I don't need the trigger to respond with any data other than some sort of ping that VB.NET can pick up.

I've also been thinking about using the ultrasonic/motion sensor to interface with a USB keyboard encoder, to output some obscure character, and then have VB.NET watch for that character, and react when it's pressed. The problem here is that I don't want the program to have to be the main window, I want the user to be able to have it open and not worry about it.

Any help that anyone can give me with either the coding side or with the trigger side is really appreciated, thank you all in advance :)

sort by: active | newest | oldest
I do this type of programming at work (not magnets and door chimes, but digital/analogue inputs and automation of other hardware based upon the input).  I use LabJack products, but there are cheap alternatives like this one:
http://www.pc-control.co.uk/digibee_info.htm
This allows simple VB integration through a .dll library, and there are some brief code examples on the site.  Google around though, as there may be alternatives.

As someone else pointed out, using a microcontroller would be very simple too.  Atmel have an example "voice recorder" circuit with amplifier and everything which could easily be adapted, and digital inputs is what microcontrollers do best:
www.atmel.com/Images/doc1456.pdf
iBurn (author)  triumphtotty5 years ago
Okay, I'll keep that in mind. I'm trying to do as much of this myself as possible since it's my senior project.
Currently I'm playing around with using a keyboard encoder to input a character into the computer, and then having VB.NET pick it up as the trigger and respond accordingly.
I'm definitely bookmarking that Digi-Bee, thank you! :)
You're welcome.  There may be an issue with your method in that the VB application has to have focus to pick up the keypress.  If you used the PC for something else, or accidentally clicked on the desktop, then the keypress would pass to whatever is focused at that time I think.  You could always startup your application, unplug the mouse and keyboard, and your HID encoder would then be the only input source.  Or you could write a fullscreen application (a bit like a screensaver with no ability to get rid of it?) to prevent focus from being lost.  If you can lay your hands on an old Net-top (e.g. an EeePC) which only uses 15-20W of power too, that would be neat!  I'm a VB.NET developer by day, so just yell if you have any coding problems.  Cheers and good luck, T.
iBurn (author)  triumphtotty5 years ago
Actually I've got some code so that VB.NET will catch the button no matter what the focus is on. Here it is if you want to take a look:

http://pastebin.com/tudMPDuW
That's amazing, and it should work nicely. Seems to work right up to Win7 64-bit too. :)
iBurn (author)  triumphtotty5 years ago
:) Thank you!
Does this have to be interfaced with a PC? If you trying to make a little alarm system that can play an audio file all that can be done on a micro controller. Then all the hardware can be in one simple box with no wires having to be ran across a room.

Sounds like you don't really need a PC for this since you only want an audio file to play. Any micro controller like the Arduino can do this for you. There are a great many sensor options you can use with the Arduino and even an attachment that will play back MP3 files. So you can connect everything up to one little device. It is all programmed in a derivative of C++. If you need to interface with the PC you can do that too as the Arduino can stay tethered to the PC through a USB cable and send serial data back to the PC for a VD.Net app to read and use.
iBurn (author)  mpilchfamily5 years ago
Sorry, I thought I answered this yesterday morning, but I guess it didn't go through.

For the most part it does have to go through a PC. I'm trying to do this as cheaply as possible, and I thought about an arduino, but I figured that if it was on a computer then I'd be able to use VB.NET to make a nice looking GUI and schedule for when it goes off.

Currently I'm playing around with using a keyboard encoder to input a character into the computer, and then having VB.NET pick it up as the trigger and respond accordingly.