Fading LED

Description

After having the LED blink in accordance with the preloaded program, I proceeded to write my own. I wanted the LED to glow at its maximum brightness, slowly fade to zero and then rise again. I used a for() loop for accomplishing this. Also, I used analogWrite instead of digitalWrite so I can have varying levels of brightness instead of a binary HIGH or LOW.

Components

  • 1 Arduino Uno
  • 1 Breadboard
  • 1 LED
  • Jumper wires
  • 1 USB cable
  • 1 220 ohm resistor

Code

int green = 11;

void setup() {
pinMode(green, OUTPUT); // initialize analog pin 11 as an output.
}

void loop() {
int x = 1;
for (int i = 0; i > -1; i = i + x)
{
analogWrite(green, i);
if (i == 255) // if the LED reaches maximum brightness,
x = -1; // start dimming it by 1 point every second
delay(100);
}
}

 

Button || <3 in Binary

Description


In my first attempt, I created a circuit that causes the LED to blink in response to a button. When the button is pressed, the current is redirected away from the LED back to GND. Otherwise, the current flows through the LED.

In a second attempt, I created a created a parallel circuit where the blinks of the two LED’s symbolize the binary language running our world. One LED is a 0 and the other LED is a 1. Together, they blink 0011110000110011, which represents ‘<3’ in ASCII. Between each looped sequence is a 2 second pause.

Both examples symbolize a theme of the course–transducing what is digital into something more human-friendly and intuitive.

 

Components


  • 1/2 Blue LED
  • 1 Button
  • Jumper cables
  • Resistors (220Ω)
  • 1 Arduino Uno
  • 1 Breadboard

Code


Button Code

int buttonInput = 2;
int LED = 13;
int buttonState = 0;

void setup() {
 pinMode(LED, OUTPUT);
 pinMode(buttonInput, INPUT);
 buttonState = LOW;

}

void loop() {
 buttonState = digitalRead(buttonInput);
 //When button is pressed, LED turns off
 if (buttonState == HIGH) {
 digitalWrite(LED, LOW);
 } else {
 digitalWrite(LED, HIGH);
 }
}

Binary Code

const int led1 = 13;
const int led2 = 12;
const int buttonInput = 2;

int buttonPress = 0;
int buttonCurrent = 0;
int buttonOld = 0;
 
void setup() {
 pinMode(led1, OUTPUT);
 pinMode(led2, OUTPUT);

 
}

void LEDfunc(int ledPin, int repeat) {
 for (repeat; repeat>0; repeat--) {
 digitalWrite(ledPin, HIGH);
 delay(200);
 digitalWrite(ledPin, LOW);
 delay(200);
 }
}
void loop() {
 delay(2000);
 LEDfunc(led1, 2);
 LEDfunc(led2,4);
 LEDfunc(led1, 4);
 LEDfunc(led2, 2);
 LEDfunc(led1, 2);
 LEDfunc(led2,2);

}


Button Version

When button is not depressed IMG_0338

Binary Version

IMG_0374 IMG_0377

Lab 01 – Sandeep

Description

The lab was about the basic task of blinking an LED. I connected the output pin 13 and the ground pin to the breadboard. Next I placed a resistor (220 ohms) on the breadboard and connected it to the jumper cable connecting output pin 13. The long leg of the LED was connected to the resistor and the shorter was connected to the jumper cable connecting to the ground pin. I wrote a code to vary the duration of LED blinking using a for loop. This reminded me of the lights we have up at diwali (festival of lights) where a similar random repeating set of LEDs are lit.

Components

  • 1 Arduino Uno R3
  • 1 Breadboard
  • 1 LED
  • 5 jumper cables
  • 1 USB power cable

Code

/*
* Lab 01: LED Blink
* Sandeep Pal
* Prof : Kimiko Ryokai
* TA : Noura Howell
*
* Description:
*
* The following code is a modification of the basic example of LED blinking using and Arduino
* I have made the LEDs blink at a varying rate over time by using a for loop
*
* Materials:
*
* 1 Arduino Uno R3
* 1 Breadboard
* 1 LED
* 5 jumper cables
* 1 USB power cable
*
*
*/

/*
* Defining output pin
*/
int ledPin = 13;

/*
* Writing the setup function to initialize the output pin to 13
*/
void setup() {
pinMode( ledPin, OUTPUT);
}

