DesignSpark Electrical Logolinkedin
Menu Search
Ask a Question


I have bought the Vilros Ultimate Starter Kit Raspeberry Pi 3 B+ on Amazon that consists of a breadboard, breakout kit, resistors and some LEDS that I wanted to try this Sunday.
Unfortunately it doesn't work, I am trying pin #21 but nothing happens.

I have tried the following code on Pyton, saved it under and run it with sudo python but nothing happens.

raspberry pi gpio programming

0 Votes


February 4, 2019 10:31

Also, the code in the link you gave is controlling pin 12, but you are connecting to pin 21, so you won't see any change regardless of what you do. (From what I saw on a quick check on the web, only pin 12 has hardware PWM support, so unless you use a version of the library that implements PWM via software, using PWM on pins other than 12 won't work.) It can also get confusing because there are processor i/o pin numbers and GPIO connector pin numbers, and the two are not the same.

Do make sure you include a resistor in series with LED to limit the current. Otherwise you risk damage to the LED and/or the Raspberry Pi output. A 330 ohm resistor will be a safe choice. For green, blue, or white LEDs (which have a higher forward voltage, closer to the 3.3 volt output of the RPi) a 120 or 150 ohm resistor will still be safe and give brighter output.

Here is a link to a page with a good description of blinking an LED with the Raspberry Pi

In addition to being about controlling an LED instead of about controlling a servo, the article at the above link is much better written (in terms of explaining what it is doing) than the link you provided. I suggest looking there or at other sites rather than the one your original link is on as you progress to other projects.

(The link you gave will cause action on a servo. But it doesn't explain how to calculate the duty cycles argument for intermediate rotation angles. And the duty cycle parameters it used actually correspond to 0.5 ms and 2.5 ms pulse width, so someone making a guess and linearly interpolating between the 2.5 and 12.5 argument duty cycle values would find no change from 2.5 to 5, then rotation from 5 to 10, then no change from 10 to 12.5% duty cycle.)

0 Votes

February 4, 2019 10:32

Pulse Width Modulation (PWM) can be used to control the speed of dc motors or the brightness of LEDs. BUT, the format used for driving a hobby servomotor isn't much use for either. A servomotor PWM signal has a pulse repetition frequency of 50Hz and the range of pulse widths only extends from 1 to 2ms. Given the pulse period of 20ms, you can see that the average voltage seen by the LED can only be from 5 to 10% of the full output. You need to find a routine which gives you 0 to 100% of PWM.

0 Votes

February 4, 2019 10:33

I'm interested in learning Python so had a look at the link, but this seems to go to a servo drive which I don't think will work with a LED especially as it has a 1 second sleep between the pulses. Can you post the correct code link.

0 Votes

February 4, 2019 10:32

@Boss yes i check the link and code my main question how to led on and off each one second using python

February 4, 2019 10:34


0 Votes