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

Using the LM1830N with Netduino


  • Please log in to reply
14 replies to this topic

#1 Casmer

Casmer

    Member

  • Members
  • PipPip
  • 22 posts
  • LocationGrant, FL

Posted 26 August 2013 - 06:12 AM

I have made a circuit to detect water level. The circuit is from the datasheet for the LM1830. it drives an LED. What I am wondering is how do it convert this LED to an input on my Netduino? I am missing something very basic about electronics here I think.

I have attached an image of the sample circuit, and the full datasheet.

I just blew out my netduino making a stupid mistake and don't want to fry the next one.

Attached Files



#2 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 26 August 2013 - 06:27 AM

Casmer, first of all be sure to connect the ground of the LM to the ground of the Netduino.

Afterward connect the LM's output (pin 12) to any Netduino input: that's should be enough.

 

However, bear in mind that:

  • you must enable the input's pullup resistor, otherwise there's no way to get a logic "one" voltage on that pin;
  • you may set the pin as an output by mistake and that could lead to an excessive stress for both the pin itself and the LM internal transistor. Thus, I'd suggest to use any low-value resistor (e.g. 100 to 1k Ohms) from the LM's pin 12 and the Netduino I/O pin.

 

At this point you can even travel to the moon.

Cheers


Biggest fault of Netduino? It runs by electricity.

#3 Casmer

Casmer

    Member

  • Members
  • PipPip
  • 22 posts
  • LocationGrant, FL

Posted 26 August 2013 - 06:30 AM

So it will read a 1 when the reference circuit would have turned on the LED, and a 0 when it would have been off? or Vice versa? Looking at the schematic what made that obvious? I am trying to understand why I couldn't tell that.



#4 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 26 August 2013 - 07:14 AM

On the test circuit above, the led will turn on when the transistor (think it as a switch) closes to the ground.

If you remove the led, the transistor will work in the same way, of course. So, when it closes you'll read a "false" in the InputPort in your code.

 

For the same reason, when the transistor opens there's no more "short" to the ground, and it should be something else (that is the pull-up resistor) that ties the pin voltage up to +3.3V (or +5V, whereas applies).

 

Please note that the LM can be powered as much as +16V, but the Netduino can't!

The LM's internal transistor shorting to the ground is a very good solution because won't impose anything but a "short to the ground". That is, the sensor works at +16V and the Netduino at +3.3V, and there's no contraints between these two supplies.

Anyway, take care to either enable the internal Netduino's pullup, or add an external resistor (any ranging 5k to 50k) across the Netduino's input and +3.3V.

 

Have fun!


Biggest fault of Netduino? It runs by electricity.

#5 roguemat

roguemat

    Advanced Member

  • Members
  • PipPipPip
  • 54 posts
  • LocationSouth Africa

Posted 26 August 2013 - 02:34 PM

This isn't an answer to your question, but rather an alternative solution to detecting water level: http://www.ebay.com/...=item5659ebc4c9

These sensors are cheap and work really well with the Netduino or standalone. Although, if you just need to detect water at certain levels this is overkill.


I make Windows Phone stuff for beer money and rent (in order of priority). I've got a blog and am on the Twitter machine.

#6 Casmer

Casmer

    Member

  • Members
  • PipPip
  • 22 posts
  • LocationGrant, FL

Posted 26 August 2013 - 02:48 PM

On the test circuit above, the led will turn on when the transistor (think it as a switch) closes to the ground.

If you remove the led, the transistor will work in the same way, of course. So, when it closes you'll read a "false" in the InputPort in your code.

 

For the same reason, when the transistor opens there's no more "short" to the ground, and it should be something else (that is the pull-up resistor) that ties the pin voltage up to +3.3V (or +5V, whereas applies).

 

Please note that the LM can be powered as much as +16V, but the Netduino can't!

The LM's internal transistor shorting to the ground is a very good solution because won't impose anything but a "short to the ground". That is, the sensor works at +16V and the Netduino at +3.3V, and there's no contraints between these two supplies.

Anyway, take care to either enable the internal Netduino's pullup, or add an external resistor (any ranging 5k to 50k) across the Netduino's input and +3.3V.

 

