I have an easy circuit wired up, with an LED connected to pin 18 on the BOARD reference. I run a simple program to put pin 18 to HIGH, which turns the LED on, and then a couple of seconds later, I set pin 18 to LOW, and finally I end my program with GPIO.cleanup().

At this point the LED is off, which means that pin 18 is off (LOW). Now I reboot or restart my Raspberry Pi, and when it boots back up, the LED on pin 18 turns on again, even though the pin was off before I rebooted the Raspberry Pi.

Why may this be happening? How can I configure a specific pin, like pin 18 to be off when the Raspberry Pi boots up? And I don't want any GPIO pins to be on HIGH when the Raspberry Pi boots up.

I am concerned about this problem, because let's say that pin 18 is connected to a DC motor on a robot, and when the Raspberry Pi boots up, the motor will turn on, and this is not something that I want because that will interferes with the whole structure of the robot, and some motors might start and others won't, depending on the pins they are connected to. I want to manually turn on all the motors in a synchronized manner.

One other thing is that not all the pins have this problem. Some stay off when the Raspberry Pi boots, but others don't.

Peter Mortensen
  • 2,014
  • 2
  • 15
  • 17
Viktor Raspberry
  • 415
  • 2
  • 4
  • 8
  • Is that LED on as brightly as it would be when you set it high, or is it just glowing dimly? – goldilocks Jun 18 '15 at 08:19
  • There is 3.3 volts applied to it. – Viktor Raspberry Jun 18 '15 at 12:07
  • So if you go into `/sys/class/gpio` and export pin 18, what state does the system then say it is in if you change nothing? – goldilocks Jun 18 '15 at 14:05
  • When I write "/sys/class/gpio" , it says "-bash: /sys/class/gpio: Is a directory". I am not sure how to export a specific pin. – Viktor Raspberry Jun 18 '15 at 15:43
  • There are oodles of [explanations of that](http://raspberrypi.stackexchange.com/a/1129/5538), so I won't bother to regurgitate. That example is kind of heavy on the `echo`, which writes, i.e., sets something. After you export it you want to refrain from that and just use `cat`, which reads, to check the direction and the value. – goldilocks Jun 18 '15 at 15:50
  • Thank You for the link. I did all the steps that the tutorial showed, and the LED's turned off, then I did "sudo reboot", and when it rebooted, the same LED's turned on again at boot. I am guessing that the settings are not being saved or something. – Viktor Raspberry Jun 18 '15 at 16:04
  • No, as various people have pointed out, the pins have a default state at boot. As per the Broadcom pdf in joan's answer though, that pin should be low at boot, although the OS may change that -- which is why I said you should use the OS `/sys` interface to **check the settings**, not to play with them. If they confirm it's set high before you change anything, then the physical state is consistent with the OS, and (if you want) you can investige the device tree angle. Note doing the export *may* change the state -- obviously you will notice with the LED -- I'm not sure of the rules there. – goldilocks Jun 18 '15 at 16:10
  • Just to clarify, setting that stuff in `/sys` doesn't persist across boot. Those aren't real files. They're in memory conduits to the kernel (when you read one, you're asking for information, when you write to one, you're sending the kernel a setting), which is why they all have a size of 0, etc. – goldilocks Jun 18 '15 at 16:15
  • Out of curiousity, does this LED turn on *immediately* when you plug in the power, then stay on, or does it only come on after a few seconds? I'm not sure if there is enough time to notice a difference between the power on state and any state that might be set by the kernel when in loads, but there might be. That would be the delay between the red PWR LED built into the board and your LED on pin 18. – goldilocks Jun 18 '15 at 16:20
  • I looked at Joan's PDF, and I analyzed the states of the GPIO's, and I am not sure how to set and configure those pins which are naturally set to HIGH, to LOW, and to save those settings, I am very new to raspberry pi, and I dont know much, so sorry that I am not understanding very well. – Viktor Raspberry Jun 18 '15 at 16:21
  • Regarding your question, wheter or not the LED turns on right after the power is on. The answer is not, the raspberry pi boots up, those texts and lines come up, where everything loads, and after like 5 to 10 seconds the LED's turn on. – Viktor Raspberry Jun 18 '15 at 16:24
  • You CANNOT change the default state at power on, That's carved into the hardware. So if you absolutely cannot have this pin high, you need a different pin, or as joan suggests additional hardware. If it is on immediately when you apply the power, that's the issue, which is odd since the spec says GPIO 18 is low. If it is the OS, you *can* change that. Also, you can use the OS to set it at boot, if you are okay with the few seconds that will take. This is why you need to determine the difference, and what `/sys` says at boot. – goldilocks Jun 18 '15 at 16:28
  • To re-iterate my other point, if you are sure there's really 3.3 V there great, but note an LED connected to an input pin on low at boot *will light up*, just not as strongly as it would with the pin on output set high. This *does not* indicate 3.3V of power. It is because the input floats and there may be 1-2 V there. – goldilocks Jun 18 '15 at 16:31
  • Ok I get it now, its unfortunate that I can't change the state of the pins which are naturally set to HIGH, but that's the way it is. – Viktor Raspberry Jun 18 '15 at 16:35
  • Another thing I can do is set a python program to run at boot, and that program will set all the GPIO's which are HIGH to LOW. – Viktor Raspberry Jun 18 '15 at 16:36

3 Answers3


At powerup the GPIOs are pulled either high or low through the internal resistors. Whether the pull is high or low for a particular GPIO is detailed on page 102 of BCM2835 ARM Peripherals.

As the Linux kernel is started and if device tree is enabled (likely) then it will reconfigure the GPIOs according to the device tree settings. Modules loaded from /etc/modules could also update the GPIO state.

Any other software you have running at start up could potentially reconfigure the GPIOs subsequent to the device tree settings and module loads.

It is safest to find a hardware solution if you have hardware which could be incorrectly triggered at system startup.

Peter Mortensen
  • 2,014
  • 2
  • 15
  • 17
  • 70,096
  • 5
  • 71
  • 105

When the Raspberry Pi boots the GPIO lines are reset to the chip default, then the OS is loaded and resets them to the OS default. There is no way to "remember" the settings across a reboot. See also What is the power on state of the GPIOs? and GPIO state after boot.

  • 906
  • 1
  • 6
  • 20

I know it's pretty late. To answer. You can write a python script or bash script which manually sets the pin to low and schedule a cron job to run at every boot. You won't need to modify any system/critical files. Apart from cron

  • 21
  • 1