Netduino Pull up and Pull down Resistor

The idea of a pull up and pull down resistor initially confused me. After reading around the web a bit I found a description that helped me. Pull up and pull down resistors are used when you have something on your board that is not connected between the Vcc and ground (this is also known as an open circuit). Say for example when we wire up a motion sensor to our circuit, there will be a period of time when it is an open circuit or open collector. Whilst something is not connected directly between Vcc and ground it is susceptible to external electrical noise – which means you might get random erratic readings. For this reason – we use the pull up or pull down resistor.

Pull Up Resistor Example on the Netduino

The pull up resistor will make the input read as high/Vcc and when triggered go low to 0/ground.

Pull Up – Not Connected

Here we have the input port d0 being pulled up to Vcc by the 10k resistor. If we didn’t have the resistor you might get the event handler being randomly fired by electric fluctuations in the circuit.

Pull Up – Connected

Now when we complete the circuit by connecting to ground, we will fire the event handler. Our pin was being held at Vcc (3.3v) and now will be pulled to ground (0v). So our second parameter in the event handler will read as a low of 0.

Pull Up – Source Code

using System;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware;
using SecretLabs.NETMF.Hardware.NetduinoPlus;

namespace _3_Digital_Input
{
    public class Program
    {
        public static void Main()
        {
            InterruptPort input = new InterruptPort(Pins.GPIO_PIN_D0, true, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeLow);
            input.OnInterrupt += new NativeEventHandler(input_OnInterrupt);

            Thread.Sleep(Timeout.Infinite);
        }

        static void input_OnInterrupt(uint data1, uint data2, DateTime time)
        {
            string s = "";
        }
    }
}

Pull Down Resistor Example on the Netduino

The pull down resistor will make the input read as 0. When it is triggered it will go high to Vcc (3.3v).

Pull Down – Not Connected

Here we now are connected via the 10k ohm resistor to ground, bringing the pin to 0v.

Pull Down – Connected

When I complete the circuit the event handler fires. The pin was being held at 0v and now has been pulled high to 3.3v. If you breakpoint on the event handler and inspect the second parameter (data2) you should see the value come in as 1.

Pull Down – Source Code

using System;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware;
using SecretLabs.NETMF.Hardware.NetduinoPlus;

namespace _3_Digital_Input
{
    public class Program
    {
        public static void Main()
        {
            InterruptPort input = new InterruptPort(Pins.GPIO_PIN_D0, true, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeHigh);
            input.OnInterrupt += new NativeEventHandler(input_OnInterrupt);

            Thread.Sleep(Timeout.Infinite);
        }

        static void input_OnInterrupt(uint data1, uint data2, DateTime time)
        {
            string s = "";
        }
    }
}

Side note: The Netduino does also have an inbuilt Pull up resistor that you can turn on and off by the software. This is an enumeration that you can see as one of the parameters when creating the interrupt port. I didn’t include it on this example, as I wanted to show mirror symmetry between the pull up and pull down circuits.

The Netduino does not have an inbuilt Pull down resistor. So you will always have to wire it like the example above.

About these ads

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s