Have fun!

Thanks that is abundantly clear now that its not 2:30 in the morning! I was looking for a circuit diagram that explains the pull up resistor and pull down resistor. Seeing the circuit diagrams helps me understand more. If I can't find them I will ask that question next. the main schematic of the Netduino Plus 2 doesn't show that, at least not in a way I can understand it. I was actually trying to take the point where the LED was and power a similar transistor circuit and I was moving a wire and hit the 12V power. What I missed in the datasheet is that the LM1380 can run off of 5V that I did not pick up on. I will take that 12 V complete out of the bread board and make sure only the 5V regulated power is used.



#7 Casmer

Casmer

    Member

  • Members
  • PipPip
  • 22 posts
  • LocationGrant, FL

Posted 28 August 2013 - 04:36 AM

Now I have this working except the IO input reads as turning on and off constantly. Not sure what I am doing wrong now. I am using an interrupt and a push button works fine on the input.

this is how the port is configured:

buttonOn2 = new AutoRepeatInputPort(Pins.GPIO_PIN_D8, Port.ResistorMode.PullUp, false);

 

Pin 12 reads -0.237 Volts when connected to the multi meter when the probe is not touching water and it reads 0.095 V when the probe is touching water.

I think maybe pin 12 has AC voltage as one of the reference diagrams has this same pin driving a Speaker if that helps.



#8 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 28 August 2013 - 06:23 AM

Well, AutoRepeatInputPort is something I wrote time ago, but surely not as for this kind of application!

That class is tailored for a pushbutton: imagine it used for incrementing/decrementing a value step-by-step. Instead of clicking many times the button to run over a large variation, the AutoRepeatInputPort leads a virtual-click repetition automatically.

For a sensor that's a nightmare!

 

Anyway, the configuration should be similar:

buttonOn2 = new InputPort(Pins.GPIO_PIN_D8, Port.ResistorMode.PullUp, false);

Now, you should perform these checks:

  • be sure to reliably wire the ground of the sensor to the ground of the Netduino, and do not detach it any more;
  • run the app so that the above code will be executed;
  • detach the sensor (pin 12) from the Netduino pin 8, but always leave the ground connected between the two circuits. Now, place the voltmeter across the Netduino pin 8 and ground: you should read around +3.3V. If that's not, there's probably something related the code. Also take care to choose the right pin.
  • connect back the Netduino pin 8 to the sensor's pin 12: if you have a low-value resistor (any valued from 100 to 1k Ohms is fine), then use that for the connection instead a simple short.
  • with the multimeter check again the voltage as above, across Netduino pin 8 and ground: you should read around 3.3V when the sensor is not active, and roughly 0v when it does.

If everything will succeed, you can go further on writing software!

 

Testing with speaker.

do not connect any coiled/magnetic-based component to the Netduino unless a proper protection circuit. The essence of any magnetic component is to store the energy as magnetic, then discharge it back in the simplest way. It means that when you connect a speaker (which is a coil surroinding a magnet) and you feed energy to it, that energy is actually stored; when you stop to feed, the stored energy will be discharged usually with a high-voltage feedback. That will damage seriously most circuits.

So, don't connect speakers, motors, transformers, relays, etc.

 

Have fun!


Biggest fault of Netduino? It runs by electricity.

#9 Casmer

Casmer

    Member

  • Members
  • PipPip
  • 22 posts
  • LocationGrant, FL

Posted 28 August 2013 - 06:13 PM

Well, AutoRepeatInputPort is something I wrote time ago, but surely not as for this kind of application!

That class is tailored for a pushbutton: imagine it used for incrementing/decrementing a value step-by-step. Instead of clicking many times the button to run over a large variation, the AutoRepeatInputPort leads a virtual-click repetition automatically.

For a sensor that's a nightmare!

 

Anyway, the configuration should be similar:

buttonOn2 = new InputPort(Pins.GPIO_PIN_D8, Port.ResistorMode.PullUp, false);

