Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 5 of 5

Thread: controling Power Pin with code? (on/off)

  1. #1
    Junior Member
    Join Date
    Aug 2019
    Posts
    4

    controling Power Pin with code? (on/off)

    Hello,

    I have Teensy 3.2.
    I want to know if I can control the power Pins with code? I mean can i switch the power on and off on that particular pin?

    For example, I want to connect a fan on Pin 26 (that is 3.6 to 6.0 volt pin) and turn it on and off for a particular condition like when temperature goes above 26C turn it on, etc. Is it possible? What command you use for powering Pin 26 On/Off (if possible).

    Thanks in anticipation.

  2. #2
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    3,135
    First you must set the pin to output via pinMode(pin, OUTPUT);
    Then you can use digitalWrite(pin, HIGH) to turn it on and LOW to turn it off. However, you should NOT source power from the pin itself, the pin should be on a transistor or mosfet which controls the fan

  3. #3
    Senior Member
    Join Date
    Nov 2015
    Location
    Cold hollow VT
    Posts
    120
    @tonton81 is on the money for controlling external devices. To control the whole Teensy circuit you would have to add a device similar to the AdaFruit Push-Button-Powewer switch breakout. That device uses a push button to operate a latch and a power mosfet. The other side of the latch can be controled by a digitsl pin to turn the latch 'off'. I have also seen other latch circuits that allow touch operation to toggle the state of the latch with a short touch for 'on' and a longer touch for 'off'.

  4. #4
    Junior Member
    Join Date
    Aug 2019
    Posts
    4
    Quote Originally Posted by tonton81 View Post
    First you must set the pin to output via pinMode(pin, OUTPUT);
    Then you can use digitalWrite(pin, HIGH) to turn it on and LOW to turn it off. However, you should NOT source power from the pin itself, the pin should be on a transistor or mosfet which controls the fan

    I get it. What you mean is, don`t connect the fan directly to pin 26 right? I have a 4V mini fan that i want to automate.

  5. #5
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    3,135
    Correct, the fan must get it's power from the mosfet or transistor, the teensy pin must only allow the signal to tell the mosfet/transistor to turn off or on. There are relay boards and mosfet breakouts you can find on adafruit, or build one using simple online circuits

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •