---
tag: m0042
title: Set Pin State
brief: Set an analog or digital pin to a specified state.
author: thinkyhead

requires: DIRECT_PIN_CONTROL
group: control
codes: [ M42 ]

notes:

parameters:
  -
    tag: I
    optional: true
    since: 1.1.9.1
    description: Ignore protection on pins that Marlin is using.
    values:
      -
        type: bool
  -
    tag: T
    optional: true
    since: 2.0.5.2
    description: Set the pin mode. Prior to Marlin 2.0.9.4 this is set with the `M` parameter.
    values:
      -
        tag: 0
        description: '`INPUT`'
      -
        tag: 1
        description: '`OUTPUT`'
      -
        tag: 2
        description: '`INPUT_PULLUP`'
      -
        tag: 3
        description: '`INPUT_PULLDOWN`'
  -
    tag: P
    optional: true
    description: A digital pin number (even for analog pins) to write to. (`LED_PIN` if omitted)
    values:
      -
        tag: pin
        type: int
  -
    tag: S
    optional: false
    description: The state to set. PWM pins may be set from 0-255.
    values:
      -
        tag: state
        type: int

examples:
  -
    pre: Turn the LED pin on
    code: M42 S1
  -
    pre: Turn on pin 33
    code: M42 P33 S1
  -
    pre: Set pin 44 to do PWM with 50% DC
    code: M42 P44 S128

---

For custom hardware not officially supported in Marlin, you can often just connect up an unused pin and use [`M42`](/docs/gcode/M042.html) to control it.
