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 @  and
//TigPT @

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() {
  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){
  for(int i=0;i<steps;i++){
    digitalWrite(stepperPin, HIGH);
    digitalWrite(stepperPin, LOW);

void loop(){
  PIRalarmValue = analogRead(PIRalarmPin);
  if (PIRalarmValue < 100) {
    alarmValue = 0;
  else {
    alarmValue = 1;
  if (alarmValue = alarmValuePrevious) {
    if (alarmValue = 0) {
      digitalWrite(ledPin, HIGH);
      alarmValuePrevious = 0;
    else {
      digitalWrite(ledPin, LOW);
      Serial.println("no motion");
      alarmValuePrevious = 1;


Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: