+ Post New Thread
Results 1 to 14 of 14
  1. #1
    Newbie level 4
    Points: 42, Level: 1

    Join Date
    Jan 2020
    Posts
    7
    Helped
    0 / 0
    Points
    42
    Level
    1

    Control a switch by microcontroller 16F877a

    Hello everyone,
    I have this project where I should put a switch between a powerbank and a phone, and I should be able to control it by a microcontroller.
    So I found that a reed relay and a transistor is what I need but don"t have any refrences or idea of how to do it.
    So any help would be very appreciated. thank you

  2. #2
    Super Moderator
    Points: 80,975, Level: 69
    Achievements:
    7 years registered
    Awards:
    Most Frequent Poster 3rd Helpful Member

    Join Date
    Apr 2014
    Posts
    16,421
    Helped
    3728 / 3728
    Points
    80,975
    Level
    69

    Re: Control a switch by microcontroller 16F877a

    Hi,

    Millions of schematics for a simple transistor - relay - control are available in the internet.
    Every detail of design is explained may thousand times.

    I wonder how much time you spent to find a solution on your own.

    Klaus
    Please donīt contact me via PM, because there is no time to respond to them. No friend requests. Thank you.



    •   AltAdvertisement

        
       

  3. #3
    Newbie level 4
    Points: 42, Level: 1

    Join Date
    Jan 2020
    Posts
    7
    Helped
    0 / 0
    Points
    42
    Level
    1

    Re: Control a switch by microcontroller 16F877a

    Thank you Klaus for your reply.
    the reason I posted this is to get some help, to discuss if what Im doing is right or not, or if there is a better way, to get opinions and help of other people with much more expertise than me since Im kinda new to this.
    and yes it took me sometime to know that I should use a relay.



  4. #4
    Advanced Member level 2
    Points: 2,862, Level: 12

    Join Date
    Jan 2019
    Posts
    523
    Helped
    136 / 136
    Points
    2,862
    Level
    12

    Re: Control a switch by microcontroller 16F877a

    pick a transistor whose CE or DS voltage is about twice the voltage of the powerbank
    and whose Ic or Id is about twice what you expect the current in the relay coil to be.

    pick a relay whose coli voltage is consistent with the powerbank
    and whose contacts are rated for the about twice the voltage of the power bank
    and whose current is about twice what the powerbank will provide to the load.

    what is the voltage of the powerbank?
    what current does the phone draw?
    sketch the circuit, label the components, specify the manufacturer and the manufacturer's part number
    write down how you think it works, then post all of that and ask your questions

    please provide specific information about the porblem and your solution,
    then the forum can help

    the forum provides help, it doesn't do your work for you


    1 members found this post helpful.

  5. #5
    Newbie level 4
    Points: 42, Level: 1

    Join Date
    Jan 2020
    Posts
    7
    Helped
    0 / 0
    Points
    42
    Level
    1

    Re: Control a switch by microcontroller 16F877a

    thank you very much for the valuable informations ! And yes I do agree, I just needed directions for the path I should follow to make this work.
    thank you so much again wwfeldman



  6. #6
    Newbie level 4
    Points: 42, Level: 1

    Join Date
    Jan 2020
    Posts
    7
    Helped
    0 / 0
    Points
    42
    Level
    1

    Re: Control a switch by microcontroller 16F877a

    Hello again,

    as for what u've told me to do, here is where Im at for now :
    Click image for larger version. 

