Monday, May 4, 2015

Let There Be Lights

How to build and control a series of LEDs on an Arduino:
by J.B. Wylzan

Project 1:  Let There Be Lights:
The objective of this project is to turn on all 9 Leds at the same time. 
"Let there be Lights" is the iHackLab equivalent of "Hello World" .


Hardware:
9 LEDs
9 resistors, 200 ohms
connecting wires
breadboard
computer cable
Arduino UNO

Schematic Diagram:

image created by fritzing

Block Diagram:
image created by fritzing
                                        
Code # 1:  
/*
  Let There Be Lights Project
  iHackLab Switching Lights
  powered by Arduino
  sketched by J.B. Wylzan
  modified by Lawsinium

  Turns On all the LEDs once at the same time
  This example code is public domain.
 */

// Setup pins 4 to 12
void setup() 
{
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(11, OUTPUT);
  pinMode(12, OUTPUT);
}

// Turn on all LEDs once
void loop() 
{
  digitalWrite(4, HIGH);          // switch on pin 4 
  digitalWrite(5, HIGH);          // switch on pin 5 
  digitalWrite(6, HIGH);          // switch on pin 6 
  digitalWrite(7, HIGH);          // switch on pin 7 
  digitalWrite(8, HIGH);          // switch on pin 8 
  digitalWrite(9, HIGH);          // switch on pin 9 
  digitalWrite(10, HIGH);         // switch on pin 10 
  digitalWrite(11, HIGH);         // switch on pin 11
  digitalWrite(12, HIGH);         // switch on pin 12
}

Challenges:  
1. Turn on Led #8 only
2. Turn on and off LEDs 7 and 10
3. Turn on and off all even LEDs
4. Turn on and off all odd LEDs
5. Turn on and off LEDs from left to right.

Actual Layout :  

Procedure:
1. Use the same prototype as shown above
2. Run the Arduino Interface
3. Select File > New
4. Copy Code #1 above
5. Paste Code #1
6. Click File > Save
7. Click Verify
8. Click Upload
9. All 9 Leds will light up all at the same time once.






Disclaimer:  We shall not be liable for any loss or damage of whatever nature - direct, indirect, consequential, or otherwise - which may arise as a result of your use of any information on this website.

Public Domain Notice: Copyright (c) 2000. All rights reserved. This article is part of a book entitled iHackRobot. Copies are welcome to be shared or distributed publicly as long proper citations are observed. Please cite as follows: Biotronics: The Silver Species, Joey Lawsin, 1988, USA.
================================================================== 
The Homotronics® and Homodruinos® logos are registered trademarks.
Copyright Biotronics© Inc. iHackRobot®. All Rights Reserved.
Patent Pending. 2000 © ®

L.A.W.S.I.N. Educational Production
 ================================================================== 

No comments:

Post a Comment