Arduino

Home / projects / microcontrollers / Arduino



Enclosure with Random Parts

This is the enclosure with the button installed, the hole cut for the LED, and the perf board mounted.

Inside view of the top panel so you can see the perf board mounted. I need to figure out some easy way to cut these,
this time I just scored it with an xacto knife and then broke it off with pliers. As you can see that worked ok for
the top layers and then left the rest rough.

Another view, you can see the standoffs that the board is mounted too.

The circuit for the 7 segment display. I can't find a shift register anywhere local so I have to order one. Once I have
one that should reduce the number of pins used on the Arduino.

So the first thing I decided to make is an enclosure filled with various parts so I can test out building something and working with my tools I have laying around.

I'm not really sure what it is going to do yet. I was thinking maybe it would count down then light up a bunch of bright LED's. Kind of like a poor mans 'party button' if you have seen that (just look on youtube.)

Here is the parts list for this build:

1 - Radioshack project enclosure 4"x6"x2"
1 - Radioshack switch with safety cover (because it looks cool!)
1 - Radioshack perf board 2 3/4"x 3 3/4"
1 - box of Radioshack 10mm standoffs
1 - sparkfun 4 digit 7 segment led display, blue
12 - 1k ohm resistors
4 - 3906 pnp transistors

Lessons learned so far:

Enclosure manufacturers don't talk to PCB manufacturers at all. The enclosure people make all kinds of enclousures and add mounting points and everything but they don't make any PCB's to mount to them.

Enclosures are a bitch to cut. I used the dremel drill press to hit the corners of the led display area then used an xacto knife to cute lines between them. The I used various saws to link the holes then nibblers to get it somewhat square, I'm going to have to get a CNC mill to get this right.

The LED isn't mounted yet because the distance is wrong, it barely reaches the holes on the perf board. I am going to get some female headers and solder those to the perf board and that should make it fit nicely. Also, that will let me remove the LED to use it for something else later.

Right now the digits are multiplexed. This is a common anode display and the cathodes are connected to pins 0-6, except the colon which is connected direct to ground since I'm leaving it always on.

The anodes are conneted to pins 8-11 via 1 k ohm resistors and pnp 3906 transistors. The pins connect to base on the transistor, the emitter is connected to the anodes and the collector to 5v.

Sketch follows...


#define D1 8
#define D2 9
#define D3 10
#define D4 11

int ms = 1;
int digitPins[4] = {8, 9, 10, 11};

void setup() {
  DDRD = B01111111;

  for(int i=0; i < 4; i++) {
    pinMode(digitPins[i], OUTPUT);
    digitalWrite(digitPins[i], LOW);
  }

  zero();
  delay(ms *100);
  one();
  delay(ms *100);
  two();
  delay(ms *100);
  three();
  delay(ms *100);
  four();
  delay(ms *100);
  five();
  delay(ms *100);
  six();
  delay(ms *100);
  seven();
  delay(ms *100);
  eight();
  delay(ms *100);
  nine();
  delay(ms *100);

  for(int i=0; i < 4; i++) {
    digitalWrite(digitPins[i], HIGH);
  }



  for(int i=0; i < 1000; i++) {
    digitalWrite(digitPins[0], LOW);
    PORTD = B01010010; // f
    delay(3);
    digitalWrite(digitPins[0], HIGH);

    digitalWrite(digitPins[1], LOW);
    PORTD = B01101100; // u
    delay(3);
    digitalWrite(digitPins[1], HIGH);

    digitalWrite(digitPins[2], LOW);
    PORTD = B01111000; // c
    delay(3);
    digitalWrite(digitPins[2], HIGH);

    digitalWrite(digitPins[3], LOW);
    PORTD = B00100010; // k
    delay(3);
    digitalWrite(digitPins[3], HIGH);
  }
}

void loop() {
    digitalWrite(digitPins[0], LOW);
    zero();
    digitalWrite(digitPins[0], HIGH);    

    digitalWrite(digitPins[1], LOW);
    one();
    digitalWrite(digitPins[1], HIGH);
    
    digitalWrite(digitPins[2], LOW);
    two();
    digitalWrite(digitPins[2], HIGH);
    
    digitalWrite(digitPins[3], LOW);
    five();
    digitalWrite(digitPins[3], HIGH);    
}

