Hi my first Java program to control a LED has failed, the LED does not come on even though the pin state is continuously HIGH ?

Heres the Java code :-

final GpioController gpio = GpioFactory.getInstance();
System.out.println("Setting GPIO_04 as output");
final GpioPinDigitalOutput led = gpio.provisionDigitalOutputPin( RaspiPin.GPIO_04 );
boolean currentState = false;
for (;;) {
    Thread.sleep( 1000 );
    System.out.println("Current state is " + led.getState());

This prints out :-

Setting the GPIO_04 as output
Current state is HIGH
Current state is HIGH
Current state is HIGH

etc... ?? What am I doing wrong ? why is the state continuously HIGH and why isnt the LED on ? (It comes on if I connect to the 5v or 3.3v pins so the circuit is ok)

1 Answer 1


Did you use the correct pins? There is a difference between the old Rev1 and Rev2 GPIO layout so you might used a wrong reference.

If you plan to do loads of led GPIO, the time to designa GPIO LED overview board might save you a lot of time in the future.

A good reference for pin layouts is http://wiringpi.com/pins/ However actual GPIO numbers might differ depending on which lib you're using.

  • Im using pi4j version 0.0.5 I wonder if it needs updating for PI 2 ? <groupId>com.pi4j</groupId> <artifactId>pi4j-core</artifactId> <version>0.0.5</version> Jul 18, 2015 at 17:14
  • Yes it does, updating to version 1.0 and it works beautifully. Thanks for your rapid reply. Jul 18, 2015 at 17:54

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.