LED stair lighting based on Arduino, Part 7

12 Jun

I’m closing of this project as I think that with the current configuration I will not be able to achieve what I want.
By closing this project I will kick of a new one(Version 2) which would be a bit more complicated from the hardware and programming point but at least it will give me more freedom. The new version of arduino automatic stairs is already being developed and I will post a new post soon(watch this space). For those of you who are still interested in this project here is a draft code:

int counter = 100;  // for delayLights
// 8 LED pins
int ledPin11 = 11;
int ledPin10 = 10;
int ledPin9 = 9;
int ledPin8 = 8;
int ledPin7 = 7;
int ledPin6 = 6;
int ledPin5 = 5;
int ledPin3 = 3;
int ledVal;
float sinVal;
boolean nightMode = false;
boolean testRun = false;
boolean goingUp = false;
boolean lightsOn = false;
// choose input pin (for Infrared sensor UP)
int inputPin2 = 2;
int valUP = 0;
int lightSens = 0; //light sensor value
// choose input pin (for Infrared sensor DOWN)
int inputPin4 = 4;
int valDOWN = 0;
int ledPins[] = { 3, 5, 6, 7, 8, 9, 10, 11};
void setup()
{
pinMode(ledPin11, OUTPUT);
pinMode(ledPin10, OUTPUT);
pinMode(ledPin9, OUTPUT);
pinMode(ledPin8, OUTPUT);
pinMode(ledPin7, OUTPUT);
pinMode(ledPin6, OUTPUT);
pinMode(ledPin5, OUTPUT);
pinMode(ledPin3, OUTPUT);
Serial.begin(9600);
pinMode(inputPin2, INPUT);
}
void loop()
{
lightSens=analogRead(0);
Serial.println(lightSens);
if (lightSens < 900) //check if it is bright
{
nightMode = false;
testRun = false;
}
if (lightSens > 1000) //check if it is dark
{
nightMode = true;
}
if (nightMode == true && testRun == false) //do a test run
{
TestMode();
testRun = true;
}
if (nightMode == true && testRun == true)
{
valDOWN = digitalRead(inputPin4);
if (valDOWN == LOW)
{
if (lightsOn == false)
{
goingDownOn();
goingUp = false;
}
if (counter != 0)
{
counter = 10;
}
}
valUP = digitalRead(inputPin2);
if (valUP == LOW)
{
if (lightsOn == false)
{
goingUpOn();
goingUp = true;
}
if (counter != 0)
{
counter = 10;
}
}
}
if (counter != 0)
{
counter = counter – 1;
delayLights();
}
if (counter == 0 && goingUp == false && lightsOn == true)
{
goingDownOff();
}
if (counter == 0 && goingUp == true && lightsOn == true)
{
goingUpOff();
}
}
// Delay routine
void delayLights()
{
delay(250);
}
// Going Up light on
void goingUpOn()
{
lightsOn = true;
counter = 10;
for (int i=0; i<10; i++)
{
for (int x=0; x<91; x++)
{
sinVal=(sin(x*(3.1412/180)));
ledVal=int(sinVal*255);
analogWrite(ledPins[i], ledVal);
delay(2);
}
}
}
// Going Up light off
void goingUpOff()
{
lightsOn = false;
for (int i=0; i<10; i++)
{
for (int x=90; x>-1; x–)
{
sinVal=(sin(x*(3.1412/180)));
ledVal=int(sinVal*255);
analogWrite(ledPins[i], ledVal);
delay(5);
}
}
}
// Going Down light on
void goingDownOn()
{
lightsOn = true;
counter = 10;
for (int i=9; i>-1; i–)
{
for (int x=0; x<90; x++)
{
sinVal=(sin(x*(3.1412/180)));
ledVal=int(sinVal*255);
analogWrite(ledPins[i], ledVal);
delay(2);
}
}
}
// Going Down light off
void goingDownOff()
{
lightsOn = false;
for (int i=9; i>-1; i–)
{
Serial.println(“going down lights off”);
for (int x=90; x>-1; x–)
{
sinVal=(sin(x*(3.1412/180)));
ledVal=int(sinVal*255);
analogWrite(ledPins[i], ledVal);
delay(5);
}
}
}
void TestMode()
{
for (int i=9; i>-1; i–)
{
digitalWrite(ledPins[i], HIGH);
delay(50);
digitalWrite(ledPins[i], LOW);
Serial.println(“Test 1”);
}
for (int i=0; i<10; i++)
{
digitalWrite(ledPins[i], HIGH);
delay(50);
digitalWrite(ledPins[i], LOW);
Serial.println(“Test 2”);
}
}
Edit:
Copying code from the web makes it useless it changes something and cannot be compiled. Here is a zip file of the code. Download

