I want to make pin no.15 (GPIO 22) as HIGH automatically, when the RPi is powered up. (Raspberry Pi 3 Model B)

The status of the pin is used for a power on logic. This pin is used to check whether the device is ON or OFF.

Any help is appreciated.

3 Answers 3


You cannot control the state of a pin on power up. The default state of pins is given in https://raspberrypi.stackexchange.com/a/32643/8697

You can set the state of pins in Device Tree, but there will be some delay. The answer https://raspberrypi.stackexchange.com/a/32643/8697 discuses this. Whether that delay is acceptable depends on what you are connecting.

The default Device Tree settings configure most pins as inputs.

You would be better selecting a pin which is high by default, but the choices are limited. Another option is to reverse your circuitry so a Low is the default.


It occurred to me you could use the inbuilt gpio-poweroff if you are prepared to invert your logic.

dtoverlay=gpio-poweroff,gpiopin=22 would cause the pin to go low after the Pi powers up (still NOT on power up, but using DT very shortly after). When the Pi is shut down it would go high.

There is an option active_low, but this seems to require custom code.

Name: gpio-poweroff
Info: Drives a GPIO high or low on poweroff (including halt)
Load: dtoverlay=gpio-poweroff,=
Params: gpiopin GPIO for signalling (default 26)

   active_low              Set if the power control device requires a
                            high->low transition to trigger a power-down.
                            Note that this will require the support of a
                            custom dt-blob.bin to prevent a power-down
                            during the boot process, and that a reboot
                            will also cause the pin to go low.

Found the solution.

made an executable with the pin I want to be HIGH all the time (I've used wiringPi library) after the Pi is powered up. Then I put the file in rc.local

sudo nano /etc/rc.local

just before exit 0 , append the following :

sudo /path/to/the/executable/my_prgm &

The '&' is a must( for continuous running in background -- for producing pulses, otherwise will execute once -- good for pin state change). Don't forget to put it there.

Ctrl+X , followed by Y and Enter, to save the file. And `reboot'

To kill it, in the terminal , sudo killall my_prgm

  • 1
    This will not set the state of the pin "when the RPi is powered up" which is the question you asked. If you had asked how to set the state after the Pi has booted you would have got a similar answer at the time. NOTE this is one solution, but not the best. There are better solutions which set the state earlier, and independently of user code.
    – Milliways
    Jan 7, 2017 at 10:59
  • If you need to use & this means your program is continuously running in the background. If all you want to do is set the state of a pin this should not be necessary and you are needlessly consuming resources. You can write a program which changes pin state then exits.
    – Milliways
    Jan 7, 2017 at 11:09
  • Oh I understand. I want to set the state on power up. Can you help me with this one?
    – Sam
    Jan 9, 2017 at 4:03
  • 2
    As I stated in my original answer You cannot control the state of a pin on power up. If you want to set ASAP after, you can configure in Device Tree. This is a complex area, described in github.com/raspberrypi/documentation/blob/master/configuration/… The defaults are in the .dtb files in /boot, and you can download the dtb compiler and source files. You could modify these or make an overlay. I have done this, but it is best avoided and you would be better selecting a pin which is high by default (again as I suggested in the answer).
    – Milliways
    Jan 9, 2017 at 4:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.