Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

Inductive sensor input problem


  • Please log in to reply
11 replies to this topic

#1 Kristoffer

Kristoffer

    Advanced Member

  • Members
  • PipPipPip
  • 37 posts

Posted 05 June 2012 - 01:03 PM

Hi

I got an Inductive Proximity Sensor (https://www.mysick.c...ProductID=51476), which I'd like to read the output from with my Netduino.

It's a DC 3-wire PNP NO and I give it 24V.

See attachment for the setup.

The censor seems to work fine, when triggered it gives 24V in output and 0V when not triggered.

I've made a voltage divider which brings the sensor output down to ca. 4V and my multimeter confirms that.

But I can't read that value in Netduino, this little program outputs only "true"

public static void Main()
{
     var ip = new InputPort(Pins.GPIO_PIN_D1, true, Port.ResistorMode.PullUp);
     while (true)
     {
          Debug.Print("ip.Read() = " + ip.Read());
          Thread.Sleep(1000);
     }
}

I'm definitely not an electronic master mind, so any help with my setup is appreciated.

Thank you
Kristoffer

EDIT: attached file, sorry!

Attached Files



#2 Coding Smackdown

Coding Smackdown

    Advanced Member

  • Members
  • PipPipPip
  • 78 posts
  • LocationLewisville, TX USA

Posted 05 June 2012 - 01:09 PM

Kristoffer, By default the Digital IO pins only return a True for High (3.3V) or False for Low (0V). If you want to read varying degrees of voltage you'll need to use one of the Analog IO Pins. These will return a voltage between 0 and 3.3V that you could then use to determine the proximity from the device. There are a lot of examples in the forums as well in several of the books on Netduino to help get you started. Good Luck and keep us posted on your progress.
Brewing Award Winning Beer with a Netduino!
http://diybrewery.com

#3 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 05 June 2012 - 02:01 PM

The censor seems to work fine, when triggered it gives 24V in output and 0V when not triggered.

I've made a voltage divider which brings the sensor output down to ca. 4V and my multimeter confirms that.

So it's or 4V or 0V, nothing in between? The digital input pins are 5V tolerant and should measure this, but your code contains a small issue to register that:
var ip = new InputPort(Pins.GPIO_PIN_D1, true, Port.ResistorMode.PullUp);
// Try this:
var ip = new InputPort(Pins.GPIO_PIN_D1, true, ResistorModes.Disabled);

"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#4 Kristoffer

Kristoffer

    Advanced Member

  • Members
  • PipPipPip
  • 37 posts

Posted 05 June 2012 - 07:24 PM

... If you want to read varying degrees of voltage you'll need to use one of the Analog IO Pins....

My goal is to receive a high signal so I give it 4.2V to a digital pin, that should be enough to give a high signal, as I understand the analog pins can only handle max. 3.3V input? So a digital pin and that voltage should be fine.

Changing to this
var ip = new InputPort(Pins.GPIO_PIN_D1, true, ResistorModes.Disabled);
gives me randomly true and false signals no matter what state the sensor is in :(

However, I noticed one thing, the voltage between the volt out of the voltage divider and the ground on the 24V power supply is 4.2V when sensor is triggered, but the voltage is only 2.8 between volt out of voltage divider and ground on Netduino, see attachment (Inductive sensor Netduino setup2.png)

So this is where I'm lost, what is ground? should I just try to turn up the output volt of the voltage divider to get +3.3V between Netduino Ground and input voltage (output voltage of voltage divider).

Kristoffer

Attached Files



#5 Coding Smackdown

Coding Smackdown

    Advanced Member

  • Members
  • PipPipPip
  • 78 posts
  • LocationLewisville, TX USA

Posted 05 June 2012 - 07:36 PM

If I remember correctly, The Netduino will see anything higher than 1V as True and this might be where your trouble is. Can you configure your voltage divider such that when the sensor is not triggered your below 1V? Guys, can you help me out with what the true voltage threshold is for On vs. Off on the digital ports?
Brewing Award Winning Beer with a Netduino!
http://diybrewery.com

#6 Kristoffer

Kristoffer

    Advanced Member

  • Members
  • PipPipPip
  • 37 posts

Posted 05 June 2012 - 07:46 PM

If I remember correctly, The Netduino will see anything higher than 1V as True and this might be where your trouble is

yes, that might be the problem, but how would I configure the Voltage provider? I've tried with a transistor without luck.

At the moment I'm trying to read up on transistors, they might help.

#7 CW2

CW2

    Advanced Member

  • Members
  • PipPipPip
  • 1592 posts
  • LocationCzech Republic

Posted 05 June 2012 - 07:52 PM

So this is where I'm lost, what is ground?

Connect the battery minus terminal with Netduino ground.

#8 Kristoffer

Kristoffer

    Advanced Member

  • Members
  • PipPipPip
  • 37 posts

Posted 05 June 2012 - 07:59 PM

Connect the battery minus terminal with Netduino ground.

Bingo! :)


But why? I just don't get that ground thing, I think I must read more about basic electronics.

Thank you very much.

#9 CW2

CW2

    Advanced Member

  • Members
  • PipPipPip
  • 1592 posts
  • LocationCzech Republic

Posted 05 June 2012 - 09:07 PM

The ground is basically a zero voltage reference. The 'trick' in your particular case is that the power supply in your PC, which powers Netduino, has a transformer which isolates it from the 24 V power supply (which probably has transformer too (*)). So you have two circuits that do not share the zero voltage reference, there is no relation between the voltages measured in those circuits (because each has its own local ground). By connecting those grounds together, you create a single reference point to measure the voltage against. (*) The same applies for batteries, a battery-powered circuit is isolated too.

#10 Kristoffer

Kristoffer

    Advanced Member

  • Members
  • PipPipPip
  • 37 posts

Posted 05 June 2012 - 09:46 PM

Ok, that makes sense, I've done this in other setups I've made out of examples, but this time I decided only to do something if I could explain it to myself. I learned something today :) , thanks again.

#11 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 07 June 2012 - 05:35 AM

@Kristoffer: Mr. John Smith is going to measure some parts (pretty long), using a normal tape measure. He's helped by another friend, let's call her Mrs. Jane Brown. However, they don't see each other, and John holds a tape edge, while Jane holds the other. John shout his reading: "This is 9.4m long!" Upon this statement, could you say that a certain part is 9.4m long, *without* actually knowing Jane placed her tape edge? As CW2 writes, the "ground" is a strong reference. As our *real* ground is the reference for heights. Everest is 8.8km high...respect to what? Maybe to the Philippines groove? Maybe to the Earth center? Too hard and too impractical. The reference is widely considered as the sea level. Finally, about the voltage. "This point is at 10 V" it means nothing. The correct statement is "this point has a voltage drop (i.e. potential difference) of 10 V respect to the commong ground (which is conventionally at 0 V". Hope it helps. Cheers
Biggest fault of Netduino? It runs by electricity.

#12 Kristoffer

Kristoffer

    Advanced Member

  • Members
  • PipPipPip
  • 37 posts

Posted 23 July 2012 - 02:07 PM

Hi Mario I didn't see your great explanation until now, but thank you for making it clear :) Kristoffer




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.