Now, you should perform these checks:

  • be sure to reliably wire the ground of the sensor to the ground of the Netduino, and do not detach it any more;
  • run the app so that the above code will be executed;
  • detach the sensor (pin 12) from the Netduino pin 8, but always leave the ground connected between the two circuits. Now, place the voltmeter across the Netduino pin 8 and ground: you should read around +3.3V. If that's not, there's probably something related the code. Also take care to choose the right pin.
  • connect back the Netduino pin 8 to the sensor's pin 12: if you have a low-value resistor (any valued from 100 to 1k Ohms is fine), then use that for the connection instead a simple short.
  • with the multimeter check again the voltage as above, across Netduino pin 8 and ground: you should read around 3.3V when the sensor is not active, and roughly 0v when it does.

If everything will succeed, you can go further on writing software!

 

Testing with speaker.

do not connect any coiled/magnetic-based component to the Netduino unless a proper protection circuit. The essence of any magnetic component is to store the energy as magnetic, then discharge it back in the simplest way. It means that when you connect a speaker (which is a coil surroinding a magnet) and you feed energy to it, that energy is actually stored; when you stop to feed, the stored energy will be discharged usually with a high-voltage feedback. That will damage seriously most circuits.

So, don't connect speakers, motors, transformers, relays, etc.

 

Have fun!

I am saying that the reference circuit of this device will drive a speaker/buzzer by simply replacing the LED with a loudspeaker. to me that means the current coming out of the sensor is alternating, as if I remember correctly speakers need alternating current to generate a sound. Though the last time before this project that I really worked with electronics was close to 15 years ago. I was trying to respond to an interrupt, will not using your auto repeat work ok? I would have through press/release would be the same using that class or using the port directly.



#10 Casmer

Casmer

    Member

  • Members
  • PipPip
  • 22 posts
  • LocationGrant, FL

Posted 28 August 2013 - 06:37 PM

Ok, I added a diode as well as the resistor, then in the code for the input port polling I did this:

 

private static DateTime lastTrue = DateTime.Now;

static void buttonOn2Handler()

{

//this check is just to make sure I never have a time over flow ( paranoia or confidence?)

if ((DateTime.Now - lastTrue).Seconds > 600)

lastTrue = DateTime.Now.AddSeconds(-100);

bool data2 = buttonOn2.Read();

if (!data2)

{

if ((!relayState1) )

{

Debug.Print("Water Pressed");

relayState1 = true;

relay1.Write(relayState1);

}

lastTrue = DateTime.Now;

}

else

{

if (relayState1 && ((DateTime.Now - lastTrue).Seconds > 4))

{

 

Debug.Print("Water Release");

relayState1 = false;

relay1.Write(relayState1);

}

 

}

}



#11 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 29 August 2013 - 04:19 AM

Sorry, Casmer, it's my fault! I didn't not check the datasheet, but I referred only to the schematic above.

The circuit you used is for testing, and without smoothing capacitor, will output a square wave, not a continuous signal.

You should consider the schematic at page 6 (bottom), instead. However, the resistor/diode/transistor group depicted at pin 12 is not necessary, and everything we discussed about the interface with the Netduino is still alive.

Cheers


Biggest fault of Netduino? It runs by electricity.

#12 Casmer

Casmer

    Member

  • Members
  • PipPip
  • 22 posts
  • LocationGrant, FL

Posted 29 August 2013 - 02:52 PM

Sorry, Casmer, it's my fault! I didn't not check the datasheet, but I referred only to the schematic above.

The circuit you used is for testing, and without smoothing capacitor, will output a square wave, not a continuous signal.

You should consider the schematic at page 6 (bottom), instead. However, the resistor/diode/transistor group depicted at pin 12 is not necessary, and everything we discussed about the interface with the Netduino is still alive.

Cheers

You are referring to the second transitor for controlling a solenoid? that is what is on page six. Also, how would that create a constant output? does that have to do with out transistors switch on or off that I don't know about? I though it would do the same thing all over again.



#13 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 29 August 2013 - 04:58 PM

Refer to page 6, bottom circuit.

The LM working principle is based on a oscillator. Its output (pin 13) is going though a capacitor to the probe (and pin 10), which acts essentially as a resistor to the ground. The higher is the fluid conductivity, the lower will be the resistance. This phenomena is due by the free ions available in the fluid, so it depends on what's in the fluid itself.

