I haven't yet started this project, but I am trying to figure out the best way a trigger a relay when a button is clicked on a UI in java. The relay will release a lock on a door when the button is clicked. I've looked at rasberri pi, but I am not familiar with that product. Can anyone suggest how I should go about doing this?
-
Well, where is this UI running? – OldProgrammer Sep 20 '15 at 19:03
-
What is a real platform? This question is quite rare with Java, but You must execute non-portable operation for example with serial port. – Jacek Cz Sep 20 '15 at 19:04
-
http://stackoverflow.com/questions/3246077/controlling-simple-relay-switch-via-usb – mlwn Sep 20 '15 at 19:05
-
On a single PC, about 10 feet from the door that needs to be locked/unlocked. This is an office application. – Cannon Moyer Sep 20 '15 at 19:07
-
http://denkovi.com/usb-eight-channel-relay-board-for-automation – mlwn Sep 20 '15 at 19:09
1 Answers
I've implemented this in several different ways and indeed done all sorts of device interface with Java for engineering experimentation and automation.
The real question here is do you have a specific relay device in mind as this is going to drive how you implement a Java interface? As examples, the two most recent Java-Relay applications I have implemented involved one of the following devices:
- Case 1: Using Java to control low contact resistance measurement/signal SPDT(Single Pole, Double Throw) relays
- Device: Keysight (Agilent/HP) 34970A and the 20 Channel Switch Unit
- Case 2: Using Java to control SPDT power relays
- Device: SainSmart USB Relay Board
In Case 1 I used RXTX which is a Java serial port implementation to interface with the Agilent 34970 using a serial port.
In Case 2 I used the JavaFTDI package to interface directly with the FTDI chip onboard the relay board using BitBang mode. While I eventually go this option working, the combined lack of documentation from FTDI and SainSmart made me gouge my eyes out for days.
Certainly you could alternatively use a Raspberry Pi and its GPIOs to either control a separate relay purchased from Digi-Key or in fact use the GPIOs themselves as a relay assuming very low voltage was used. I'm imagining two scenarios, one where the user is actually directly interfacing with the Pi or another where the Pi is on the network and through a user interface running on a separate PC the user is leveraging RMI to cause the Pi to change GPIO states.
Really, what I would suggest is looking at what relay you want to use, and post a more specific question regarding how to interface to that relay assuming Java is your preferred language. Alternatively, you could ask what the lowest barrier to entry/learning curve/cost options there are for relays that can be controlled through Java. Without more detail, it's hard to recommend a path forward.

- 168
- 9
-
I ended up going with case 2. I looked into the JavaFTDI package but cannot seem to figure out which code I need in the project I need to use (there are several folders containing many different classes with the same names). @automation – Cannon Moyer Sep 26 '15 at 13:32
-
Did you end up ordering one of those relay boards as well or are you just looking at the software? Now that you've picked specific relays and software I'd recommend editing your original question and asking to open the question back up since the mods closed it. I'll try and put an example together. – Automaton Sep 27 '15 at 15:38