Shop OBEX P1 Docs P2 Docs Learn Events
Basic stamp 2 with TIP 120 — Parallax Forums

Basic stamp 2 with TIP 120

BornaBorna Posts: 36
edited 2014-07-27 19:04 in BASIC Stamp
Hello all,
I am very new to MC and need help
I am trying to drive a solenoid with Basic Stamp 2 using TIP 120 transistor
Here is my diagram and code
As you can see the code is very simple. All I want to at this point is to activate the solenoid 10 sec

' {$PBASIC 2.5}
' {$STAMP BS2}
HIGH 7
SLEEP 10000
LOW 7

what happen is at the start of the program, the solenoid will become active for about 3 secs then become deactivated for a fraction of a sec and immediately become active again for about 3 sec, and follow the same pattern continuously

The following code doesn't do anything
' {$PBASIC 2.5}
' {$STAMP BS2}
LOW 7
SLEEP 10000
HIGH 7

The following code behaves like the first scenario
' {$PBASIC 2.5}
' {$STAMP BS2}
HIGH 7

Comments

  • BornaBorna Posts: 36
    edited 2014-07-27 09:02
    I forgot the attachment
    tip.jpg
    462 x 346 - 8K
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2014-07-27 10:05
    SLEEP 10000??

    Try PAUSE 10000
    HIGH 7
    PAUSE 10000
    LOW 7
    PAUSE 3000
    
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2014-07-27 11:10
    bonkbonk:
      HIGH 7
      PAUSE 2500
      LOW 7
      PAUSE 2500
    
    GOTO bonkbonk
    
    
    DO
      HIGH 7
      PAUSE 2500
      LOW 7
      PAUSE 2500
    LOOP
    
  • 72sonett72sonett Posts: 82
    edited 2014-07-27 11:43
    No flyback diode over the solenoid?
  • ercoerco Posts: 20,257
    edited 2014-07-27 14:01
    Batteries low? Solenoids pull lots of current and the battery voltage drops over 3 seconds, Stamp resents. Try a bigger system battery or a seperate battery for the Stamp.

    Also, your 1K base resistor may be too high. Try 330 ohms.
  • BornaBorna Posts: 36
    edited 2014-07-27 14:35
    thank you all.
    The issue was sleep instead of pause.
    Changed that to pause and working fine.
    No sure why I used sleep? :)
    maybe I was thinking Java

    Would you also tell me if the diagram looks correct?
    As mentioned, do I need a diode between Pin 7 and the resistor?
  • ercoerco Posts: 20,257
    edited 2014-07-27 19:04
    You should put a flyback diode across (in parallel with) your solenoid. Reverse-biased, so no current flows through it when the solenoid is energized. Doesn't do anything obvious, except when your switch off your solenoid, a huge (many thousand volts, likely) voltage spike is produced as the magnetic field collapses. That voltage spike can damage your I/O pin, but the diode absorbs that energy to protect your Stamp. You can use a rectifier diode (1N4001 type) or signal diode (1N914 type). Always good practice to add such a diode on relay coils and especially a huge solenoid coil such as you have.

    http://en.wikipedia.org/wiki/Flyback_diode
Sign In or Register to comment.