November 23, 2016

Arduino Railroad Lights



ARDUINO RAILROAD LIGHTS


INTRODUCTION
Arduino is a micro-controller which can be programmed to do certain operations like lighting led, controlling servo, etc. We’ll use Arduino UNO or any other clone to create Railroad lights. A railroad light usually consists of two red lights flashing alternately. The time interval between both lights must be less than one second in order to experience the Railroad scenario.



MATERIALS REQUIRED

  • Arduino UNO or any other clone and USB cable
  • Red 5mm LED (2)

  • 20 K ohm resistor (2)

  • Breadboard

  • Jumpers


PROCEDURE

  • Connect digital pin 7 of Arduino to longer leg of led via a resistor and connect the shorter leg of LED to ground pin on Arduino.

  • Similarly connect digital pin 8 to LED via a resistor and back to another ground pin on Arduino.

  • The circuit is complete, upload the code and you can verify the output.

  • The USB cable serves both as a medium to upload code as well as 5V power source.


CODE

The code for Railroad lights is as follows. Copy and paste it on Arduino IDE.

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

// the loop function runs over and over again forever
void loop() {
  digitalWrite(8, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(300);              // wait for 300 millisecond
  digitalWrite(8, LOW);    // turn the LED off by making the voltage LOW
  delay(300);             // wait for 300 millisecond
  digitalWrite(7, HIGH);
  delay(300);
  digitalWrite(7, LOW);
  delay(300);
}

No comments:

Post a Comment