1

On my RPi 3 I have a PHP website to control 10 LEDs. Each is wired to a separate GPIO pin and 220 ohm resistor.

Here is the code:

<html>

<head>
    <title>LED Control</title>
    <style type="text/css">
        input[type=submit] {
            width: 20em;  height: 20em;
        }

    </style>
</head>

<body>
    <table style="width:100%;height:100%">
        <tr>
            <th>
                <form method="get" action="gpio.php">
                <input type="submit" value="1 ON" name="led1on">
                </form>
            </th>
            <th>
                <form method="get" action="gpio.php">
                <input type="submit" value="1 OFF" name="led1off">
                </form>
            </th>
            <th>
                <form method="get" action="gpio.php">
                <input type="submit" value="2 ON" name="led2on">
                </form>
            </th>
            <th>
                <form method="get" action="gpio.php">
                <input type="submit" value="2 OFF" name="led2off">
                </form>
            </th>
        </tr>

        <tr>
            <th>
                <form method="get" action="gpio.php">
                <input type="submit" value="3 ON" name="led3on">
                </form>
            </th>
            <th>
                <form method="get" action="gpio.php">
                <input type="submit" value="3 OFF" name="led3off">
                </form>
            </th>
            <th>
                <form method="get" action="gpio.php">
                <input type="submit" value="4 ON" name="led4on">
                </form>
            </th>
            <th>
                <form method="get" action="gpio.php">
                <input type="submit" value="4 OFF" name="led4off">
                </form>
            </th>
        </tr>

        <tr>
            <th>
                <form method="get" action="gpio.php">
                <input type="submit" value="5 ON" name="led5on">
                </form>
            </th>
            <th>
                <form method="get" action="gpio.php">
                <input type="submit" value="5 OFF" name="led5off">
                </form>
            </th>
            <th>
                <form method="get" action="gpio.php">
                <input type="submit" value="6 ON" name="led6on">
                </form>
            </th>
            <th>
                <form method="get" action="gpio.php">
                <input type="submit" value="6 OFF" name="led6off">
                </form>
            </th>
        </tr>

        <tr>
            <th>
                <form method="get" action="gpio.php">
                <input type="submit" value="7 ON" name="led7on">
                </form>
            </th>
            <th>
                <form method="get" action="gpio.php">
                <input type="submit" value="7 OFF" name="led7off">
                </form>
            </th>
            <th>
                <form method="get" action="gpio.php">
                <input type="submit" value="8 ON" name="led8on">
                </form>
            </th>
            <th>
                <form method="get" action="gpio.php">
                <input type="submit" value="8 OFF" name="led8off">
                </form>
            </th>
        </tr>

        <tr>
            <th>
                <form method="get" action="gpio.php">
                <input type="submit" value="9 ON" name="led9on">
                </form>
            </th>
            <th>
                <form method="get" action="gpio.php">
                <input type="submit" value="9 OFF" name="led9off">
                </form>
            </th>
            <th>
                <form method="get" action="gpio.php">
                <input type="submit" value="10 ON" name="led10on">
                </form>
            </th>
            <th>
                <form method="get" action="gpio.php">
                <input type="submit" value="10 OFF" name="led10off">
                </form>
            </th>
        </tr>
    </table>

<?php
$setmode21 = shell_exec("/usr/local/bin/gpio -g mode 21 out");
if(isset($_GET['led1on'])){
$gpio_on = shell_exec("/usr/local/bin/gpio -g write 21 1");
}
else if(isset($_GET['led1off'])){
$gpio_off = shell_exec("/usr/local/bin/gpio -g write 21 0");
}

$setmode20 = shell_exec("/usr/local/bin/gpio -g mode 20 out");
if(isset($_GET['led2on'])){
$gpio_on = shell_exec("/usr/local/bin/gpio -g write 20 1");
}
else if(isset($_GET['led2off'])){
$gpio_off = shell_exec("/usr/local/bin/gpio -g write 20 0");
}

$setmode26 = shell_exec("/usr/local/bin/gpio -g mode 26 out");
if(isset($_GET['led3on'])){
$gpio_on = shell_exec("/usr/local/bin/gpio -g write 26 1");
}
else if(isset($_GET['led3off'])){
$gpio_off = shell_exec("/usr/local/bin/gpio -g write 26 0");
}

$setmode16 = shell_exec("/usr/local/bin/gpio -g mode 16 out");
if(isset($_GET['led4on'])){
$gpio_on = shell_exec("/usr/local/bin/gpio -g write 16 1");
}
else if(isset($_GET['led4off'])){
$gpio_off = shell_exec("/usr/local/bin/gpio -g write 16 0");
}

$setmode19 = shell_exec("/usr/local/bin/gpio -g mode 19 out");
if(isset($_GET['led5on'])){
$gpio_on = shell_exec("/usr/local/bin/gpio -g write 19 1");
}
else if(isset($_GET['led5off'])){
$gpio_off = shell_exec("/usr/local/bin/gpio -g write 19 0");
}

$setmode13 = shell_exec("/usr/local/bin/gpio -g mode 13 out");
if(isset($_GET['led6on'])){
$gpio_on = shell_exec("/usr/local/bin/gpio -g write 13 1");
}
else if(isset($_GET['led6off'])){
$gpio_off = shell_exec("/usr/local/bin/gpio -g write 13 0");
}

$setmode12 = shell_exec("/usr/local/bin/gpio -g mode 12 out");
if(isset($_GET['led7on'])){
$gpio_on = shell_exec("/usr/local/bin/gpio -g write 12 1");
}
else if(isset($_GET['led7off'])){
$gpio_off = shell_exec("/usr/local/bin/gpio -g write 12 0");
}

$setmode6 = shell_exec("/usr/local/bin/gpio -g mode 6 out");
if(isset($_GET['led8on'])){
$gpio_on = shell_exec("/usr/local/bin/gpio -g write 6 1");
}
else if(isset($_GET['led8off'])){
$gpio_off = shell_exec("/usr/local/bin/gpio -g write 6 0");

$setmode3 = shell_exec("/usr/local/bin/gpio -g mode 3 out");
if(isset($_GET['led9on'])){
$gpio_on = shell_exec("/usr/local/bin/gpio -g write 3 1");
}
else if(isset($_GET['led9off'])){
$gpio_off = shell_exec("/usr/local/bin/gpio -g write 3 0");
}

$setmode2 = shell_exec("/usr/local/bin/gpio -g mode 2 out");
if(isset($_GET['led10on'])){
$gpio_on = shell_exec("/usr/local/bin/gpio -g write 2 1");
}
else if(isset($_GET['led10off'])){
$gpio_off = shell_exec("/usr/local/bin/gpio -g write 2 0");
}
}
?>

</body>
</html>

And the wiring is here: wiring

The problem is that LEDs 9 and 10 do not light up. I have tried switching output pins of LEDs 9 and 10, which didn't fix anything. I swapped the wires for 7 and 8 with 9 and 10, which made LEDs 9 and 10 (connected to 7 and 8) turn on and LEDs 7 and 8 not turning on.

If I go to python and set all 10 pins to HIGH all the LEDs turn on as expected.

When I turn on the Pi LEDs 9 and 10 are dim, but on.

How do I fix this issue?

  • 2
    We need to see the code you are using and a photo of your connections. – joan Jan 31 '18 at 21:19
  • I'm ditching this code and restarting with python; feel free to answer though. – Yubin Lee Feb 12 '18 at 19:00

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.