Completely new at this

Wendy

Joined Mar 24, 2008
23,415
There is nothing formal about this, but generally one or two members take an interest in someone else project. Looks like Tracecom has volunteered. :p

Seriously, if you have any questions about schematic or how a circuit I've posted (or any circuit for that matter) works, just ask. Many times you'll get many answers, and one might make sense where the rest don't.
 

tracecom

Joined Apr 16, 2010
3,944
There is nothing formal about this, but generally one or two members take an interest in someone else project. Looks like Tracecom has volunteered. :p
Bill,

I am interested in the project and am working on a PICAXE solution, but that doesn't mean that other options aren't welcome. I saw on youtube some examples of light bars that were run by 555's, and would love to see such a circuit from you. I think that elec_mech is coming up with a non-μC solution and hope to see it as well.
 

elec_mech

Joined Nov 12, 2008
1,500
Okay, I'm making progress as time allows. Because I've yet to figure out how to embed an image into the message portion of a post, you'll have to settle for PDF attachments.

I've created a simple 555 timer circuit in astable mode to cover flashing the yellow and white LEDs. Using Bill's dual LED circuit as a reference, I added an N- and P-channel MOSFET to the output of the 555. The MOSFETs are used to handle the current draw of the LEDs and reduce power consumption of transistors normally found with this type of circuit. You can change the blink rate with VR1.

Please note that transistors and MOSFETs are still new territory for me, so I kindly ask the people with more knowledge in this area to review and let me know if I've done something incorrectly. I'll look more into which MOSFETs will work best once I've gotten some feedback on the circuit

The resistors on the LEDs will depend on the voltage available to power the circuit. For the OP, what is the voltage available to the circuit? Since this is for an RC car, I assume you've got 7.2VDC or 9.6VDC, but that also assumes you're using an electric (not gas) car.

I need more time, but I think I have a discrete solution for flashing the red and blue LEDs as described using a CD4017 and either a ULN2804 or possibly a CD4066, one of the latter two to handle the current draw. For the OP, is the following okay:

Red:
1. On
2. Off
3. On
4. Off
5. On
6. Off

Blue:
6. On
7. Off
8. On
9. Off
10. On
1. Off

Can the blue light up as soon as the red finishes its sequence? In other words, once the red LED lights up for the third time, the blue LED comes on as soon as the red LED goes out. Same case for vice-versa. Is this okay or do you need a pause (everything off) between the transisition of the two colors?
 

Attachments

Thread Starter

32_d3gr33s

Joined Oct 29, 2011
35
Okay, I'm making progress as time allows. Because I've yet to figure out how to embed an image into the message portion of a post, you'll have to settle for PDF attachments.

I've created a simple 555 timer circuit in astable mode to cover flashing the yellow and white LEDs. Using Bill's dual LED circuit as a reference, I added an N- and P-channel MOSFET to the output of the 555. The MOSFETs are used to handle the current draw of the LEDs and reduce power consumption of transistors normally found with this type of circuit. You can change the blink rate with VR1.

Please note that transistors and MOSFETs are still new territory for me, so I kindly ask the people with more knowledge in this area to review and let me know if I've done something incorrectly. I'll look more into which MOSFETs will work best once I've gotten some feedback on the circuit

The resistors on the LEDs will depend on the voltage available to power the circuit. For the OP, what is the voltage available to the circuit? Since this is for an RC car, I assume you've got 7.2VDC or 9.6VDC, but that also assumes you're using an electric (not gas) car.

I need more time, but I think I have a discrete solution for flashing the red and blue LEDs as described using a CD4017 and either a ULN2804 or possibly a CD4066, one of the latter two to handle the current draw. For the OP, is the following okay:

Red:
1. On
2. Off
3. On
4. Off
5. On
6. Off

Blue:
6. On
7. Off
8. On
9. Off
10. On
1. Off

Can the blue light up as soon as the red finishes its sequence? In other words, once the red LED lights up for the third time, the blue LED comes on as soon as the red LED goes out. Same case for vice-versa. Is this okay or do you need a pause (everything off) between the transisition of the two colors?
That looks fine for the flash pattern. If the blue flashes immediatly after the red, thats fine as well. Im not too concered with the timing of the flashes, just as long as they are alternating back and forth.

for the battery, i planned on using 1 (or 2 if needed) 9 volt batteries. Ive tried using the main battery for lights on a previous car, and just found it more practical to have a seperate battery for the lights, otherwise i have to try to plug in the body to the chassis.
 

Thread Starter

32_d3gr33s

Joined Oct 29, 2011
35
That is almost perfect! Only question is can you slow the flashing down on the white/yellow? I was kind of hoping for a slow flash.
 

elec_mech

Joined Nov 12, 2008
1,500
Tracecom,

And I thought I was fast posting a portion of the circuit - nice job. I believe the OP stated he wanted the red to flash three times (blue off during this time), then the blue to flash three times (red off during this time), then repeat.

At least, that was my understanding.

OP,

When you say 9V battery, do you mean a regular 9V rectangular or something like a 9.6V RC battery pack? You won't get a lot of time out of a regular 9V battery and we'll have to better plan how to hook up the LEDs so they don't die when the discharge curve gets below a certain level. In layman's terms, it won't be terribly efficient and you'll need to replace the 9V battery pretty often. Now, if you could fit six or eight AA batteries into the car . . .
 

ke5nnt

Joined Mar 1, 2009
384
I have been following this thread loosely, only because I'm short on time, otherwise I'd have been following it more in depth and providing my own input, but between my own projects and my insane school/work schedules, I'm really just out of time.

Anyways, the OP had been wondering about using microcontrollers for police style lighting. I thought I'd post a couple examples so that he can see what the coding process looks like. Also, even though it looks incredibly daunting at first, once you understand what the language is saying, it gets way easier to write things. Additionally, it is so much fun to play with the patters by making changes to the software and seeing how it effects the hardware. Picking up microcontrollers and learning to write code (not 100% proficient with it myself) was one of the best things I ever decided to do.

Ok, both examples were written in MPLAB IDE free version for Microchip MCUs. First example is written in assembly language and has multiple flash patterns that can be scrolled through by depressing a momentary switch.

Keep in mind the code isn't as pretty as it could be, it was one of the first pieces of software I wrote, and doesn't take full advantage of what the MCU can do, but it works.

Rich (BB code):
;************************************************************************
;PROGRAM GI-101-D
;4 MHZ INT OSC
;Ryan Goff 
;NOV-12-2009
;************************************************************************
;
        LIST    p=PIC12F629
        INCLUDE p12f629.INC
;
;************************************************************************
        __CONFIG B'11000110000100'    ;CODE PROTECTION OFF, HIGHEST BANDGAP VOLTAGE,
                                    ;BROWNOUT DETECTION OFF, MCLR INTERNALLY TIED TO Vdd,
                                    ;POWER-UP TIMER ENABLED, WDT OFF, INT OSC / I/O ON GP4,5
        ERRORLEVEL    -302
;************************************************************************
COUNT1    EQU     22
COUNT2    EQU        23
COUNT3    EQU        24
F_COUNT    EQU        25
F_COUN2    EQU        26
;
        ORG        0x00
        GOTO    START
;
        ORG        0x04
        GOTO    SBNCE
;
;************************************************************************
;Subroutines
T40MS    MOVLW    0x3F
        MOVWF    COUNT1
        MOVLW    0x20
        MOVWF    COUNT2
TLOOP1    DECFSZ    COUNT1
        GOTO    $+2
        DECFSZ    COUNT2
        GOTO    TLOOP1
        RETURN
;----------------------
T50MS    MOVLW    0x0F
        MOVWF    COUNT1
        MOVLW    0x28
        MOVWF    COUNT2
TLOOP2    DECFSZ    COUNT1
        GOTO    $+2
        DECFSZ    COUNT2
        GOTO    TLOOP2
        RETURN
;----------------------
T125MS    MOVLW    0xA7
        MOVWF    COUNT1
        MOVLW    0x62
        MOVWF    COUNT2