void loop() {
// writing a for loop to vary the duration for which the LED should blink
for(int j =0; j<5;j++){ int jVal = j*200; //writing high voltage to the digital output : 13 digitalWrite(ledPin, HIGH); //modifying the delay based on the loop variable delay(1000-jVal); //writing low voltage to the digital output : 13 digitalWrite(ledPin, LOW); delay(jVal); } }

 

Lab 01 – Disco Lights

I tried to play around with the lights and more than a loop, I thought I could make it groovy and hence, chose to sync the lights with the legendary disco number Stayin’ Alive by the BeeGees (click for video; may be too loud though).

To get the different accents and beats, I set three connections in parallel and I placed the green and the yellow LEDs in serial to indicate a stronger third beat. I added the tempo variable in the code itself so if we change the song to, say a slower tempo in 4/4 time, this can be adjusted too! A slightly more varied drumbeat can also be incorporated!

Code:


int ledPin = 13; // goes to yellow and green
int ledPinTwo = 12; // goes to red
int ledPinThree = 11; // goes to blue

void setup()
{
pinMode(ledPin, OUTPUT);
pinMode(ledPinTwo, OUTPUT);
pinMode(ledPinThree, OUTPUT);
}
void loop()
{

// Drumbeat pattern (each column is one beat)
// YG: 1100 0000 0000 0000
// R: 1100 1100 1100 1100
// B: 1100 0000 1100 0000
// Tempo for Stayin' Alive: 104 BPM

digitalWrite(ledPin, HIGH);
digitalWrite(ledPinTwo, HIGH);
delay(30000/104);
digitalWrite(ledPin, LOW);
digitalWrite(ledPinTwo, LOW);
delay(30000/104);

digitalWrite(ledPinTwo, HIGH);
delay(30000/104);
digitalWrite(ledPinTwo, LOW);
delay(30000/104);

digitalWrite(ledPinTwo, HIGH);
digitalWrite(ledPinThree, HIGH);
delay(30000/104);
digitalWrite(ledPinTwo, LOW);
digitalWrite(ledPinThree, LOW);
delay(30000/104);

digitalWrite(ledPinTwo, HIGH);
delay(30000/104);
digitalWrite(ledPinTwo, LOW);
delay(30000/104);

}

Lab 01 – Molly

Description:

For this lab, I began with the simple on/off LED example to get used to the Arduino board. After that, I wanted to try putting multiple LEDs into the circuit. I found some examples online that showed me how to initialize the other LEDs into different ports in my Arduino, and how to create loops to run those. I ended up using all three LEDs, and lighting them in order sequentially.
(I had looked to find information on running multiple LEDs at different rates at the same time, but wasn’t able to find anything simple to implement. It seemed like the delay() function allowed other loops to start running? I’d like to explore this more but haven’t yet.)

Components:

  • 1 Arduino Uno
  • 1 breadboard
  • 3 LEDs
  • 3 220Ω resistors
  • jumper wires
  • USB cable
  • computer

Code:
int led1 = 13;
int led2 = 10;
int led3 = 6;

void setup() {
// put your setup code here, to run once:
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
}

void loop() {
// put your main code here, to run repeatedly:
digitalWrite(led1, HIGH);
delay(1000);
digitalWrite(led1, LOW);
delay(100);
digitalWrite(led2, HIGH);
delay(1000);
digitalWrite(led2, LOW);
delay(100);
digitalWrite(led3, HIGH);
delay(1000);
digitalWrite(led3, LOW);
delay(100);
}

Photos:

single LED
IMG_1169

three LEDs
IMG_1172

Lab – 1 – Alternating Lights

After the initial blink set up, I worked towards setting up two different LEDs to blink alternately.

2 LED
2 Resistors (220Ω)
Jumper wire
1 Arduino
1 Breadboard

##Code##
// the setup function runs once when you press reset or power the board
void setup() {
 // initialize digital pin 13 as an output.
 pinMode(13, OUTPUT);
 pinMode(12, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
 digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level)
 digitalWrite(12, LOW); // turn the LED off by making the voltage LOW
 delay(500); // wait for .5 seconds
 digitalWrite(13, LOW); // turn the LED off by making the voltage LOW
 digitalWrite(12, HIGH); // turn the LED on (HIGH is the voltage level)
 delay(500); // wait for .5 seconds
}

Lab 1: J-A-K-E

Description


I used an Arduino with a green light. I rewrote my code to spell out my name, J-A-K-E in morse code, then to pause for a couple seconds, then repeat.

I wrote individual functions for a “dot” and for a “dash,” then used those functions to construct a function for each of the four letters that I needed.

When I tested it out, it appeared to work well, although I’m not a fluent morse-code-ist, so I cannot say for sure. Today’s class was so hecking cool! I could make blinky patterns all night.

Components


  • 1 Arduino
  • 1 LED
  • 1 Resistor (220Ω)
  • 1 Breadboard

Code

[[code]]czoxODgzOlwiLyoNCiAqIExhYiAxOiBMRUQgQmxpbmtlcg0KICogSmFrZSBQZXR0ZXJzb24NCiAqIFByb2YuIFJ5b2thaSAtLSBJbmZ7WyYqJl19byAyNjINCiAqIFdlZG5lc2RheSwgQXVndXN0IDMxDQogKiANCiAqIFRoZSBmb2xsb3dpbmcgcHJvZ3JhbSB1c2VzIGFuIEFyZHVpbntbJiomXX1vLCBhIExFRCwgYW5kIGEgMjIwIE9obQ0KICogcmVzaXN0b3IgaW4gc2VyaWVzLCBhbmQgc3BlbGxzIG91dCBteSBuYW1lLCBcIkotQXtbJiomX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IHRoZSAybmQgTEVEIG9uIA0KIGRlbGF5KDUwKTsgDQogZGlnaXR7WyYqJl19YWxXcml0ZSg4LCBMT1cpOyAvLyB0dXJuIHRoZSAybmQgTEVEIG9mZiANCiBkZWxheSg1MCk7DQogZGlnaXRhbFdyaXRlKDgsIEhJR3tbJiomXX1IKTsgDQogZGVsYXkoNTApOyANCiBkaWdpdGFsV3JpdGUoOCwgTE9XKTsgDQogZGVsYXkoNTApOw0KIGRpZ2l0YWxXcml0ZSg4LCBIe1smKiZdfUlHSCk7IA0KIGRlbGF5KDUwKTsgDQogZGlnaXRhbFdyaXRlKDgsIExPVyk7IA0KIGRlbGF5KDUwKTsNCiBkaWdpdGFsV3JpdGUoOCx7WyYqJl19IEhJR0gpOyANCiBkZWxheSg1MCk7IA0KIGRpZ2l0YWxXcml0ZSg4LCBMT1cpOyANCiBkZWxheSg1MCk7DQogDQp9XCI7e1smKiZdfQ==[[/code]]

Arduino – 2 LED Lights Blinking in Turns

Description:

I used Arduino with a blue LED first, and customized its blinking rate. Based on that, I added another circuit loop for a green LED light. And for the coding part, I changed the code further to make the two LED lights blink in turns at a customized rate. A full loop will be like that LED A blinks once for 1 second, LED B blinks twice for 0.5 second each, and then LED B blinks once for 1 second, LED A blinks twice for 0.5 second each.

Components:

  • 2 LED
  • 2 Resistors (220Ω)
  • 6 Jumper wires
  • 1 Macbook Pro
  • 1 Arduino
  • 1 Breadboard
  • 1 USB cable

Code:

void setup() {
// initialize digital pin 13 as an output.
pinMode(13, OUTPUT);
pinMode(12, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(13, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
digitalWrite(12, HIGH); // turn the LED off by making the voltage LOW
delay(500); // wait for 0.5 second
digitalWrite(12, LOW); // turn the LED off by making the voltage LOW
delay(500); // wait for 0.5 second
digitalWrite(12, HIGH); // turn the LED off by making the voltage LOW
delay(500); // wait for 0.5 second
digitalWrite(12, LOW); // turn the LED off by making the voltage LOW
delay(500); // wait for 0.5 second

digitalWrite(12, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(12, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
digitalWrite(13, HIGH); // turn the LED off by making the voltage LOW
delay(500); // wait for 0.5 second
digitalWrite(13, LOW); // turn the LED off by making the voltage LOW
delay(500); // wait for 0.5 second
digitalWrite(13, HIGH); // turn the LED off by making the voltage LOW
delay(500); // wait for 0.5 second
digitalWrite(13, LOW); // turn the LED off by making the voltage LOW
delay(500); // wait for 0.5 second
}

Comment:

I love it! It’s fun to experiment with Arduino :p

Photos:

IMG_0540 IMG_0541 IMG_0542 IMG_0543

 

 

Variable blinking light

Description


I used an Arduino with a red light. I changed the code to have a variable rate of blinking moving back and forth between a delay of 100 to 500 milliseconds. I tested it and saw the change.

Components


  • 1 Arduino
  • 1 LED
  • 1 Resistor (220Ω)
  • 1 Breadboard
  • 3 Wires

Code


int ledPin = 13;
int currentRate = 1000;
int rateDir = 0;
// the setup function runs once when you press reset or power the board
void setup() {
// initialize digital pin 13 as an output.
pinMode(ledPin, OUTPUT);
}
// the loop function runs over and over again forever
void loop() {
if (currentRate > 500) {
rateDir = 0;
} else if (currentRate < 100) {
rateDir = 1;
}
if (rateDir == 1) {
currentRate = currentRate + 50;
} else {
currentRate = currentRate - 50;
}
digitalWrite(ledPin, HIGH); // turn the LED on (HIGH is the voltage level)
delay(currentRate); // wait for current delay
digitalWrite(ledPin, LOW); // turn the LED off by making the voltage LOW
delay(currentRate); // wait for current delay
}

IMG_20160831_151457