How can i connect the water level switch to microcontroller ?

Discussion in 'General Electronics Chat' started by Rawankhader, Sep 22, 2017.

  1. Rawankhader

    Thread Starter New Member

    Sep 22, 2017
    28
    1
    Hi all,

    I need to use the following water level switch .


    80f64752-1e4a-47f4-87fe-c23915aa110c.jpg



    Description:

    • Product Name : Float Switch;Max Contact Rating : Max Contact Rating;10W : 10W;Max Switching Voltage : 100V DC
    • Max Switching Current : 0.5A;Max Breakdown Voltage : 220V DC;Max Carry Current : 1.0A;Max Contact Resistance : 100mΩ
    • Temperature Rating : -10 ~ +60 °C / +85 °C;Float Ball Material : PP;Float Body Material : PP;Float Ball Size(Approx) : 24 x 17mm /0.94" x 0.7"(L*D)
    • Thread Dia(Approx) : 16mm/3/8" PT;Hex Nut Diameter : 23mm /0.9";Body Length : 90mm/3.5";Cable Length : 39cm / 15.3"
    • Color : Black;Net Weight : 22g;

    I want to use 10k pull up resistor with the switch to connect it with the microcontroller .

    The distance between the tank(switch) and the microcontroller 15 m.

    Should I modify the connection ?


    Thank you .
     
  2. MaxHeadRoom

    Expert

    Jul 18, 2013
    16,120
    4,718
    That should work ok IMO, it may be wise to use a grounded shield for the switch conductors.
    Also maybe debounce the input at the micro.
    Max.
     
    Rawankhader likes this.
  3. MrChips

    Moderator

    Oct 2, 2009
    17,044
    5,271
    What microcontroller?
    What power is powering the microcontroller?
    How much voltage and current do you have available from the power supply that is supplying the microcontroller?

    A 10kΩ pull-up might work but it will be susceptible to noise pickup.
    A 220Ω ½W resistor would be a better choice.

    And you may want to put a filter capacitor across the input of the microcontroller,

    and maybe a MOV while you're at it.

    Better yet, use an opto-coupler/isolator.
     
    Rawankhader likes this.
  4. MaxHeadRoom

    Expert

    Jul 18, 2013
    16,120
    4,718
    It appears to be a simple contact closure switch, what micro are you using?
    I prefer schmitt trigger input for this application if it has one.
    Max.
     
    Rawankhader likes this.
  5. MrChips

    Moderator

    Oct 2, 2009
    17,044
    5,271
    TS is asking for 15m of cabling which I can only assume will be in an industrial environment.
     
    Rawankhader likes this.
  6. MaxHeadRoom

    Expert

    Jul 18, 2013
    16,120
    4,718
    Hence the grounded shielding suggestion.;)
    Max.
     
    Rawankhader likes this.
  7. Rawankhader

    Thread Starter New Member

    Sep 22, 2017
    28
    1
    I use pic16f877a ..
    12v 1A power supply with step down buck converter
     
  8. MrChips

    Moderator

    Oct 2, 2009
    17,044
    5,271
    Hence my suggestion of 20mA current loop into an opto-isolator.
     
    Rawankhader likes this.
  9. MrChips

    Moderator

    Oct 2, 2009
    17,044
    5,271
    Use a 620Ω ½W resistor in series with an opto-isolator driven from the 12V line.
    Then use a 2k-10k pullup on the receiver of the opto-isolator into the PIC input.
     
    Rawankhader likes this.
  10. MaxHeadRoom

    Expert

    Jul 18, 2013
    16,120
    4,718
    Personally I would test the simple input first, you can always go to plan B and add another option if needed.
    Max.
     
    Rawankhader likes this.
  11. MrChips

    Moderator

    Oct 2, 2009
    17,044
    5,271
    Oh, Max. Strange hearing that coming from an industrial CNC guy.;)
    One power spike and he is going to fry his PIC.
     
    Rawankhader likes this.
  12. Rawankhader

    Thread Starter New Member

    Sep 22, 2017
    28
    1
    You mean like this ..
    20170922_175958.jpg
     
  13. MrChips

    Moderator

    Oct 2, 2009
    17,044
    5,271
    Looks good. The switch should go on the GND leg for safety.
     
    Rawankhader likes this.
  14. Rawankhader

    Thread Starter New Member

    Sep 22, 2017
    28
    1
    20170922_180603.jpg
    Like this ?

    Why we used opto ?

    Should the opto be close to pic or to the switch ?

    Regards ;)
     
  15. MrChips

    Moderator

    Oct 2, 2009
    17,044
    5,271
    The 620Ω value is not carved in stone. Anything from 470Ω to 1kΩ will work fine.

    Why opto?
    The objective is to keep EMI away from your PIC input. You want the opto close to the PIC.

    Water switch = = = = 15m cable = = = = opto / / PIC

    Any high voltage spike picked up on 15m cable does not jump across the opto-isolator.
     
    Rawankhader likes this.
  16. Rawankhader

    Thread Starter New Member

    Sep 22, 2017
    28
    1
    Thank you :)

    Should I denounce the switch or using the opto enough ?

    if I use 9v ,7v or 15 v power supply instead of 12v should I modify the circuit ,)
     
    Last edited: Sep 22, 2017
  17. MrChips

    Moderator

    Oct 2, 2009
    17,044
    5,271
    If you just want to read the status of the water level then you don't need to debounce the switch.
     
    Rawankhader likes this.
  18. Rawankhader

    Thread Starter New Member

    Sep 22, 2017
    28
    1
    And if I use 9v ,7v or 15 v power supply instead of 12v should I modify the circuit ,)
     
  19. MrChips

    Moderator

    Oct 2, 2009
    17,044
    5,271
    When you select the opto-isolator, check the data sheet for the max current allowed on the LED. You don't want to exceed the max current.

    With 15V supply , 680Ω series resistor would give about 20mA.
    You have a lot of leeway with anything from 680Ω to 1000Ω for any supply voltage from 7V to 15V.
     
    Rawankhader likes this.
  20. Rawankhader

    Thread Starter New Member

    Sep 22, 2017
    28
    1
    Thank you for your appreciated effort ;)
     
Loading...