Using an Arduino to seeif a USB stick has been inserted into computer/connected?

I have an odd question that I cant really seem to wrap my head around.

Project summary:

1.) 'standalone' Arduino circuit (ie: battery driven) embedded into a project based

2.) same project has a USB memory stick embedded into its base along side Arduino.. (so the user can plug in the 'project' into their USB hub and use it for storage...etc..

**(Im actually hoping/[planning on embedding a flash app/movie that autoplays when the USB stick is inserted.. but that is not Arduino related)

What I would like to do is somehow check/alert the Arduino when the usb stick is inserted.. (& in turn blink some lights or play a sound..etc)

but am un-clear on approach I can even take.

I first thought.. maybe crack the case open and tap the led pad? to check for it being 'hi/on'?

but I dont think it has an led light....

extending the same train of thought... (cracking open the case).. maybe tapping/checking the +5v line or something from the USB power? (that is powering the usb memory stick)

ideas?

again this is NOT checking to see if USB on arduino is connected.. (my custom board doesnt even have a USB port on it)..
this is trying to spitball ideas on checking to see if an external USB memory stick has been connected to the pc? (I suppose gets power would be enough though too)

thanks!

Monitoring the USB power line would seem like your most feasible option. Obviously it would be easy to break into that by connecting your memory stick via an extension lead.

As in just soldering/tapping the V++ line in the USB memory stick/Flash drive?.. and then using that line as my 'digital' input to whatever pin I want on my Arduino...yes?

I can safely use the jumper/wire as is...being that it will only be 5v max.. this is safe to use by itself on an Arduino pin?

thanks

Well, I'm envisaging you breaking into the extension cable and not hacking the USB device itself, but yes that's the general idea.

I seem to recall that the Arduino may be damaged if the voltage on an input pin is greater than the voltage on the Arduino's 5V pin so if you're powering the Arduino separately it would pay to check the voltages carefully. If in doubt, use a voltage divider to bring the voltage you're sensing down into a safe range. From memory the threshold of a digital input is 60% of the 5V voltage so if you arrange the voltages appropriately you could use a digital input to detect the USB voltage. Or use an analog input, read the analog value and compare to a threshold - easy enough either way, but you if you're short of analog pins bear in mind that you don't strictly need an analog pin for this.

I have most pins open at this point.. just trying to brainstorm the project specs a bit..

There is no 'cable' to hack.. its a USB flash drive.. standalone unit.. (not a USB hub or anything)..

this is to be embedded into a project base.. so it can be connected to a computer.. and used a normal USB memory stick.. (more or less)..

I'd like to however keep tabs on this.. so I can play a tune or blink some leds when its first gets connected.

the Arduino itself will be battery powered (7.4v li-ion pack)....

xl97:
There is no 'cable' to hack.. its a USB flash drive.. standalone unit..

This is why I suggested connecting via a USB extension cable, so that you can access the USB electrics without physically breaking into your flash drive's enclosure.

ahh..

reading back I see now what you meant by 'extension lead'..

not sure if it'll work like that though.. as an extra extension cable would be removable from the usb stick..(base of the project)..

so Im guessing I 'have' to try and tap the flash drive directly somehow..

thanks

xl97:
ahh..

reading back I see now what you meant by 'extension lead'..

not sure if it'll work like that though.. as an extra extension cable would be removable from the usb stick..(base of the project)..

so Im guessing I 'have' to try and tap the flash drive directly somehow..

thanks

Or just put the whole assembly in a project box. Apply epoxy/duct tape as needed. Depends on how user-proof you want it. You have to have something to mount the LEDs to anyway, right?

xl97:
an extra extension cable would be removable from the usb stick..(base of the project)..

I can't understand what problem you're referring to there, so presumably there's something else going on that I haven't understood. Isn't your Arduino going to be inside an enclosure? Is the USB flash drive contained inside the same enclosure, or plugged into it by an external socket? How does the whole thing plug into a PC USB port - directly or via a lead?

think of a base.. which is nothing more than a flat box..(maybe .5-1.0 in tall) probably 5 x 5 square..

the battery pack & Arduiono are in there..

the usb memory stick is ALSO in there..

there is will be a little slot for the memory stick to either slide out, (like most memory sticks do now, on their own to protect the usb port side)..or have an opening the same size as the USB port.. so you can use an extension cable to plug it into the computer..

think of it as a wall plug/outlet...(USB) on the side of the project base

(so to answer your question.. it could be directly connected.. but most likely, someone will use an extension cable to connect the project to the computer)

Im failing to see how even hacking/using the cable in this approach is even feasible??

the cable would be plugged in to use the memory stick..and unplugged when not in use with the PC...

how could I 'hack/use the cable? to make contact with the Arduino?.. (cant)

so I need to somehow tap the memory stick itself.. as its right by the Arduino..

@wizdum-

I dnt understand your suggestion?

It IS more or less going in a 'project box'.. however there are NO cables going to be sticking of if this project.. only 1 PORT (the usb memory stick)
and it will all be secured down. (what am I missing here?)

ok.. let simplify this..

I have a box with Arduino & a usb memory stick..

this box has one 'hole/opening' where the usb memory stick port is located.

when use connects this box either directly to their PC.. or is they use an extension cable to connection it.. what is best approach to detecting when the usb memory stick has been connected to a PC (or given power..we'll use that as its easier)..

hacking a 'cable' will not work..

(at least I cant see what your suggesting, how it will work in this application?)

hacking a cable/cord... how does it ever make connection with the Arduino? (no access to it? no wires to it?)

the only access you have is the normal action of connecting your usb memory stick..

internally the Arduino can 'connect' to the usb memory stick.. (IM hoping to tap the power rail on the USB memory stick.. and use a dsigital pin to say.. OH>. the USB memory stickk has power.. (must be connected to the PC).. DO SOMETHING ARDUINO!!!!.... DO SOMETHING!!!! :wink:

thanks!

This is all being connected to a computer anyway. The Operating System certainly knows when a USB device is attached. Why not write a program on the PC to monitor for when the device is attached or not, possibly sending a message to the Arduino over USB/Serial to let it know?

well the computer/connection was just to use usb 'memory' stick.. (not connected to Arduino at all)

so they could use the prop/project as a functional device as well..

(sorta like you see those toys with embedded usb stick in them for flash drives...etc)

so are you suggesting two usb cables be used?

(also my custom arduino/standalone board doesnt have a usb port on it as mentioned above) :wink:

I think just taking the usb memory stick and finding a pad to tap/jumper off of is the best idea/approach TBH..

just not sure if I can just grab the 5v from the usb stick/rail/pad and tie directly to a digital pin to get a hi/low reading?

I'm completely confused what you are doing and why would the Arduino care if a "USB Memory stick is attached"? I'm also not sure what you mean by "USB Memory Stick".

1.) when the user takes the prop and connects it to the PC.. I want the Arduino (to know the usb/flash drive has gotten power) and to make the prop do something (move, blink leds, make a sound)

2.) I am saying USB/Memory stick (flash drive, thumb drive.. whatever you want to call it) to separate it from anyone thinking about a USB port on the Arduino circuit end of things.

maybe this help illustrate the project better? (visually)

a box.. with standalone/powered Arduino circuit..

in same box/enclosure.... there is a USB stick/memory stick/flash drive/thumb drive/jump drive.. (whatever you fancy to call it)..

I am looking for an approach to tell when the usb drive is plugged into the computer.. (ie: I think it getting power should be enough to signal this)..

so I want the Arduino to 'check' for this.. when it happens.. (ie: that pin goes HI).. do something based on the code.

xl97:
hacking a 'cable' will not work..

I can't understand what problem makes you say that. To me it seems trivially simple.

Decide what type of USB connector you want this contraption to present to the PC. Perhaps you will decide to present a USB A male connector, the same as a typical USB memory stick. (There are other options.)

Get a USB cable which has the required USB connector at one end, and a USB A female socket at the other end. If you're presenting a USB A male connector, then this will be a plain old USB A male-to-female extension cable.

Plug your USB flash drive into the relevent end of the cable. Attach the other end to your enclosure so it presents the right external interface. You now have an internal lead connecting to the flash drive. You are free to hack into this cable to expose the 5V and ground lines for your Arduino to sense. If you want to be slightly more elegant about it, instead of using an extension lead you'll use a lead which has a panel-mount socket; this would have exposed terminals at the back which you could connect to directly.

What's the problem?

to me your solution is saying to always have some 'pig tail' cable sticking out of the prop.. (not acceptable)..

I dont know what you mean by this: "Decide what type of USB connector you want this contraption to present to the PC"

I cant really 'pick/decide' anything.. (unless your suggesting make some 'go-between' board between the flash drive and the cable)?? which is silly, and way more work than would ever need to be done. the flash drive has a predetermined usb connector/end.. (that fits directly into a usb port on a PC)

the image explains it. thats whats inside the 'box' with a slot for the fllsh drive end to stick out

there is a 'slot' in the prop/project base that exposes the flash drive/memory stick so it can be connected to a computer.

thats just how it works/is.

so while you could use an extension cable to connect the prop/project to the PC.. there is no way to make any contact from the outside of the box (where the cable resides/connects to the flash drive).. to the inside of the box (where the Arduino resides)..

I just dont know how to explain it any clearer than that