header

 

More links

AutoHotkey | Android | Arduino | COMM140Fractals | Grammar Checkers | Knots | A Million Dots Activity |  Processing | Processing for Scratch Users | Redbubble | Tutorials | Weather | World Time Meeting Planner | Favicon Generator.

Home > Tutorials > Arduino > Projects >Traffic Lights running on an ATTiny85

 

Traffic Lights running on an ATTiny85

See How-To: Shrinkify Your Arduino Projects

This project was created for the Ballarat fire brigade where I am a volunteer fire fighter.

The rational for the project was to build a set of red & green "traffic lights" connected to the fire station door.
The lights would turn red as soon as the door starts to open and then green when they are fully open.
When the door is fully closed the red light turns off. When either the red or green light has been on for 12 minutes they will turn off this will prevent the globes from burning out.

 

/*
Control the door warning lights

Purpose to turn on a Red warning light when the door is not fully open, and to turn on a Green light when the door is fully open.

Note there is a micro switch that detects when the door is closed and another switch that detects when the door is fully open.

The switch at the bottom of the door is normally open
The switch at the top of the door track is normally closed

Turn off both LED's while bottomSwitch_3 (8) is LOW
The bottom switch is LOW when the door is closed
so there is no need to burn out the LED's when the
door is closed most of the time.

Turn on the Red LED as soon as the door starts to open
When the door is fully open the topSwitch_4 (9) goes LOW
so turn off the Red LED and turn on the Green LED

see board layout http://www.rupert.id.au/tutorials/arduino/

*/

int redLedPin = 2;
int greenLedPin = 1;
int topSwitch_4 = 4;
int bottomSwitch_3 = 3;
int timer = 1440; // set to 1440 for a 12 minute timer on both red and green lights

int counterGreen = 0;
int counterRed = 0;

void setup()
{
   pinMode(redLedPin, OUTPUT);
   pinMode(greenLedPin, OUTPUT);
   pinMode(topSwitch_4, INPUT_PULLUP);
   pinMode(bottomSwitch_3, INPUT_PULLUP);

   counterGreen = 0; // Timer counterGreen for GREEN LED
   counterRed = 0; // Timer counterRed for RED LED
}

void loop()
{
   delay(500); // Loop every half a second

   if (digitalRead(bottomSwitch_3) == HIGH) // The door starts to open

   {
      if (digitalRead(topSwitch_4) == LOW) // The door is not fully open
      {
      digitalWrite(redLedPin, HIGH); // Turn on the Red light
      digitalWrite(greenLedPin, LOW); // Turn off the Green light
      counterGreen = 0; // reset counterGreen for GREEN Light

      counterRed = counterRed + 1;
      if ( counterRed > timer) // if the Red light has been on for more than 12 minutes turn it off
      {
         digitalWrite(redLedPin, LOW); // Turn off Red Light
         digitalWrite(greenLedPin, LOW); // Turn off Green Light
      }

   }
   if (digitalRead(topSwitch_4) == HIGH) // The door is fully open
   {
      digitalWrite(redLedPin, LOW);
      counterRed = 0; // reset counterRed for RED Light
      digitalWrite(greenLedPin, HIGH);
      counterGreen = counterGreen + 1;

      if ( counterGreen > timer) // if the Green light has been on for more than 12 minutes turn it off
      {
      digitalWrite(redLedPin, LOW);
      digitalWrite(greenLedPin, LOW);
      }
   }
}
if (digitalRead(bottomSwitch_3) == LOW) // The door is fully closed
{
   digitalWrite(redLedPin, LOW); // Turn off the Red light
   digitalWrite(greenLedPin, LOW); // Turn off the Green light

   counterGreen = 0; // reset counterGreen for GREEN Light
   counterRed = 0; // reset counterRed for RED Light

   }
}

 

 


APA citation:
Russell, R. (2016, July 05, 07:25 am). Traffic lights running on an attiny85.
     Retrieved December 24, 2024, from http://http://www.rupert.id.au/tutorials/arduino/projects/traffic-lights/index.php

Last refreshed: December 24 2024. 10:47.52 am

rupert dot russell at acu dot edu dot au Support Wikipedia

Creative Commons License This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License.


542 visits since April 23, 2013