Notes About Working with Various Arduino & Netduino Microcontroller Boards

Sunday, November 25, 2012

Using an ePIR Motion Detector with a Netduino Plus 2

Here is a C# "translation" of the sample code I posted yesterday.  If the ePIR detects motion, the code print Y to the debug console, otherwise it prints an N. A reading is taken every second. As in yesterday's example for the Arduino, there is no compensation for ambient light in order to keep the example simple.


ePIR   -->  Netduino Plus 2   
pin 1       GND
pin 2       3.3V
pin 3       Digital 1 (TX)
pin 4       Digital 0 (RX) + 100k pull-up resistor
pin 6       3.3V  (no light level correction)

C# Code:

using System.Threading;
using Microsoft.SPOT;
using System.IO.Ports;

namespace ePIR
  public class Program
    const byte STATUS_CMD = 0x61;
    const int DELAY = 1000;
    public static void Main()
      SerialPort serialPort = new SerialPort("COM1", 9600, Parity.None, 8, StopBits.One);
      while (true)
        char result = (char) serialPort.ReadByte();

To use COM2, connect to digital pins 2 (TX) & 3 (RX). To use COM3 connect to digital pins 7 (TX) & 8 (RX). 

No comments:

Post a Comment