Tags: ,

8 Responses

  1. Unge Danielsen says:

    Hi there.

    I’m planning to do the same thing. And are now looking at what parts I need. How far have you come with your project?

    Best Regards
    Arne-Morten Danielsen

    • wjh says:

      hello

      thx for the answer
      i guess its connected to copy from the webside.,
      but some errors does not make sence ..

      is there a way to send the code by link?

      thx in advance

      best

      wjh

      sketch_aug28a:88: error: stray ‘\’ in program
      sketch_aug28a:127: error: stray ‘\’ in program
      sketch_aug28a:141: error: stray ‘\’ in program
      sketch_aug28a:156: error: stray ‘\’ in program
      sketch_aug28a:158: error: stray ‘\’ in program
      sketch_aug28a:158: error: stray ‘\’ in program
      sketch_aug28a:159: error: stray ‘\’ in program
      sketch_aug28a:170: error: stray ‘\’ in program
      sketch_aug28a:175: error: stray ‘\’ in program
      sketch_aug28a:175: error: stray ‘\’ in program
      sketch_aug28a:182: error: stray ‘\’ in program
      sketch_aug28a:182: error: stray ‘\’ in program
      sketch_aug28a.cpp: In function ‘void loop()’:
      sketch_aug28a:88: error: expected `;’ before ‘u2013’
      sketch_aug28a.cpp: In function ‘void goingUpOff()’:
      sketch_aug28a:127: error: expected `)’ before ‘u2013’
      sketch_aug28a:127: error: ‘u2013′ was not declared in this scope
      sketch_aug28a:127: error: expected `;’ before ‘)’ token
      sketch_aug28a.cpp: In function ‘void goingDownOn()’:
      sketch_aug28a:141: error: expected `)’ before ‘u2013’
      sketch_aug28a:141: error: ‘u2013′ was not declared in this scope
      sketch_aug28a:141: error: expected `;’ before ‘)’ token
      sketch_aug28a:184: error: expected `}’ at end of input

      • Andrius says:

        I’ve seen this before, HTML messes up some characters and code would not compile. I’ve attached zip file with the code at the bottom of the post.

  2. wjh says:

    Hello,

    reallynice in deed.,
    i´ll try ,but while compiling there should be some probl. with “counter = counter – 1;”.

    or did i miss something ?

    best

    wjh

    • Andrius says:

      Can you paste the full error message that you are getting. I think it might be because of code pasting from the website. Check if counter is properly declared in the begening of the code.

  3. wjh says:

    hello,

    wow., thx u so much.

    great work 😀

    best

    wjh

  4. robert says:

    hi,

    nice project u did. i put the code on my board( witch compile and transfer fine)i just start with arduino ,so i am not as big in understand everything.

    i read all parts u wrote more than once ,but still i have to ask.

    the (stair) leds ., do they go all to GND ? or to plus ?

    and were did u put the lightsensor on., ( in the code it looks like pin 2 ., but there is the IR sensor already.

    also what i didnt get yet is., are the ir sensors going to the digital inputs ?

    i am sorry for those question., i hope u find some time and get back..

    thx in advance

    respect

    r.

    • Andrius says:

      LED depend how you connect them. If you us ULN darlington array then the common is + and GND goes through ULN to digital pins. If connecting directly then its the other way, but you need to use resistors.
      There are two IR sensors digital pins 2 and 4. Light Sensor goes to analog pin 0.

Leave a Reply

IT Blog

Just another blog on Kozeniauskas.com Network