Pages: [1]   Go Down
Author Topic: question and suggestion  (Read 395 times)
0 Members and 1 Guest are viewing this topic.
South Louisiana
Offline Offline
Full Member
***
Karma: 0
Posts: 180
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I learn best by functional projects. i have been wanting to learn programming and improve my knowledge of component level electronics for quite a while. So i decided to integrate some led's into the door handles of my truck, they look cool and all, but i mostly wanted to do it because i would learn a lot in the process.

I have quite a few LED's i will be controlling so i am using some 3904 transistors to get the job done and keep the heavy lifting off the board.

So:

If i hook up an o-scope on the board side of the PWM output i see a great square wave. At the led it's not so pretty. Any idea why the pwn signal looks funky on the other side of the transistor? For the most part it works ok, i am just wondering if there is a better way to do this that i may be unaware of.

so here's some info and some code.

the resistor between the board and transistor is a 10K



« Last Edit: July 31, 2010, 01:14:07 pm by goofballtech » Logged

South Louisiana
Offline Offline
Full Member
***
Karma: 0
Posts: 180
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
if ( digitalRead (alarmIn) == HIGH && alarmOffCount == 0 ) {
  alarmOffCount = 1;
  ledFade (fr, fb, fg, rr, rg, rb, 35, .5, 5); // white fade when truck is unlocked
}

while (digitalRead (intlights) == LOW && digitalRead (alarmIn) == HIGH){ //code for interior lights to change colors selected by 5K pot

totalValue = 0; //reset variables at beginning of loop
trueValue = 0;

 for (int i=1; i<=50 ; i++){ //take 50 readings from Analog Input pin
 trueValue = analogRead(colorIn);
 totalValue = trueValue + totalValue;
 sampleTotal = i;
 }

colorValue = totalValue/sampleTotal; //get average of 50 readings pulled in from loop
      
Serial.println(colorValue); // Print average color value to serial port

intLights (0, 175, 0, rr, 0, fr); // takes a value from the pot (0-1023) and uses that value to change the colors on the led
intLights (165, 345, rr, rb, fr, fb);
intLights (335, 515, rb, rg, fb, fg);
intLights (505, 685, rg, rr, fg, fr);
intLights (675, 855, 0, rb, 0, fb);
intLights (845, 1015, 0, rg, 0, fg);

 }


while ( digitalRead (alarmIn) == LOW ) { // While viper is armed pin holds to low and the 4 color fade cycle repeats 100 times

alarmOffCount = 0;

for ( repeatCount=1 ; repeatCount<100 ; repeatCount++ ) {
ledFade (fr, 0, 0, rr, 0, 0, 50, 2, 5); //red fade
ledFade (0, fg, 0, 0, rg, 0, 30, .5, 5); //green fade
ledFade (0, 0, fb, 0, 0, rb, 30, 1, 5); //blue fade
ledFade (fr, fb, fg, rr, rg, rb, 30, .5, 5); // white fade
  
    if ( digitalRead (alarmIn) == HIGH ) {
    break;
    }
  }
}


Quote
void intLights (int low, int high, int LEDlower1, int LEDraise1, int LEDlower2, int LEDraise2){ //takes the value from the pot and turns it into led values
    
  if(colorValue == 0) {
    digitalWrite(rr, LOW);
    digitalWrite(fr, LOW);
    
    digitalWrite(rg, LOW);
    digitalWrite(fg, LOW);
    
    digitalWrite(rb, LOW);
    digitalWrite(fb, LOW);
  }
  
  else if(colorValue >1000){
    digitalWrite(rr, HIGH);
    digitalWrite(fr, HIGH);
    
    digitalWrite(rg, HIGH);
    digitalWrite(fg, HIGH);
    
    digitalWrite(rb, HIGH);
    digitalWrite(fb, HIGH);
  }

else if (colorValue > low && colorValue < high){
  
  int LED1 = map (colorValue, low, high, 255, 10);
  int LED2 = map (colorValue, low, high, 10, 255);
  int LED3 = map (colorValue, low, high, 255, 10);
  int LED4 = map (colorValue, low, high, 10, 255);
  
  analogWrite (LEDlower1, LED1);
  analogWrite (LEDraise1, LED2);
  analogWrite (LEDlower2, LED3);
  analogWrite (LEDraise2, LED4);
  
}

 


Quote
 void ledFade (int f1, int f2, int f3, int r1, int r2, int r3, int delayTime, float fadeIncrementOn, float fadeIncrementOff){  
   
 for (float fadeValue = 0; fadeValue <=255 ; fadeValue +=fadeIncrementOn) { //fade door led's to on
   analogWrite (f1, fadeValue);
   analogWrite (f2, fadeValue);
   analogWrite (f3, fadeValue);
   analogWrite (r1, fadeValue);
   analogWrite (r2, fadeValue);
   analogWrite (r3, fadeValue);
   delay(delayTime);
   
   if ( digitalRead (alarmIn) == HIGH ){ //check to see if alarm is still armed
    digitalWrite (fg, LOW); // Turn all LED's off
    digitalWrite (fb, LOW);
    digitalWrite (fr, LOW);
    digitalWrite (rg, LOW);
    digitalWrite (rb, LOW);
    digitalWrite (rr, LOW);
    repeatCount=1;
    loop ();
    }
  } 
 
  for (float fadeValue = 255; fadeValue >=0 ; fadeValue -=fadeIncrementOff) { //fade door led's to off
   analogWrite (f1, fadeValue);
   analogWrite (f2, fadeValue);
   analogWrite (f3, fadeValue);
   analogWrite (r1, fadeValue);
   analogWrite (r2, fadeValue);
   analogWrite (r3, fadeValue);
   delay(delayTime);
    
    if ( digitalRead (alarmIn) == HIGH ){ //check to see if alarm is still armed
    digitalWrite (fg, LOW); // Turn all LED's off
    digitalWrite (fb, LOW);
    digitalWrite (fr, LOW);
    digitalWrite (rg, LOW);
    digitalWrite (rb, LOW);
    digitalWrite (rr, LOW);
    repeatCount=1;
    loop ();
    }
  }

digitalWrite (fg, LOW); // Turn all LED's off
digitalWrite (fb, LOW);
digitalWrite (fr, LOW);
digitalWrite (rg, LOW);
digitalWrite (rb, LOW);
digitalWrite (rr, LOW);

 if ( digitalRead (alarmIn) == HIGH ){ //check to see if alarm is still armed
    repeatCount=1;
    loop ();
    }
    
  delay(1000);
  
   if ( digitalRead (alarmIn) == HIGH ){//check to see if alarm is still armed
    repeatCount=1;
    loop ();
    }
      
 }

Logged

South Louisiana
Offline Offline
Full Member
***
Karma: 0
Posts: 180
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

that diagram was build more so for guys who were curious how i wired it more than what was happening in. I just posted it because it was available. It works on but the leds seem to flicker sometimes and i think the signal not being a good square wave is why.

The wiring diagram is of a shield i built from a bread board to tie into.





as far as the diagram goes.

the 6 vertical resistors are tied to the Base of each transistor.

the three transistors on the left tie to the front door handles and interior led's. the three on the right use the other resistors on the board to tie to the rear door handle led's.
« Last Edit: July 31, 2010, 02:08:36 pm by goofballtech » Logged

Pages: [1]   Go Up
Jump to: