0

members

Easy Basics: Project 012c Pulsing LED

of Acoptex.com in UNO

Basics: Project 012c

Project name: Pulsing LED

Attachments: program1 

In this project, you needed these parts :

1.Aruduino Uno R3 (you can also use the other version of Arduino)

2.Arduino IDE ( you can download it from here  )

3.Jumper cables

4. LED 1 pc

5. Resistor 1 pc (220 Om)

6. Breadboard

General

In this project we will try to change the luminance of LED gradually through programming. Since the pulsing light looks like breathing in some other sources on interenet it´s called the Breathing LED. We will use pulse width modulation (PWM) to do this project. 

Pulse width modulation, or PWM, is a technique for getting analog results with digital means. Digital control is used to create a square wave, a signal switched between on and off. This on-off pattern can simulate voltages in between full on (5 Volts) and off (0 Volts) by changing the portion of the time the signal spends on versus the time that the signal spends off. The duration of "on time" is called pulse width. To get varying analog values, you change, or modulate, that width. If you repeat this on-off pattern fast enough with some device, an LED for example, it would be like this: the signal is a steady voltage between 0 and 5V controlling the brightness of the LED. (See the PWM description on the official website of Arduino).In the graphic below, the green lines represent a regular time period. This duration or period is the inverse of the PWM frequency. In other words, with Arduino's PWM frequency at about 500Hz, the green lines would measure 2 milliseconds each.

A call to analogWrite() is on a scale of 0 - 255, such that analogWrite(255) requests a 100% duty cycle (always on), and analogWrite(127) is a 50% duty cycle (on half the time) for example.

You will find that the smaller the PWM value is, the smaller the value will be after being converted into voltage. Then the LED becomes dimmer accordingly. Therefore, we can control the brightness of the LED by controlling the PWM value.

Signals and connections of LED

The operating voltage of the LED is 1.8V and the operating current is 10mA-20mA. The Arduino Uno board can supply 5V or 3.3V power. We will use 5V for this project, so the minimum resistance of the current limiting resistor should be (5 V to 1.8 V)/20 = 160 Om. The 220 Om offered in the kit is suitable and you can also choose other resistors that meet the condition. The larger the resistance is, the dimmer the LED will get.

Build the circuit

The following picture shows the needed connections with the Arduino Uno 

 

Code

We can use the analogWrite() function to write different values to pin 11. The luminance of the LED will change based on that. On the Arduino Uno board, pin 3, 5, 6, 9, 10, and 11 are the pins of PWM (with “~“ marked). You can connect any of these pins.

When a=0, which accords with the condition a<=255, a++ equals to 1 (here in a= a+1, the two "a"s are not the same, but a now = a before + 1). Run the code in the curly braces: write a=0 into ledPin, wait for 10ms and exit the loop in the curly braces. Back to the for() function. When a=1, meaning a<=255, a++ equals 2. Run the code in curly braces again and write a = 1 into ledPin. The loop repeats until a = 256 which dissatisfies the condition a<=255. Write 0 - 255 to ledPin (the LED at pin 11). The LED will become brighter as the value increases. The for statement is used to repeat a block of statements enclosed in curly braces. analogWrite() writes an analog value (PWM wave) to a pin. It has nothing to do with an analog pin, but is just for PWM pins. You do not need to call the pinMode() to set the pin as output before calling analogWrite().

Step by Step instruction

  1. Plug your Adruino Uno board into your PC and select the correct board and com port
  2. Open up serial monitor and set your baud to 9600 baud
  3. Verify and upload the the sketch to your Adruino Uno board
  4. You should see that the LED gets brighter and brighter, then slowly dimmer, and again brighter and dimmer repeatedly, just like pulsing.

Summary

We successed with gradual change of the luminance of our LED through programming and learned PWM.

Libraries:

  • No libraries required for this project

Program/Sketch

  • See attachments on the begining of this project description. 


Other projects of Acoptex.com
Easy Merry Xmas to everyone of Acoptex.com, Not selected 24-12-2019

Published at 21-07-2017
Viewed: 827 times