How to use a switch to use 5V DC or 5V PWM from an Arduino

Discussion in 'The Projects Forum' started by ramosjos321, Feb 12, 2019.

  1. ramosjos321

    Thread Starter New Member

    Jun 8, 2017
    3
    0
    I'm trying to modulate a gas sensor heater but am having difficulty doing so.
    I want to use a normally open switch (SPST type) to control the voltage. When
    the switch is open the heater should receive 5V DC. When the switch is closed,
    the heater should be getting 5V PWM from an Arduino. Note that the heater is
    already connected to +5V and the PWM from the switch is connected to GND.
    The idea is that when the switch is closed, the PWM is shorted. When the switch
    opens the heater should get a 5V DC. What's happening is that when the switch is
    open, the heater is getting a positive [0,5V] PWM and when it is closed, it is getting a
    [-5V,5V] PWM. Is there a better or easier way to do this? Any help will be appreciated.
     
  2. danadak

    Distinguished Member

    Mar 10, 2018
    2,903
    629
    In code you can set the PWM compare reg such that it outputs
    DC high. That would be a way of using one pin to both effect
    DC and, when needed, a duty cycle PWM wave.

    Regards, Dana.
     
  3. danadak

    Distinguished Member

    Mar 10, 2018
    2,903
    629
    Another way use a PSOC, 1 chip, has lots of other capabilities than
    just this problem. You can see resources used / un-used right hand
    window.

    upload_2019-2-12_18-52-58.png


    This approach leaves the PWM running, just switches off the output pin
    by the OR gate. The switch input is de-bounced as you can see and fed
    to a D which captures the closing of the switch to force output pin to DC
    logic level out. When - edge is de-bounced D is reset allowing PWM
    output to pass thru OR gate to output pin.


    Regards, Dana.
     
  4. ramosjos321

    Thread Starter New Member

    Jun 8, 2017
    3
    0
    Dana, thanks for your reply but I forgot to mentioned that I wanted to do this
    with hardware as much as possible. It is part of a much larger circuit.

    Jose
     
Loading...