Published

Remote switch with LinkitONE

Turning off my ADSL antenna automatically when I don't need it.

IntermediateFull instructions provided313
Remote switch with LinkitONE

Things used in this project

Hardware components

LinkIt ONE
MediaTek Labs LinkIt ONE
×1
2 2n3904 NPN transistor
×1
Bistable (latching) relay
×1
Breadboard (generic)
Breadboard (generic)
×1
BreadBoard wires
×1
2 resistor 120
×1
2 resistor 1K
×1

Story

Read more

Schematics

Fritzing

File missing, please reupload.

Code

Code

C/C++
#include 
#include 

#define DELAY      60000
#define PIN_ON     3
#define PIN_OFF    9

char ssid[] = "YOURSSID";
char pass[] = "YOURPWD";

int relayStatus = -1;

void setup()
{
  Serial.begin(9600);
  LWiFi.begin();

  // Iniztialize PIN for relay
  pinMode(PIN_ON,OUTPUT);
  pinMode(PIN_OFF,OUTPUT);
  digitalWrite(PIN_ON,LOW);
  digitalWrite(PIN_OFF,LOW);

  delay(1000);
}

void loop() 
{
  Serial.println();
  Serial.print("Searching for AP...");
  if ( LWiFi.connectWPA(ssid, pass) != 1 )
  {
    Serial.println("Not Found");

    // The SSID is not present, turn off the relay
    if ( relayStatus == -1 || relayStatus == 1 )
    {
      relayStatus = 0;
      switchRelay(0);
    }
  }
  else
  {
    Serial.println("Found!");

    // The SSID has been found, turn on the relay
    if ( relayStatus == -1 || relayStatus == 0 )
    {
      relayStatus = 1;
      switchRelay(1);
    }
  }

  LWiFi.disconnect();

  // Sleeps for a while...
  delay(DELAY);
}

//
void switchRelay(int command)
{
  // Send the HIGH signal to the corret PIN
  if ( command == 1 )
  {
    Serial.println("Turning ON relay");
    digitalWrite(PIN_ON,HIGH);
    delay(50);
    digitalWrite(PIN_ON,LOW);
  } 
  else
  {
    Serial.println("Turning OFF relay");
    digitalWrite(PIN_OFF,HIGH);
    delay(50);
    digitalWrite(PIN_OFF,LOW);
  } 
}

Credits

anonymous

Comments

Add projectSign up / Login