Welcome to Hackster!
Hackster is a community dedicated to learning hardware, from beginner to pro. Join us, it's free!
Published

Remote switch with LinkitONE

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

IntermediateFull instructions provided765
Remote switch with LinkitONE

Things used in this project

Hardware components

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

Please log in or sign up to comment.