Things used in this project

Hardware components:
09264 1
RGB Diffused Common Anode
08377 02 l
Resistor 330 ohm
12002 04
Breadboard (generic)
11026 02
Jumper wires (generic)
Cutting board
Plastic cutting board sold at WalMart, DollarTree, etc.
Software apps and online services:
BCM2835 Library for RPi
Other libraries exist for GPIO support on RPi
Geany IDE
Optional if another IDE is preferred
C++ Boost library for Raspbian
Hand tools and fabrication machines:
Strips, dots, etc. Available at most office supply stores.


Generic connection
Danger ... use appropriate current limiting resistor
Genericrpi ri7dffjkip


Source for Blink_3C/C++
Written for common anode RGB LED
// blink3.c
// Example program for bcm2835 library
// Blinks a tricolor LED on an off every 0.5 secs (editable)
// Or you can test it before installing with:
// gcc -o blink -I ../../src ../../src/bcm2835.c blink3.c
// sudo ./blink3

// For Geany GUI IDE:
// 	Compile switches:  gcc -Wall -c "%f" -l bcm2835
// 	Build switches:    gcc -Wall -o "%e" "%f" -l bcm2835
// 	Execute switches:  sudo "./%e"
// YouTube vid:

#include <bcm2835.h>
#include <stdio.h>

// modified mrb 20170419 for RPi Zero
// LED between common anode to +3.3 and Pin 12, 16, 18 to 330 Ohm to RGB of LED
// RPi P1_pin_12 == GPIO_18
// RPi P1_pin_16 == GPIO_23
// RPi P1_pin_18 == GPIO_24

#define RED RPI_GPIO_P1_12 // SAME RESULTS AS #define PIN 18
#define GRN RPI_GPIO_P1_16
#define BLU RPI_GPIO_P1_18

#define t_On	10
#define t_Off	300
#define Led_Off	HIGH
#define Led_On	LOW

int main(int argc, char **argv)
    if (!bcm2835_init() ) return 1 ;

    // Set the pin to be an output
    bcm2835_gpio_fsel(RED, BCM2835_GPIO_FSEL_OUTP) ;
    bcm2835_gpio_fsel(GRN, BCM2835_GPIO_FSEL_OUTP) ;
    bcm2835_gpio_fsel(BLU, BCM2835_GPIO_FSEL_OUTP) ;
	// LED used is a RGB with a common anode which connects to 3.3V
    // Therefore, any LED is OFF when the port pin is HIGH
    bcm2835_gpio_write(RED, Led_Off);
    bcm2835_gpio_write(GRN, Led_Off);
    bcm2835_gpio_write(BLU, Led_Off);

    while (1)						// Function same as loop() in Arduino
	// LEDs illuminate when cathode is connected by output buffer to ground (sink)
	// ***WARNING*** a suitable current limiting resistor must be used (~330 Ohm)
	// RED LED on, wait, off, wait ... next color, repeat
	bcm2835_gpio_write(RED, Led_On);
	bcm2835_gpio_write(RED, Led_Off);
	// Repeat for Green
	bcm2835_gpio_write(GRN, Led_On);
	bcm2835_gpio_write(GRN, Led_Off);
	// Repeat for Blue
	bcm2835_gpio_write(BLU, Led_On);
	bcm2835_gpio_write(BLU, Led_Off);
    // Unless program responds to a Ctrl+C (break), the above loops forever
    bcm2835_close();				// housecleaning
    return 0;


Ray Burnette

IT architect - retired AT&T... USAF-Secure Comm , Burroughs, Clemson U. School of EE Research, Southern Bell, BellSouth, SofKinetics, Inc. (President), AT&T IT

Thanks to SpazzTech.


Did you replicate this project? Share it!

I made one

Love this project? Think it could be improved? Tell us what you think!

Give feedback


ProjectsCommunitiesTopicsContestsLiveAppsBetaFree StoreBlogAdd projectSign up / Login