Sunday, September 2, 2012

Netduino - Optocoupler testing

I have finally had chance to spend a few minutes on the last part of my relay control board, this part demonstrates the use of an optocoupler along with PWM to control a 12 volt LED. My next test will be to use this circuit with a computer fan in order to provide the fan control for my relay enclosure.

This circuit is very straight forward, it uses a 4N35M octocoupler, an LED and 2 resistors. There is a 1k resistor between the digital out of the netduino and pin 1 on the octo and another to match the LED. I am using a 12 volt 1 amp power supply in this example.



using System;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware;
using SecretLabs.NETMF.Hardware.Netduino;

namespace CIRC_08
{
public class Program
{
static PWM pwm = new PWM(Pins.GPIO_PIN_D5);

public static void Main()
{
while (true)
{
for (int sensorValue = 1; sensorValue < 101; sensorValue++) { Debug.Print(sensorValue.ToString()); pwm.SetDutyCycle((uint)sensorValue); Thread.Sleep(100); } for (int sensorValue = 100; sensorValue > 2; sensorValue--)
{
Debug.Print(sensorValue.ToString());
pwm.SetDutyCycle((uint)sensorValue);
Thread.Sleep(100);
}

pwm.SetDutyCycle(0);
Thread.Sleep(10000);
}
}

}
}