TLOOP3    DECFSZ    COUNT1
        GOTO    $+2
        DECFSZ    COUNT2
        GOTO    TLOOP3
        RETURN
;----------------------
T250MS    MOVLW    0x4F
        MOVWF    COUNT1
        MOVLW    0xC4
        MOVWF    COUNT2
TLOOP4    DECFSZ    COUNT1
        GOTO    $+2
        DECFSZ    COUNT2
        GOTO    TLOOP4
        RETURN
;-----------------------
...
;*************************************************************************
;Initialize
START    BSF        STATUS,5        ;SELECT BANK 1
        MOVLW    B'11111111'
        MOVWF    OPTION_REG        ;SELECT TMR0 OPTIONS AND PRESCALER TO 128
        MOVLW    B'01000100'        ;SELECT PIN2 INPUT, 6:3 AND 1:0 OUTPUT
        MOVWF    TRISIO            ;GPIO AS ABOVE
        BCF        STATUS,5        ;SELECT BANK 0
        MOVLW    B'11010000'        ;ALLOW GP2/INT, SET GLOBAL INTERRUPT
        MOVWF    INTCON            ;INTERRUPT ON FALLING EDGE
;
;*************************************************************************
;                    STROBING WIG-WAG
SWAG    BCF        INTCON,1        ;CLEAR INT FLAG
        CLRF    GPIO            ;CLEAR GPIO PINS
SWAG1    MOVLW    .6
        MOVWF    F_COUNT            ;6 FLASHES
S_1        BSF        GPIO,0            
        CALL    T40MS            ;LED1 ON
        BCF        GPIO,0            
        CALL    T40MS            ;LED1 OFF
        DECFSZ    F_COUNT            ;6 FLASHES?
        GOTO    S_1                ;FLASH AGAIN IF NO
        CALL    T40MS
        MOVLW    .6
        MOVWF    F_COUNT            ;6 FLASHES
S_2        BSF        GPIO,4
        CALL    T40MS            ;LED2 ON
        BCF        GPIO,4            
        CALL    T40MS            ;LED2 OFF
        DECFSZ    F_COUNT            ;6 FLASHES?
        GOTO    S_2                ;FLASH AGAIN IF NO
        CALL    T40MS
        BTFSC    INTCON,1        ;INT FLAG?
        GOTO    RPDFLSH            ;GO NEXT PATTERN IF YES
        GOTO    SWAG1            ;OR STAY HERE
;*************************************************************************
;                    RAPID FLASH
RPDFLSH    BCF        INTCON,1        ;CLEAR INT FLAG
        CLRF    GPIO            ;CLEAR GPIO PINS
R_1        BSF        GPIO,0
        CALL    T50MS            ;LED1 ON
        BCF        GPIO,0
        CALL    T50MS            ;LED1 OFF
        BSF        GPIO,4
        CALL    T50MS            ;LED2 ON
        BCF        GPIO,4
        CALL    T50MS            ;LED2 OFF
        BTFSC    INTCON,1        ;INT FLAG?
        GOTO    STRBSH            ;GO NEXT PATTERN IF YES
        GOTO    R_1                ;OR STAY HERE
;**************************************************************************
;                    STROBE SHIFT
STRBSH    BCF        INTCON,1        ;CLEAR INT FLAG
        CLRF    GPIO            ;CLEAR GPIO PINS
STRBSH1    MOVLW    .6
        MOVWF    F_COUNT            ;6 FLASHES
SS_1    BSF        GPIO,0
        CALL    T40MS            ;LED1 ON
        BCF        GPIO,0
        CALL    T40MS            ;LED1 OFF
        DECFSZ    F_COUNT            ;6 FLASHES?
        GOTO    SS_1            ;FLASH AGAIN IF NO
        MOVLW    .6
        MOVWF    F_COUNT            ;6 FLASHES