Name:	Schema.png 
Views:	12 
Size:	388.5 KB 
ID:	157514

    the simulation is working, but I don't know if it's going to work perfectly in real life.

    So the Powerbank voltage is 3.7V, and the phone draw a current of 1.5A max

    - as for the transistor, I choosed BC547.
    - a 5V relay

    is it a good choice ?



    •   AltAdvertisement

        
       

  7. #7
    Super Moderator
    Points: 80,975, Level: 69
    Achievements:
    7 years registered
    Awards:
    Most Frequent Poster 3rd Helpful Member

    Join Date
    Apr 2014
    Posts
    16,421
    Helped
    3728 / 3728
    Points
    80,975
    Level
    69

    Re: Control a switch by microcontroller 16F877a

    Hi,


    Values of capacitors for the XTAL need to be smaller by a factor of about 1.000.000.

    Each bjt base needs a current limiting resistor.
    Each LED needs a current limiting resistor.

    What's the idea behind the GND symbol at the relay contact?
    What's the expected relay coil current?

    Klaus
    Please donīt contact me via PM, because there is no time to respond to them. No friend requests. Thank you.



  8. #8
    Advanced Member level 3
    Points: 3,592, Level: 14
    baileychic's Avatar
    Join Date
    Aug 2017
    Posts
    719
    Helped
    54 / 54
    Points
    3,592
    Level
    14

    Re: Control a switch by microcontroller 16F877a

    Your Battery +ve is shorting to GND when relay is Off.



  9. #9
    Newbie level 4
    Points: 42, Level: 1

    Join Date
    Jan 2020
    Posts
    7
    Helped
    0 / 0
    Points
    42
    Level
    1

    Re: Control a switch by microcontroller 16F877a

    Thank you Klaus and baileychic for your reply.
    Just out of curiosity, why the values of the capacitors of the XTAL should be smaller ? and indeed, I should've add the resistors for current limitation.
    As for the relay coil current, I have a 5 volt rating and the coil resistance is 69Ω so the coil current is 5 / 69 = 72.4 mA. why ?
    For the GND at the relay contact, the simulation didn't work without it. my battery is supposed to be a Powerbank.

    thank you again guys for your time.



  10. #10
    Advanced Member level 2
    Points: 2,862, Level: 12

    Join Date
    Jan 2019
    Posts
    523
    Helped
    136 / 136
    Points
    2,862
    Level
    12

    Re: Control a switch by microcontroller 16F877a

    the ground on the off side of the relay is required so that the computer simulation has a reference
    voltage from which to determine all the voltages in that branch of the circuit.

    the ground connection could be anywhere in the branch.

    does the simulation activate the relay when Q1 is on?
    does the LED TT light up?

    i'm thinking it doesn't because when the relay is activated, the "switch" is connected the other way,
    and there is no reference in the PB branch of the circuit and the simulation would have a problem.



  11. #11
    Super Moderator
    Points: 80,975, Level: 69
    Achievements:
    7 years registered
    Awards:
    Most Frequent Poster 3rd Helpful Member

    Join Date
    Apr 2014
    Posts
    16,421
    Helped
    3728 / 3728
    Points
    80,975
    Level
    69

    Re: Control a switch by microcontroller 16F877a

    Hi,

    Just out of curiosity, why the values of the capacitors of the XTAL should be smaller ? and indeed, I should've add the resistors for current limitation.
    As for the relay coil current, I have a 5 volt rating and the coil resistance is 69Ω so the coil current is 5 / 69 = 72.4 mA. why ?
    For the GND at the relay contact, the simulation didn't work without it. my battery is supposed to be a Powerbank.
    This are more than basic questions.
    * Generally you need to know what "voltage" and "current" means and how to calculate it.
    * Then you need to read datasheets and keep on datasheet informations. Every one needs to do this, even we professionals. Every day.

    -----------------------------
    XTAL capacitors: are given in the XTAL datasheet. How to calculate them: in the according application notes.
    And there are many millions of example circuits showing useful values.

    BJT base resistors. Many online calculators are available. Many millions of example circuits showing useful values.
    Coil current determines BJT collector current --> this determines useful BJT base current --> this determines useful base resistor values.

    LED currents and voltages are given in it's datasheet. This determines the current limiting resistor values.
    Many millions of example circuits showing useful values.

    Why don't you use the internet? It gives all informations you need. Every datasheet, application note, online calculators, design examples....
    For every tiny information you may find online tutorials, often even videos.
    Use them ... this all is for free.

    Imagine....more thirty years ago, when I learned electronics..there was no internet. This really was hard time.
    Hard time to get informations like datasheets, electroncis courses, there even was no library around with according books.
    Many trials and fails ... often with ugly smelling smoke.
    Luck you - you have internet now. So use it.

    Also you have the simulation tool. It's easy to measure (LED, BJT, battery...) current ... without smoke and fire and explosions.

    Klaus
    Please donīt contact me via PM, because there is no time to respond to them. No friend requests. Thank you.



  12. #12
    Newbie level 4
    Points: 42, Level: 1

    Join Date
    Jan 2020
    Posts
    7
    Helped
    0 / 0
    Points
    42
    Level
    1

    Re: Control a switch by microcontroller 16F877a

    Thank you for your replay.
    wwfeldman yes the simulation is working perfectly fine.
    Klaus, thank you for the valuable informations. I will stop asking questions in here.
    Just one final question, do you think that since this is on battery, I can just use a mosfet instead of a relay to avoid the cost of powering the coil while on ?
    could a MOSFET do the work ?



    •   AltAdvertisement

        
       

  13. #13
    Advanced Member level 2
    Points: 2,862, Level: 12

    Join Date
    Jan 2019
    Posts
    523
    Helped
    136 / 136
    Points
    2,862
    Level
    12

    Re: Control a switch by microcontroller 16F877a

    if the voltage rating of the transistor (FET or BJT) is about 1.5 to 2 times
    the voltage of the supply it will swtch, and the current rating of the
    transistor (FET or BJT) is also 1.5 to 2 times the current you expect to
    carry, then it should work.

    you should add a resistor in series with the LED.
    resistance = (source voltage - voltage drop across ON LED) / desired current in LED



  14. #14
    Newbie level 4
    Points: 42, Level: 1

    Join Date
    Jan 2020
    Posts
    7
    Helped
    0 / 0
    Points
    42
    Level
    1

    Re: Control a switch by microcontroller 16F877a

    Okey great !! thank you so much. I will do it correctly this time and let you know.
    Thank you again



--[[ ]]--