relay control

Discussion in 'The Projects Forum' started by barneydog, Feb 1, 2010.

  1. barneydog

    Thread Starter New Member

    Dec 22, 2009
    16
    0
    Hi,

    i havent been near electronics since leaving school, but recently i find myself back involved in it, after purchasing a RC truck...

    So far i have managed to build myself an LED chaser using plans off the net...

    My next project i have hunted around for, without much luck or I'm just misunderstanding what the websites are telling me.

    What i want to do, is have 3 relays. a push of a button makes 1st relay work, 2nd push makes 1+2 relays work, push 3rd time brings 1+2+3 working. 4th press of the button switches all relays off.

    Ideally i would like to use a pic to do this, as im trying to learn how to write the code for them.

    any advice will be taken and used, as im feeling very stuck here.

    thanks

    James
     
  2. retched

    AAC Fanatic!

    Dec 5, 2009
    5,201
    312
    With a pic, you could easily achieve this. You would set an array that would cycle through with the button press.

    i.e.:

    Code ( (Unknown Language)):
    1. array(1,2,3,0)
    2. if array = 1 pin 1 goes high
    3. if array = 2 pin 1 goes high and pin 2 goes high
    4. if array = 3 pin 1 goes high and pin 2 and pin 3
    5. if array = 0 pin 1 pin 2 pin 3 all low
    6. on button press advance array
    7. (not actual code)
    in this flow, the relays would be logic level and need to be attached to the corresponding pin. If you needed higher voltage for the relay coil, you would use a transistor. (be sure to protect the pic from the emf of the coil)
     
  3. barneydog

    Thread Starter New Member

    Dec 22, 2009
    16
    0
    thanks for the response.

    i understand what your saying. do you have any sample code i code view to complete this ?
     
  4. barneydog

    Thread Starter New Member

    Dec 22, 2009
    16
    0
    anyone help please?

    or some good sites i can learn to program the pic from
     
  5. retched

    AAC Fanatic!

    Dec 5, 2009
    5,201
    312
    http://www.gooligum.com.au/tutorials.html
    Here is a very good set of PIC tutorials with C and ASC. They guide you STEP-BY-STEP through programing, using the development software and where to get it all.
     
  6. barneydog

    Thread Starter New Member

    Dec 22, 2009
    16
    0
    brilliant thank you...

    reading it now and surprisingly for something like this its really interesting...:D
     
  7. retched

    AAC Fanatic!

    Dec 5, 2009
    5,201
    312
    Yes, it was a great find for me. He really can take someone from know nothing to understanding rather quickly. Very good teacher.

    Remember to pass it on to others. Once you have a good grasp of it, you will see others that are in the same boat you are in now.

    Gooligum is a great PIC tutorial resource. Teaches PIC basics and advanced topics from scratch. Also gives you the option to learn from C or assembler. That is what I found very helpful. Alot of tutorial writers stick to one language. This shows the difference and explains why each one is used. I like the tables that show final compiled file size differences between C and ASM. Its also a good way to see how things done in C translate to ASM.
     
  8. barneydog

    Thread Starter New Member

    Dec 22, 2009
    16
    0
    i have now read the introduction, all of base line pics, and starting on mid range.... brain is feeling rather fried...

    so as im going to use the 16F628A or the 16F88, im taking a break and going to compare the datasheets from the pics he used to the ones i have, and try writting some of the programs up and making a personal disco of flashing leds.

    if i dont fall asleep first :eek:

    i will certainly share that with everyone...

    I do have one last question (well for now its the last)

    At college i studied Pascal, Cobol and DB6 long time ago.....and since then i have self taught PHP, HTML, and Mysql..

    keeping with the formats i have learnt, which will be the best language for me to go into..... ASM looks the more obvious one to learn and practice, but its going against every command i have ever learnt in the way it wants things written. Maybe this is just from lack of understanding.

    What would you recommend a good starting point? and what software being i only have these pics available.

    16F628A

    16F88

    16F722

    thanks
     
    Last edited: Feb 4, 2010
  9. BMorse

    Senior Member

    Sep 26, 2009
    2,675
    234
    a 4017 decade counter, a few 1n4148 diodes and a switch would accomplish this task for you, it is so simple, a microcontroller is way overkill..... of course this is a quick circuit, you may need to debounce the switch, and add some transistors (or FETs) to the outputs to handle the relay's load.....

    With this circuit, when powered up, the only output that will be on is output Q0, so when you press the switch, Q1 will turn high and all others will be off, so only relay 1 will be on, when the switch is pressed again, the 1st relay will still be on, but also the second one will trigger, and so on.... when the switch is pressed for the 4th time, the output of the 4017 Q4, will turn high which in turn will reset the 4017.... so the sequence can then be started again by pressing the switch.....
    4017 realy control.png
     
    Last edited: Feb 4, 2010
  10. barneydog

    Thread Starter New Member

    Dec 22, 2009
    16
    0
    thanks lol


    i had it that way before (kind of)... im trying to be different now and learn something new.

    :D
     
  11. retched

    AAC Fanatic!

    Dec 5, 2009
    5,201
    312
    Stick with C. ASM is a rough language. Un-Learning can be difficult. It used to be the only option when memory was so small, but now, you can fit much larger programs on a PIC. Learning C will also help in application programing. If you build a project to sense things around you then you want your PC to do things with the data, C language can be used for both. ASM makes no sense with PC design these days. (opine)
     
Loading...