SS_2    BSF        GPIO,4
        CALL    T40MS            ;LED2 ON
        BCF        GPIO,4
        CALL    T40MS            ;LED2 OFF
        DECFSZ    F_COUNT            ;6 FLASHES?
        GOTO    SS_2            ;FLASH AGAIN IF NO
        BSF        GPIO,0            ;LED1 ON
        CALL    T250MS
        BCF        GPIO,0            ;LED1 OFF
        BSF        GPIO,4            ;LED2 ON
        CALL    T250MS
        BCF        GPIO,4            ;LED2 OFF
        BSF        GPIO,0            ;LED1 ON
        CALL    T500MS
        BCF        GPIO,0            ;LED1 OFF
        BSF        GPIO,4            ;LED2 ON
        CALL    T500MS
        BCF        GPIO,4            ;LED2 OFF
        BTFSC    INTCON,1        ;INT FLAG?
        GOTO    WIGWAG            ;GO NEXT PATTERN IF YES
        GOTO    STRBSH1            ;OR STAY HERE
;****************************************************************************
...
;****************************************************************************
;                    DUAL FLASH
DUAL    BCF        INTCON,1        ;CLEAR INT FLAG
        CLRF    GPIO            ;CLEAR GPIO PINS
DUAL1    MOVLW    .2
        MOVWF    F_COUNT            ;2 FLASHES
DS1        BSF        GPIO,0            ;LED1 ON
        CALL    T125MS
        BCF        GPIO,0            ;LED1 OFF
        CALL    T125MS
        DECFSZ    F_COUNT            ;2 FLASHES?
        GOTO    DS1                ;FLASH AGAIN IF NO
        MOVLW    .2
        MOVWF    F_COUNT            ;2 FLASHES
DS2        BSF        GPIO,4            ;LED2 ON
        CALL    T125MS
        BCF        GPIO,4            ;LED2 OFF
        CALL    T125MS
        DECFSZ    F_COUNT            ;2 FLASHES?
        GOTO    DS2                ;FLASH AGAIN IF NO
        BTFSC    INTCON,1        ;INT FLAG?
        GOTO    COMET            ;GO NEXT PATTERN IF YES
        GOTO    DUAL1            ;OR STAY HERE
;**************************************************************************
...
;***********************************************************************
...
;*****************************************************************
;                    CALIFORNIA FLASH
CALI    BCF        INTCON,1        ;CLEAR INT FLAG
        CLRF    GPIO            ;CLEAR GPIO PINS
        MOVLW    B'00000001'
        MOVWF    GPIO            ;LED1 ALWAYS ON
CALI_1    CALL    T125MS
        MOVLW    B'00010001'
        MOVWF    GPIO            ;LED2 ON
        CALL    T125MS
        MOVLW    B'00000001'
        MOVWF    GPIO            ;LED2 OFF
        BTFSC    INTCON,1        ;INT FLAG?
        GOTO    CALI_S            ;GO NEXT PATTERN IF YES
        GOTO    CALI_1            ;OR STAY HERE
;*****************************************************************
...
;*****************************************************************
;                    STROBE-FLASH ALL
SALL    BCF        INTCON,1        ;CLEAR INT FLAG
        CLRF    GPIO            ;CLEAR GPIO PINS
SALL_1    MOVLW    .4
        MOVWF    F_COUNT            ;3 FLASHES
SALL_2    MOVLW    B'00010001'        ;LED1 AND LED2 ON
        MOVWF    GPIO
        CALL    T50MS
        MOVLW    B'00000000'        ;LED1 AND LED2 OFF
        MOVWF    GPIO
        CALL    T50MS
        DECFSZ    F_COUNT            ;3 FLASHES?
        GOTO    SALL_2            ;FLASH AGAIN IF NO
        MOVLW    B'00010001'        ;LED1 AND LED2 ON
        MOVWF    GPIO
        CALL    T400MS
        MOVLW    B'00000000'        ;LED1 AND LED2 OFF
        MOVWF    GPIO
        CALL    T400MS
        BTFSC    INTCON,1        ;INT FLAG?
        GOTO    ALTS            ;GO NEXT PATTERN IF YES
        GOTO    SALL_1            ;OR STAY HERE
;*****************************************************************
...
;*****************************************************************
        end
Clipped due to character limit. Also, post 1 of 2.
 

ke5nnt

