We no longer sell products directly from the GHI Electronics website, click here for more details. Please find a Distributor to complete your online order. If you have any questions regarding this notice please contact us at support@ghielectronics.com.

Analog Inputs

Last modified July 25, 2014

Required

Tutorials: First NETMF Project

Introduction

Unlike digital input pins which can only read high or low; analog pins can read a range of voltage levels.  Micro-controllers based on 3.3V can read voltages anywhere between zero and 3.3V.

In contrast to digital input pins that are 5V tolerant; the maximum applied voltage for analog input must not exceed 3.3V (for higher voltages a voltage divider or an op-amp circuit can be used).

Using a Light Sensor to Demonstrate Analog Input

This example uses a light sensor; it's output voltage varies with light intensity; the darker the light; the higher the voltage output.

The following code requires the Microsoft.SPOT.Hardware assembly. Consult the Developers' Guide or the product manual for specific channels.

using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;


public class Program
{
    public static void Main()
    {
        AnalogInput lightSensor = new AnalogInput((Cpu.AnalogChannel)Cpu.AnalogChannel.ANALOG_7);
        double lightSensorReading = 0;

        while (true)
        {
            lightSensorReading = lightSensor.Read();
            Debug.Print(lightSensorReading.ToString());
            Thread.Sleep(500);
        }
    }
}
Leave feedback about this document.
Let us know if the information presented here was accurate, helpful and if you have any suggestions.
Leave feedback about this document.
Let us know if the information presented here was accurate, helpful and if you have any suggestions.

* Indicates required fields.
This form is only for feedback not support.
Review our how to find information guide on locating helpful resources.