void zero() {
  PORTD = B00000100;
  delay(ms);
}

void one() {
  PORTD = B00101111;
  delay(ms);
}

void two() {
  PORTD = B00011000;
  delay(ms);
}

void three() {
  PORTD = B00001001;
  delay(ms);
}

void four() {
  PORTD = B00100011;
  delay(ms);
}

void five() {
  PORTD = B01000001;
  delay(ms);
}

void six() {
  PORTD = B01000000;
  delay(ms);
}

void seven() {
  PORTD = B00001111;
  delay(ms);
}

void eight() {
  PORTD = B00000000;
  delay(ms);
}

void nine() {
  PORTD = B00000011;
  delay(ms);
}
Simple Larson Scanner/Cylon Eye

So the first thing I decided to make is an enclosure filled with various parts so I can test out building something and working with my tools I have laying around.
Sketch follows...

int green   = 10;            // Digital pin 10 - Green LED  
int red     = 6;            // Digital pin 6 - Red LED  
int blue    = 5;             // Digital pin 5  - Blue LED  
int white    = 3;             // Digital pin 3  - Blue LED  

int time    = 1;             // define delay element  
int pulsewidth;              // define pulsewidth (0-255)  
int crappo;

void setup() {  
  for (pulsewidth=0; pulsewidth <= 255; pulsewidth++){  
    analogWrite(green, pulsewidth);  
    delay(time);  
  }
}  
 
void loop() {  
 
  // slowly dim the LEDs  
  crappo = 0;
  for (pulsewidth=255; pulsewidth >= 0; pulsewidth--){  
    analogWrite(green, pulsewidth);  
    analogWrite(red, crappo);  
    crappo = crappo + 1;
    delay(time);  
  }  

  crappo = 0;
  for (pulsewidth=255; pulsewidth >= 0; pulsewidth--){  
    analogWrite(red, pulsewidth);  
    analogWrite(blue, crappo);  
    crappo = crappo + 1;
    delay(time);  
  }  

  crappo = 0;
  for (pulsewidth=255; pulsewidth >= 0; pulsewidth--){  
    analogWrite(blue, pulsewidth);  
    analogWrite(white, crappo);  
    crappo = crappo + 1;
    delay(time);  
  }  

  crappo = 0;
  for (pulsewidth=255; pulsewidth >= 0; pulsewidth--){  
    analogWrite(white, pulsewidth);  
    analogWrite(blue, crappo);  
    crappo = crappo + 1;
    delay(time);  
  }  

  crappo = 0;
  for (pulsewidth=255; pulsewidth >= 0; pulsewidth--){  
    analogWrite(blue, pulsewidth);  
    analogWrite(red, crappo);  
    crappo = crappo + 1;
    delay(time);  
  }  

  crappo = 0;
  for (pulsewidth=255; pulsewidth >= 0; pulsewidth--){  
    analogWrite(red, pulsewidth);  
    analogWrite(green, crappo);  
    crappo = crappo + 1;
    delay(time);  
  }  
}
Easy Driver Stepper Controller

This is my first try at making a schematic in Eagle.

So working with a stepper motor controller.
Sketch follows...

// setup pins to control the stepper motor
int dirPin = 3;
int stepperPin = 2;

// setup pins for the switches
int switchPin = 7;              
int switchPin_2 = 6;

// variables for reading the pin status
int val;                     
int val_2;

// variable to hold the last button state
int buttonState;                
int buttonState_2;


void setup() {
  // set stepper pins as outputs
  pinMode(dirPin, OUTPUT);
  pinMode(stepperPin, OUTPUT);

  pinMode(switchPin, INPUT);    // Set the switch pin as input
  buttonState = digitalRead(switchPin);   // read the initial state
  pinMode(switchPin_2, INPUT);    // Set the switch pin as input
  buttonState_2 = digitalRead(switchPin_2);   // read the initial state
}

void step(boolean dir,int steps){
  digitalWrite(dirPin,dir);
  delay(50);
  for(int i=0;i