[vc_row][vc_column width=”1/1″][vc_column_text]The components used in this experiment are shown below:
The components are one diode, one 470 ohm resistor,2 jumper wires and breadboard.
Schematics:
The long pin of LED is positive, and the short pin is negative.
Wiring Diagram:
The positive pin of LED is wired to digital pin 9 of Arduino,the negative pin of LED is wired to a resister and then to the GND of the Arduino.
Arduino Code:
int ledPin = 9;
int durations[] = {200, 200, 200, 500, 500, 500, 200, 200, 200};
void setup() // run once, when the sketch starts
{
pinMode(ledPin, OUTPUT); // sets the digital pin as output
}
void loop() // run over and over again
{
for (int i = 0; i < 9; i++) {
flash(durations[i]);
if (i == 2) {
delay(300);
}
}
delay(1000); // wait 1 second before we start again
}
void flash(int duration)
{
digitalWrite(ledPin, HIGH);
delay(duration);
digitalWrite(ledPin, LOW);
delay(duration);
}[/vc_column_text][/vc_column][/vc_row]
Leave a Reply
You must be logged in to post a comment.