assignment.04 | Arduino

My components are ordered and are expected to arrive on Friday by the end of the day, so I thought I should take a stab at writing the Arduino sketch to control my luminaire. Having experience in both Processing and Arduino definitely helped me with this sketch as I do not yet have the hardware to test it with, I know it will need tweaking especially the delay and the number of steps, but I think I am at a good point with it for now until I can actually test it. All I have to do now is think of the actual guts of the lamp, and rethinking the overlap between the panels. I would like to light the lamp with an LED array of some sort because I could power it off of my Arduino, but I do not know if it will work correctly as LEDs tend to be pretty tight in their beam spread. I also need to figure out how I am going to get power to this lamp. Right now the Arduino runs off of a 9v source and the stepper motor off of a 12v source. Hence the reason I would like to use LEDs. Another idea I had for control would be to write into the code for the lamp to turn off at a certain time, but seeing as it won’t be attached to a computer I cannot determine the current time on the Arduino itself (without the implementation of another chip which I forgot to purchase). So my current solution to all of those problems is to get a long power strip (because they are legal in our building) and plug everything into the power strip within the luminaire itself.

Thoughts and problems that have yet to be resolved with very little time left…!


//Controlling a stepper motor with a PIR motion sensor.
//Written by Geoff Sosebee with example code from:
//Dan Thompson @ http://danthompsonsblog.blogspot.com  and
//TigPT @ http://lusorobotica.com

int dirPin = 2;
int stepperPin = 3;
int numSteps = 1600;
int timer = 500;
int PIRalarmPin = 0;
int PIRalarmValue = 0;
int alarmValue = 0;
int alarmValuePrevious = 0;
int ledPin = 13;

void setup() {
  Serial.begin(9600);
  pinMode(dirPin, OUTPUT);
  pinMode(stepperPin, OUTPUT);
  pinMode(ledPin, OUTPUT);
  pinMode(PIRalarmPin, INPUT);
  delay (2000);  //delay 2 seconds for PIR to scan area
}

void step(boolean dir,int steps){
  digitalWrite(dirPin,dir);
  delay(50);
  for(int i=0;i<steps;i++){
    digitalWrite(stepperPin, HIGH);
    delayMicroseconds(100);
    digitalWrite(stepperPin, LOW);
    delayMicroseconds(100);
  }
}

void loop(){
  PIRalarmValue = analogRead(PIRalarmPin);
  if (PIRalarmValue < 100) {
    alarmValue = 0;
  }
  else {
    alarmValue = 1;
  }
  if (alarmValue = alarmValuePrevious) {
    if (alarmValue = 0) {
      digitalWrite(ledPin, HIGH);
      Serial.println("motion");
      delay(10);
      step(true,numSteps);
      delay(500);
      alarmValuePrevious = 0;
    }
    else {
      digitalWrite(ledPin, LOW);
      Serial.println("no motion");
      delay(10);
      step(false,numSteps);
      delay(500);
      alarmValuePrevious = 1;
    }
  }
  delay(timer);
}

Leave a Reply

Your email address will not be published. Required fields are marked *