1

I want to develop an Android app for home security surveillance that will monitor a door. I want to connect a switch reed to the USB port of an android smartphone.

It's possible to monitor this hardware switch connected to the smartphone USB port? The app will send a SMS when the contact is open.

thegrinner
  • 11,546
  • 5
  • 41
  • 64
  • This question is off-topic for SO, and I marked it as such. However, this is well-documented. Look for the ioio kit, which uses ADB to control a USB-connected dongle, or look into using one of the cheap Bluetooth boards along with an Arduino. – 323go Nov 22 '13 at 15:44
  • @323go - untrue, software interfacing to USB peripherals is very much on topic as a programming task. – Chris Stratton Nov 22 '13 at 15:45
  • Once again, SO is for specific programming-related questions, not for requirements gathering. And any basic google search would have given the OP the answer. – 323go Nov 22 '13 at 15:49
  • Just because the task also involves some hardware does not mean that the **majority of the work** will not be a programming task. – Chris Stratton Nov 22 '13 at 15:50

2 Answers2

0

Yes, if the phone has USB host mode and you connect the reed switch to an external USB enabled microcontroller or I/O chip, but unless you have one of the few devices which allows charging while operating as a USB host, your battery will quickly be depleted. (If you have feel like looking in the kernel logs, you could probably just use your switch to apply the USB sense resistor and detect that - no micro needed).

Consider using the headset jack instead, and having the reed switch drive a simple audio oscillator and detect this with the audio APIs. This should work with all phones, even older ones, and you can keep the phone powered through the USB jack.

Another option would be to use the ADK mechanism, in which a more capable external microcontroller functions as the USB host to host (and also power) the phone. A wider range of Android devices support this (or using a firmware which instead implements an ADB host, virtually all devices support it).

Chris Stratton
  • 39,853
  • 6
  • 84
  • 117
  • First sorry for my little english and for my ignorance about the use of stackoverflow. If I have posted the question in the wrong area please let me delete the topic. I'm interested in a software solution. If possible I don't want to connect an external microcontroller to the phone or other complex hardware. Your idea about the headset jack is very good! I'll study this option. Thanx for all. I'll reply my goals!Marco – user3022324 Nov 22 '13 at 15:57
0

Ok, Surfing I've found the right code to call a number when the headset button is pressed. App will stop the call after x rings. If it's impossible I will set my receiving phone to block the call but I need the app returning on screen after the call.