Joined Mar 1, 2009
384
This next example is in the C language. It's purpose was to test using EEPROM memory to store and retrieve data. Basically, the idea is that you scroll through the flash patterns until you find one you like. Once you keep the device in that particular pattern for X seconds, it stores that pattern into EEPROM so the next time you turn on the device, it automatically goes to that pattern instead of starting back at default. This code does not have a time delay programmed into it yet, so the EEPROM is written immediately upon entering a flash pattern.

Rich (BB code):
//
//    THIS IS A PROGRAM MEANT TO TEST STORING AND
//    RETREIVING EEPROM DATA
//
//    RYAN GOFF
//    AUG-23-2011
//    PIC16F628A
//    HIGH-TECH C COMPILER, MPLAB IDE
/*************************************************/

// CONFIGURATION

#include <htc.h>
#define _XTAL_FREQ 4000000
__CONFIG(INTIO & WDTDIS & PWRTEN & MCLRDIS & BORDIS & LVPDIS & UNPROTECT & UNPROTECT);

/*************************************************/

//    GLOBAL VARIABLES

unsigned char dlycnt;    //DELAY COUNTER
unsigned char fpnum;    //FLASH PATTERN NUMBER
unsigned char set = 0;
unsigned char dbnce;    //SWITCH DEBOUNCE
/*************************************************/

void main()                //MAIN PROGRAM START
{
unsigned char address = 0;    //DEFINE ADDRESS FOR EEPROM
INTEDG = 1;                    //TRIGGER INTERRUPT ON RISING EDGE
INTE = 1;                    //RB0 EDGE INTERRUPT ENABLED
ei();                        //GLOBAL INTERRUPTS ENABLED

fpnum = eeprom_read(address); //DATA READ FROM EEPROM AND COPIED TO fpnum

 OSCF=1;            // INTERNAL OSCILLATOR 48KHz
 TRISA=0XFF;        // TRISA NOT USED, ALL SET AS INPUT
 TRISB=0XF7;        // TRISB 7-4 INPUT, 3 OUTPUT, 2-0 INPUT

 while(1)                //MAIN LOOP START
 {

/************FLASH PATTERN 1**********************/

    if (fpnum==1)        //FLASH PATTERN 1
    {
     while (set!=0)        //IF "SET" VARIABLE HAS BEEN SET
     {
      eeprom_write(address, 1);    //WRITE DATA TO EEPROM
      set=0;            //UNSET "SET" VARIABLE
     }
     RB3=1;            //SET RB3 HIGH
     for (dlycnt=0; dlycnt<10; dlycnt++)    //CALL 1 SECOND DELAY
     {
        __delay_ms(100);
     }
     RB3=0;            //SET RB3 LOW
     for (dlycnt=0; dlycnt<10; dlycnt++)    //CALL 1 SECOND DELAY
     {
        __delay_ms(100);
     }
    }

/************FLASH PATTERN 2*********************/

    else if (fpnum==2)
    {
     while (set!=0)
      {
       eeprom_write(address, 2);
       set=0;
      }
      RB3=1;        //SET RB3 HIGH
      for (dlycnt=0; dlycnt<5; dlycnt++)    //CALL 500MS DELAY
      {
        __delay_ms(100);
      }
      RB3=0;        //SET RB3 LOW
      for (dlycnt=0; dlycnt<5; dlycnt++)    //CALL 500MS DELAY
      {
        __delay_ms(100);
      }
     }

/************FLASH DEFAULT************************/

    else
    {
     while (set!=0)
      {
       fpnum=0;
       set=0;
      }
      RB3=1;        //SET RB3 HIGH
    }
 }
}

/***********INTERRUPT SERVICE ROUTINE*************/

void interrupt isr(void)
{
 for(dbnce=0; dbnce<20; dbnce++)
  {
   __delay_ms(5);
  }
 fpnum++;
 set = 1;
 if(RB0==1)
  {
   ;
  }
 else
  {
   for(dbnce=0; dbnce<20; dbnce++)
    {
     __delay_ms(5);
    }
  }
 INTF=0;
}
 

