Main Site Documentation

Output of the di1 pin not enough to function the relay


#1

Hi
i brought a Panda II and Relay e block
but when i run the code it is not functioning only the small LED just light it with a poor bright. i think the output of the di1 pin not enough to function the relay .
pls help me to overcome this problem
thanks


#2

You can NOT connect a relay directly to a pin on processor, not on FEZ and not on any other microcontroller. This will damage your micro, your FEZ.

The internet is full of tutorials on this, like this one http://www.dnatechindia.com/Tutorial/8051-Tutorial/Interfacing-Relay-to-Microcontroller.html

You can use our relay board which already has the transistor on it http://www.ghielectronics.com/catalog/product/192


#3

i brought a 3-Pin E-Block RELAY and plug it to JST Connector(Di1)


#4

What JST connector, there is no JST connector on the Panda?

So how did you connect it?


#5

@ EricSan500 - I think he means via the eBlock or Connect shield.


#6

ya i have connected relay e block via connected shield


#7

My aim is to control relay through the web server . i have try several codes but i failed.pls some body help me


#8

First, make sure you are able to control the relay directly. If you still have problems then post a picture of how the relay is connected and post your code as well please


#9

thanks GUS

now my relay is functioning this is the code i have run.but i don’t how to off the relay by clinking OFF button


using System;
using System.Threading;
using System.Text;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using GHIElectronics.NETMF.FEZ;
using GHIElectronics.NETMF.Hardware;
using GHIElectronics.NETMF.Net;
using GHIElectronics.NETMF.Net.NetworkInformation;
public class Program
{
    public static void Main()
    {
        
         FEZ_Components.Relay myRelay = new FEZ_Components.Relay(FEZ_Pin.Digital.Di1);

        byte[] ip = { 192, 168, 2, 5 };
        byte[] subnet = { 255, 255, 255, 0 };
        byte[] gateway = { 192, 168, 1, 1 };
        byte[] mac = { 0x00, 0x88, 0x98, 0x90, 0xD4, 0xE0 };

        WIZnet_W5100.Enable(SPI.SPI_module.SPI1, (Cpu.Pin)FEZ_Pin.Digital.Di10,
        (Cpu.Pin)FEZ_Pin.Digital.Di7, true);
        NetworkInterface.EnableStaticIP(ip, subnet, gateway, mac);
        NetworkInterface.EnableStaticDns(gateway);

        // start server
        HttpListener listener = new HttpListener("http", 80);
        listener.Start();
        while (true)
        {
            HttpListenerResponse response = null;
            HttpListenerContext context = null;
            try
            {
                context = listener.GetContext();
                response = context.Response;

                // The button is pressed
                if (context.Request.HttpMethod == "POST")
               
                     {  
                        myRelay.On();
                        Thread.Sleep(2000);
                        myRelay.Off();
                        
                        
                        
                        
                     
                }
                // Sends response
                response.StatusCode = (int)HttpStatusCode.OK;
                byte[] HTML = Encoding.UTF8.GetBytes(
                "<html><body>" +
                "<h1>LIVING ROOM</h1>" +
                "<p>SWITCH ON OR OFF</p>" +
                "<form action=\"\" method=\"post\">" +
                "<input type=\"submit\" value=\"ON\">" +

                 "<form action=\"\" method=\"post\">" +
                "<input type=\"submit\" value=\"OFF\">" +
                "</form>" +
                "</body></html>");
                response.ContentType = "text/html";
                response.OutputStream.Write(HTML, 0, HTML.Length);
                response.Close();
            }
            catch
            {
                if (context != null)
                {
                    context.Close();
                }
            }
        }
    }
}

also i want tell u i don’t have much knowledge in C# but try to learn …


#10

Good, now you know the hardware is working fine and you only need the correct software.

Have you looked at the internet of things ebook? It already has many project examples.


#11

As Gus says, the IoT book will have relevant samples that you can use.

But what doesn’t work in your app as it stands today? What does it do when you do the POST? What stepping through your code have you tried to see the behaviour? And what values do you get in your response?

The next logical step is to change your arbitrary turn relay on wait 2 sec turn relay off into a conditional check from the response to handle the two different conditions you’re expecting.