Thursday, May 14, 2015

Stop, Look and Listen

How to build and control a Railroad Traffic Lights on an Arduino:
by J.B. Wylzan


Project 10:  Railroad Traffic Lights


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

Schematic Diagram:

Block Diagram:





Code # 10:  
/*
   Stop, Look and Listen 
   iHacklab Railroad Traffic Lights
   powered by Arduino
  sketched by J.B. Wylzan
  modified by Lawsinium

  Simulate Railroad Traffic Lights using Green, Yellow, Red Leds.
  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 the Green, Yellow, Red lights
void loop()
   {
      //Green signal
      digitalWrite(4, HIGH); // YELLOW Light on
    digitalWrite(12, HIGH); // YELLOW Light on
     delay(2000); // 5 secs
    digitalWrite(4, LOW); // RED Light on
    digitalWrite(12, LOW); // RED Light on


     //Yellow signal
    digitalWrite(5, HIGH); // YELLOW Light off
    digitalWrite(11, HIGH); // YELLOW Light off
    delay(1000);  
    digitalWrite(5, LOW); // YELLOW Light off
    digitalWrite(11, LOW); // YELLOW Light off
  
      
       //Red signal
      digitalWrite(6, HIGH); // YELLOW Light on
      digitalWrite(10, HIGH); // RED Light on
    
     delay(2000); // 5 secs
   
     //MIddle Lights
    digitalWrite(7, HIGH); // 
    digitalWrite(8, LOW); //  WHITE Light on
    digitalWrite(9, HIGH); //  
    delay(1000); // 5 secs
    digitalWrite(7, LOW); // 
    digitalWrite(8, HIGH); //  WHITE Light off
    digitalWrite(9, LOW); //  
    delay(1000);
    
    digitalWrite(7, HIGH); // 
    digitalWrite(8, LOW); //  WHITE Light on
    digitalWrite(9, HIGH); //  
    delay(1000); // 5 secs
    digitalWrite(7, LOW); // 
    digitalWrite(8, HIGH); //  WHITE Light off
    digitalWrite(9, LOW); //  
    delay(1000);
    
     digitalWrite(7, HIGH); // 
    digitalWrite(8, LOW); //  WHITE Light on
    digitalWrite(9, HIGH); //  
    delay(1000); // 5 secs
    digitalWrite(7, LOW); // 
    digitalWrite(8, HIGH); //  WHITE Light off
    digitalWrite(9, LOW); //  
    delay(1000);
    
     digitalWrite(7, HIGH); // 
    digitalWrite(8, LOW); //  WHITE Light on
    digitalWrite(9, HIGH); //  
    delay(1000); // 5 secs
    digitalWrite(7, LOW); // 
    digitalWrite(8, HIGH); //  WHITE Light off
    digitalWrite(9, LOW); //  
    delay(1000);
    
     digitalWrite(7, HIGH); // 
    digitalWrite(8, LOW); //  WHITE Light on
    digitalWrite(9, HIGH); //  
    delay(1000); // 5 secs
    digitalWrite(7, LOW); // 
    digitalWrite(8, HIGH); //  WHITE Light off
    digitalWrite(9, LOW); //  
    delay(1000);
    
     digitalWrite(7, HIGH); // 
    digitalWrite(8, LOW); //  WHITE Light on
    digitalWrite(9, HIGH); //  
    delay(1000); // 5 secs
    digitalWrite(7, LOW); // 
    digitalWrite(8, HIGH); //  WHITE Light off
    digitalWrite(9, LOW); //  
    delay(1000);
    
     digitalWrite(7, HIGH); // 
    digitalWrite(8, LOW); //   
    digitalWrite(9, HIGH); //  
   digitalWrite(7, LOW); // 
    digitalWrite(8, HIGH); //  
    digitalWrite(9, LOW); //  
    
  digitalWrite(8, LOW); //   

  digitalWrite(7, HIGH); // 
 digitalWrite(9, HIGH); //  
 delay(1000);
   digitalWrite(7, LOW); // 
   digitalWrite(9, LOW); //  
delay(3000);
     digitalWrite(6, LOW); // 
     digitalWrite(10, LOW); // 
  
   }



Actual Layout :  

Procedure:
1. Use the same prototype as shown above
2. Run the Arduino Interface
3. Select File > New
4. Copy Code #10  above
5. Paste Code #10
6. Click File > Save
7. Click Verify
8. Click Upload
9. Three Leds will simulate Red, Yellow, Green Traffic Lights




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. However, if you are interested in using any of the projects for personal or educational purposes, please inform the author by email. 



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