Wendy

Joined Mar 24, 2008
23,415

Thread Starter

32_d3gr33s

Joined Oct 29, 2011
35
Tracecom,

And I thought I was fast posting a portion of the circuit - nice job. I believe the OP stated he wanted the red to flash three times (blue off during this time), then the blue to flash three times (red off during this time), then repeat.

At least, that was my understanding.
This is what i had in mind. The current set-up isnt bad, but if possible could we switch it to that? if not, i think slowing the red/blue down just a tad would be perfect.


OP,

When you say 9V battery, do you mean a regular 9V rectangular or something like a 9.6V RC battery pack? You won't get a lot of time out of a regular 9V battery and we'll have to better plan how to hook up the LEDs so they don't die when the discharge curve gets below a certain level. In layman's terms, it won't be terribly efficient and you'll need to replace the 9V battery pretty often. Now, if you could fit six or eight AA batteries into the car . . .
I mean just a regular 9v battery. i can run 2 together because i have clips that will hold 2 9 volts, but the AA doesnt seem very do-able, because i dont really have much space in the RC car, other than under the roof. and a bunch of AA batteries visible through the windows woulnt be to appealing. not to mention i have no way of holding them in.
 

Thread Starter

32_d3gr33s

Joined Oct 29, 2011
35
I have been following this thread loosely, only because I'm short on time, otherwise I'd have been following it more in depth and providing my own input, but between my own projects and my insane school/work schedules, I'm really just out of time.

Anyways, the OP had been wondering about using microcontrollers for police style lighting. I thought I'd post a couple examples so that he can see what the coding process looks like. Also, even though it looks incredibly daunting at first, once you understand what the language is saying, it gets way easier to write things. Additionally, it is so much fun to play with the patters by making changes to the software and seeing how it effects the hardware. Picking up microcontrollers and learning to write code (not 100% proficient with it myself) was one of the best things I ever decided to do.

Ok, both examples were written in MPLAB IDE free version for Microchip MCUs. First example is written in assembly language and has multiple flash patterns that can be scrolled through by depressing a momentary switch.

Keep in mind the code isn't as pretty as it could be, it was one of the first pieces of software I wrote, and doesn't take full advantage of what the MCU can do, but it works.

Clipped due to character limit. Also, post 1 of 2.
That actually doesnt look all that complicated. obviously would take a little bit of learning, but once i get it figured out... Where would i go about picking up the materials to do this? what about learning to do it?
 

elec_mech

Joined Nov 12, 2008
1,500
And I still would like to see your solution.
And here it is. Still not 100% sure on the MOSFETs, but I'm pretty sure I'm close. I think this could be an excellent example of a project done both with a uC and discrete logic to let others in the future compare and contrast between the two.

The red and blue LEDs are controlled with the CD4017. I've included the timing diagram from the datasheet with a brief description of what is going on. I tied the clock from the 555 to feed the 4017, so the 555 will control the flash rate of all LEDs, effectively flashing them at the same rate although not in the same sequence. If you need the flash rate different between the red/blue LEDs and the yellow/white LEDs, you can add another identical 555 circuit and adjust VR1 differently to get different flash rates.

Diodes D21-D26 are used to protect the pins of the 4017 from reverse voltage.

I'm going to attempt to build this, if time allows tonight, so I can do some tests on finding the right LED resistor values. A 9V battery's voltage is going to drop over time and since we want the battery to last as long as possible, we need to find a happy medium for brightness, voltage drop, etc. If you have room for two 9V batteries, awesome, just be sure they are connected in parallel (9V output), not series (18V output).

I like programming and have used a little assembly, a little C, and a lot of Basic. Personally, I recommend using a PICAXE with Basic. Assembly is free, but the learning curve will take some time and your code will be longer and thus take more time than either C or Basic. C is easier than assembly, but it still has a decent learning curve in my opinion. Basic is by far the easiest and should take you less time to learn and write code than the other two. PICAXE is relatively inexpensive and I believe the Basic language with it is free - I haven't used PICAXE myself, so I'll have to let Tracecom field that point.
 

Attachments

Top