November 11, 2018

Arduino Rail Road Lights tutorial


ARDUINO RAILROAD LIGHTS TUTORIAL


INTRODUCTION

Arduino is a microcontroller which can be programmed to do certain operations like lighting led, controlling servo, etc. This is an Arduino DIY project intended to simulate Railroad lights. A railroad lighting system 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.

COMPONENTS REQUIRED

1. Breadboard
2. Arduino UNO and USB cable
3. Two 5mm Red LED’s
4. Two 20 Ohm resistors
5. Jumpers
6. A 5V DC Power supply

CIRCUIT SCHEMATICS

Figure1 Rail road lighting schematic

Make the appropriate connections as shown in the schematic above

CODE

This is the code for simulating Arduino Railroad lights. Note that this code is valid only for the particular schematic represented in figure1. The values and choice of ports can always be changed. 

Copy and paste the code in Arduino IDE sketch area.

void setup() {
  // initialize digital pin 4 and 7 as an output.
  pinMode(4, OUTPUT);
  pinMode(7, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(4, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(300);              // wait for 300 millisecond
  digitalWrite(4, 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