element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Raspberry Pi
  • Products
  • More
Raspberry Pi
Raspberry Pi Forum Programming- Detecting Current Through Circuit
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Raspberry Pi to participate - click to join for free!
Featured Articles
Announcing Pi
Technical Specifications
Raspberry Pi FAQs
Win a Pi
Raspberry Pi Wishlist
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Suggested Answer
  • Replies 6 replies
  • Answers 2 answers
  • Subscribers 665 subscribers
  • Views 862 views
  • Users 0 members are here
  • programming
  • raspberry_pi
  • raspberry-pi
  • raspberrypi
  • raspberry-pi-2
  • beginners
Related

Programming- Detecting Current Through Circuit

Former Member
Former Member over 10 years ago

Hi,

 

I am a very new beginner to the Raspberry Pi, and I am wondering how I can programmatically detect if there is a current flowing through the circuit I built, connected to my Raspberry Pi 2 Model B. My circuit consists of a wire connected to the 3.3V volt pin on the GPIO (PIN #01), which is connected to a magnetic door switch on the breadboard, which then connects to a ground pin (PIN #06) on the GPIO. When the switch is open, the circuit is incomplete, and thus there is no current flowing through it, and vice versa when the switch is closed. Is there any way to programmatically detect if a current is flowing through the circuit? Please ask if you need more information.

 

Thanks a lot for your help.

  • Sign in to reply
  • Cancel
  • Robert Peter Oakes
    0 Robert Peter Oakes over 10 years ago

    simply put, are you asking if there is a way to detect if the switch is open or closed ?

     

    I don't have time to draw a diagram but it is simple to describe

     

    A resistor from 3v3 of the PI to one end of the switch (10K Ohms should do), then the other end of the switch goes to ground (0V) on the PI.

    The junction of the resistor and the switch goes to an input pin of the PI

     

    when the switch is closed then there will be 0V on the input (Logic 0), when the switch is open then 3v3 will be on the input (Logic 1)

     

    word of caution, this will work on the breadboard and most lightly when at the end of a long wire too but it will be susceptible to noise and spikes induced in the wire could possibly damage the GPIO on the PI

     

    Using an opto isolator would be better for the final solution, see this post of mine for details:- Sense BIG things with your Launchpad or Arduino, OPTO Isolated inputs.

     

    it refers to Arduinos but the exact same solution will work for a PI

     

    Hope it helps

    Peter

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
  • Former Member
    0 Former Member over 10 years ago in reply to Robert Peter Oakes

    Ok thanks a lot for taking the time to answer my question, I really appreciate it! These tips will really help me!

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 10 years ago in reply to Former Member

    Remember, you will need a short Python script to do all of this.  As I told someone else on another thread, past issues of The MagPi magazine give great examples to follow.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
  • Former Member
    0 Former Member over 10 years ago in reply to Former Member

    Ok thanks a lot, I'll be sure to check out some MagPi issues!

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • clem57
    0 clem57 over 10 years ago

    Why not use an inductance from one higher voltage circuit to another lower voltage circuit and simple detect the high as a one. Better yet, send the detection to an interrupt and not bother writing code  except for the interrupt. Robert Peter Oakes would you agree?

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 10 years ago in reply to clem57

    Yeah thanks, that might work!

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube