Está en la página 1de 10

Laboratory Exercise 2

FADING LED
Introduction:
Gizduino is an open source computing platform based on a simple
input/output (I/O) board and the use of standard programming language; in
otherwords, it is a tool for implementing a program you have designed.
Gizduino is programmed using the IDE (Integrated Development
Environment).
For instance, you can read a humidity sensor connected to a potted
plant and turn on an automatic watering system if it gets too dry. Or, you can
make a stand-alone chat server which is plugged into your internet router.
Or, you can have it tweet every time your cat passes through a pet door. Or,
you can have it start a pot of coffee when your alarm goes off in the
morning.
Basically, if there is something that is in any way controlled by
electricity, the Gizduino can interface with it in some manner. And even if it
is not controlled by electricity, you can probably still use things which are
(like motors and electromagnets), to interface with it.
The possibilities of the Giduino are almost limitless. As such, there is no
way that one single tutorial can cover everything you might ever need to
know. That said, I've done my best to give a basic overview of the
fundamental skills and knowledge that you need to get your Arduino up and
running. If nothing more, this should function as a springboard into further
experimentation and learning.

Objectives:
1. To be able apply it to change brightness of the LED.
2. To be able to make LED fade in and fade out.
3. To be able to know the concepts of PWM.

Materials:

10 LEDS
Cables
330 Resistor
Arduino board
Computer/ Laptop with Arduino software installed
Breadboard
Procedure:
Part 1: Connecting Arduino to the computer
1. Open the Arduino IDE by clicking on the Arduino Icon (software).
2. Connect your Arduino to the computer using the USB cable.

3. Make sure you select the right board.


4. Then select the correct serial port.

Part 2: Compiling and Uploading file to the Arduino


1. Once you see your Arduino board is connected to your computer. Go
to the File menu -> Examples -> 03.Analog -> Fading.
2. This should open up a new window that has a tab labeled Blink.

3. Then input these codes.


4. Then click on the Sketch menu and check for any typos / errors
using verify button and Compile to the machine language if the
verification is successful.
5. If the above process is successful, you should see the message in
the status bar showing that the compilation is successful.

6. Now upload your program to the Arduino by clicking upload button


in the Sketch menu.

7. You might face some issues from step 3-5 if you have not selected a
correct board/serial port. So please make sure you went through the
part 1 carefully. Go to the Tools -> Serial Port -> COM number.
8. After checking the serial port upload it again.

Part 3: Fading LED

1. In the above Fade code you see bunch of lines performing certain
operations. In our case, turning on and off an LED connected to the
Digital pin 9.
2. After declaring pin 11 to be your ledPin, there is nothing to do in
the setup() function of your code.
3. The analogWrite() function that you will be using in the main loop of
your code requires two arguments: One telling the function which
pin to write to, and one indicating what PWM value to write.
4. In order to fade your LED off and on, gradually increase your PWM
value from 0 (all the way off) to 255 (all the way on), and then back
to 0 once again to complete the cycle. In the sketch above, the PWM
value is set using a variable called brightness. Each time through
the loop, it increases by the value of the variable fadeAmount or
fadeValue.
5. If brightness is at either extreme of its value (either 0 or 255),
then fadeAmount or fadeValue is changed to its negative. In other
words, if fadeAmount is 5, then it is set to -5. If it's -5, then it's set
to 5. The next time through the loop, this change
causes brightness to change direction as well.
6. analogWrite() can change the PWM value very fast, so the delay at
the end of the sketch controls the speed of the fade. Try changing
the value of the delay and see how it changes the fading effect.

7. Before uploading your new code to the Arduino we have to make


sure that LED is connected to the Digital pin 8, if there is nothing
connected we dont have a way to see our result. Now, you have a
fading LED controlled using an Arduino. Now, we can change the
LED fading times by editing the time in the software.

delay(30);
// here we are asking Arduino to wait for 30ms before executing
the next instruction.
Now, try to change the delay times, for both on and off times,
and upload the code again. What did you notice?

Results and Discussion:


In this laboratory exercise are the same in the previous exercise that
we use a arduino software, the different is that were going to make a normal
led lights into fading by using a arduino software and also some knowledge
that weve learned by our instructor. The steps or procedure on how to install
the software, the codes and how to compile and upload the code were stated
above, the same procedure in blinking but they are different in wirings. Then
when we try to upload our code to the arduino then it is successful, the light
isfading!
By uploading our first code in fading in which the delay is 100 (100ms)
the fade of the lights is slowly fading but when we try to change the delay
times into smaller value like 20 and 30 (20-30ms) the fade of the light is
faster to fade. It is the same in the blinking that if you change delay times
into smaller value it is faster to fade or blink. But when we try to change the
fadeValue or the fadeAmount into smaller value (where the max is 255) the
brightness is not so bright. Then if you change the output pin in the
breadboard like you change the output pin11 to pin 10 then the code that
you input is that you change it also into digital pin10.The output that weve
than is shown below.

References:
http://www.instructables.com/id/Intro-to-Arduino/
http://www.ladyada.net/learn/arduino/
https://www.arduino.cc/en/Tutorial/Fading

También podría gustarte