Shop OBEX P1 Docs P2 Docs Learn Events
stamp controlling lamp, controlled by Macintosh via USB — Parallax Forums

stamp controlling lamp, controlled by Macintosh via USB

Egon 4uEgon 4u Posts: 13
edited 2007-09-29 18:11 in BASIC Stamp
I have a simple application:

A Macintosh G5 running OS X is performing some task. Periodically, it will send a control signal to a black box, telling it to turn on a lamp for X amount of seconds.

The black box will have a Stamp at its core, which will use one of its I/O pins to turn the lamp on/off (lamp runs on three AAA batteries).

Basic questions:

1) What's a safe circuit to use between the Stamp and the Lamp? I know I need a resistor, followed by a transistor (1N4001?) followed by a relay. Can someone with experience in this kind of thing suggest values for the resistor, and relay?

2) The MAC's USB port is going to be adapted into an RS232, which I can easily interface to from the Stamp side. Does anybody know an off-the-shelf solution for adapting a USB to RS232 on a Mac?

I look forward to reading replies to my first posting! It's a great forum.

Egon

Comments

  • Shawn LoweShawn Lowe Posts: 635
    edited 2007-09-27 19:50
    Look at this post about controlling 120 V AC:

    http://forums.parallax.com/forums/default.aspx?f=5&m=219658

    I am not sure about the signals between your Mac and the stamp, but I'm someone will! [noparse]:)[/noparse]

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Shawn Lowe


    Maybe I should have waited to do that......
  • Egon 4uEgon 4u Posts: 13
    edited 2007-09-27 20:01
    Shawn,

    The lamp runs on DC (4 AAA batteries).

    I should also mention that I have committed already to a stamp BS2, so I'm looking for some circuitry that will complement that chip, and not replace it.
  • FranklinFranklin Posts: 4,747
    edited 2007-09-27 21:22
    Depending on the current the lamp requires (it can't be much) you probably don't need the relay. As for the usb to serial check out FTDI to see if their devices work with the mac. (probably do) There are several good documents and articles at the main parallax site on controlling real world devices. Take a look at the stamps in class links.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • Egon 4uEgon 4u Posts: 13
    edited 2007-09-28 07:30
    Stephen,

    I should be more specific about the "lamp". It's a siren type of lamp, which rotates and shines quite bright. You can hear the motor whirring when it's active. So it's really a lamp and a motor.

    I don't have any specs on the current draw, but it must be more than the specified BS2 limit of 40 mA.
  • Egon 4uEgon 4u Posts: 13
    edited 2007-09-28 07:33
    Correction on batteries: the siren uses 3 AA batteries
  • Egon 4uEgon 4u Posts: 13
    edited 2007-09-28 09:03
    further report on characteristics of siren:

    I put a meter on the motor and turned the thing on. The meter said 4.5 A and the motor did not go on! I removed the meter and the motor instantly went on.

    I'm obviously not really sure how to measure the current draw of my siren. I found no specs on the web. Can a device draw so much current from 3 AA batteries?

    I've also been following the discussion in "pwm power transistor" (http://forums.parallax.com/forums/default.aspx?f=5&m=218027). Very useful links and schematics. Perhaps I don't need a relay at all, and instead can use transistors with sufficient hfe?
  • Egon 4uEgon 4u Posts: 13
    edited 2007-09-28 09:36
    i'm a little quick on that SUBMIT button, sorry about the clutter...

    OK, the current draw of the alarm/lamp is measured to be 300 mA (makes more sense).

    So what if I used an I/O pin, to a resistor R, to the base of a 2n3904 (hfe=30). emitter to Vss, collector directly to (-) of alarm/lamp. The (+) of the alarm/lamp would be connected to Vdd, and to the cathode of a diode (anode connected to ground). Diode is 1N4001.

    R is 3.8V / (10mA * 2) = 190 (say 220 Ohms).

    The *2 is to ensure saturation overhead; 20 mA is within the 25 mA that an I/O pin can sink. The 10 mA in the denominator is 300 mA / 30 hfe.
  • Mike GreenMike Green Posts: 23,101
    edited 2007-09-28 13:37
    The diode is normally connected across the motor / siren / coil to dissipate the reverse EMF energy before the reverse voltage gets high enough to damage anything. Connecting it from Vdd to ground won't do much to protect the transistor. The rest of the description sounds OK.
  • Egon 4uEgon 4u Posts: 13
    edited 2007-09-29 17:21
    Mike,

    Thanks for noticing that mistake. Diode will be connected across the siren.

    I was just ordering the parts. I noticed that 2n3904 transistor is rated with a maximum Ic of 200 mA. I was measuring the alarm taking 300 mA, so now I am questioning the use of this part. Should I be using a high-power transistor instead? The hfe is also listed as 100/300. I was expecting hfe to be 30, based on a diagram I saw in the "pwm power transistor" thread. Am I missing something here? That application was talking about over 2 Amps of current!
  • Tracy AllenTracy Allen Posts: 6,664
    edited 2007-09-29 18:06
    Yes, the 2n3904 would be underrated and would probably go !pop!. You might want to go for a MOSFET like the IRL510 (or 520, or 530). They come in a larger TO220 package and can handle the current easily. The Stamp can connect directly to the gate, and there should be a pulldown resistor from gate to source, but otherwise the circuit is the same as you have outlined. If you want an NPN transistor in a small TO92 package similar to the 2n3904, the Zetex e-line transistors are remarkable in terms of the hfe (~400) and the current (4 amps pulse) and power ratings (1 watt).

    For the Mac, you can use just about any USB to Serial adapter for a data link. However, if you want to use the Mac to program the Stamp, the only ones known to work well are the FTDI adapter and the Keyspan PDA adapter. Are you aware of MacBS2 for the Mac?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • Mike GreenMike Green Posts: 23,101
    edited 2007-09-29 18:11
    Frankly, I'm partial to using logic level MOSFETs for this sort of thing. Here's an example from a manufacturer of replacement parts: www.nteinc.com/specs/2900to2999/pdf/nte2980.pdf. I've seen this on the internet for about $2.50 and it can switch up to 7A. You connect the gate directly to the Stamp I/O pin and put a 10K to 100K resistor from gate to ground to ensure the MOSFET stays off before the Stamp pin gets initialized to an output state. The MOSFET has a built-in reverse diode, so you don't need to supply one.
Sign In or Register to comment.