Anyway, on pin 10 there is a pulsing signal, having the same frequency of the reference oscillator. Since the capacitor and the fluid-resistor pattern behaves like a high-pass filter (in the frequency domain), by modifying the fluid-resistance also the amplitude on pin 10 will be related to it.

The "detector" stage acts as a level detector, so that only when the amplitude is above a certain threshold, the signal can flow through this block.

Now we're on pin 9 and the signal is *still* oscillating, but we don't want that: we just need a "stable" signal to reveal the successful detection. That's the way the capacitor on pin 9 is very important: it acts as a pulse smoother, and levels most of the ripple that we don't want.

At this point, the game is over: when the detector is able to flow the signal to pin 9, the cap gets it smoother and the final transistor will be polarized. Since the emitter (pin 12) is to the ground, the transistor polarization means that the pin 12 is tied low as well.

Hereinafter, the Netduino wiring is as we discussed above: nothing has changed.

 

My initial error was about *HOW* the LM yields the detection: I believed on a simple "stable" output, but it wasn't. Without the smoothing cap, the output is toggled at the same frequency of the reference oscillator.

 

Tell me whether that's clear enough.

Cheers


Biggest fault of Netduino? It runs by electricity.

#14 Casmer

Casmer

    Member

  • Members
  • PipPip
  • 22 posts
  • LocationGrant, FL

Posted 29 August 2013 - 08:41 PM

Refer to page 6, bottom circuit.

The LM working principle is based on a oscillator. Its output (pin 13) is going though a capacitor to the probe (and pin 10), which acts essentially as a resistor to the ground. The higher is the fluid conductivity, the lower will be the resistance. This phenomena is due by the free ions available in the fluid, so it depends on what's in the fluid itself.

Anyway, on pin 10 there is a pulsing signal, having the same frequency of the reference oscillator. Since the capacitor and the fluid-resistor pattern behaves like a high-pass filter (in the frequency domain), by modifying the fluid-resistance also the amplitude on pin 10 will be related to it.

The "detector" stage acts as a level detector, so that only when the amplitude is above a certain threshold, the signal can flow through this block.

Now we're on pin 9 and the signal is *still* oscillating, but we don't want that: we just need a "stable" signal to reveal the successful detection. That's the way the capacitor on pin 9 is very important: it acts as a pulse smoother, and levels most of the ripple that we don't want.

At this point, the game is over: when the detector is able to flow the signal to pin 9, the cap gets it smoother and the final transistor will be polarized. Since the emitter (pin 12) is to the ground, the transistor polarization means that the pin 12 is tied low as well.

Hereinafter, the Netduino wiring is as we discussed above: nothing has changed.

 

My initial error was about *HOW* the LM yields the detection: I believed on a simple "stable" output, but it wasn't. Without the smoothing cap, the output is toggled at the same frequency of the reference oscillator.

 

Tell me whether that's clear enough.

Cheers

I just plain did not see the Capacitor on pin 9. How close to 20uF do you think I have to get for it to work? thanks again!



#15 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 30 August 2013 - 04:34 AM

That's interesting!

A quick calculation yields a pretty low value (about 1nF), but the datasheet suggests a totally different order of magnitude. Well, if you have some cap to test, the very best thing is to evaluate several values. Consider that you may experience the "best value" relatively to the actual fluid you'll work on. For example, try a 100nF, 1uF and 10uF. Note that a 10uF (and possibily the 1uF as well) are electrolytic, so they are polarized: take care to wire the negative lead to the ground, and the positive to pin 9. For a 100nF cap there's no polarization at all.

 

A word about the software.

I'd avoid to use the interrupt as detector for the signal. That's because a relatively high frequency trigger will easily hang the Netduino. Consider that the LM's oscillator generates about 6kHz, and you may experience some critical point: especially whereas the smoothing cap (pin 9) is low.

I mean that I'd favor a 10uF cap than a 100nF one, even they *seem* to behave similarly. That should prevent residual waves on the pin 12, which lead a lot of useless (and dangerous) triggers to the software.

 

Hope it helps.


Biggest fault of Netduino? It runs by electricity.




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.