Proximity Light Switch Using Mobile Hotspot
by zvincent689 in Circuits > Arduino
75 Views, 0 Favorites, 0 Comments
Proximity Light Switch Using Mobile Hotspot
This is a tutorial for building a proximity light switch using the signal from your mobile hot spot. It will detect the signal coming off of your hot spot and measure its strength. It will then turn a servo that flicks on the light switch if the signal is strong enough, which indicates that you are near. It will do the same when your phone goes out of range, flicking the light switch off.
This project was done by a high school Junior as part of a Physical Computing class.
Supplies
Electronic:
- 1x Particle Argon
- 3x Jumper Wires
- 1x Breadboard
- 1x Servo with fin (preferably high-torque)
- Phone with hotspot
Tools/Materials:
- Cardboard
- Hot Glue Gun
- A lot of tape
Set Up Argon
Attach a WiFi antenna onto your device so it can connect to the internet
Go to the Particle Setup page and follow instructions
Once you get to connecting your Argon to a WiFi network, open your phone and turn on your hotspot. Reminder that the Argon will only connect to 2.4GHz, so your network should be configured 2.4GHz. Once the Argon is connected, it should start flickering and breathing blue.
For the picture above, you only need 1 WiFi antenna. The other antenna is for bluetooth, which this tutorial is not going to use.
Attach Servo
Attach the servo to your breadboard. It should have three wires. Each wire should connect to each of the following:
- Brown wire is connected into ground
- Red wire is connected to VUSB
- Yellow wire is connected to your digital pin (I used D2 for my code)
Write the Code
Go into build.particle.io, create a new app, and copy + paste my code.
SYSTEM_THREAD(ENABLED);
//lets code run when argon gets disconnected from internet
Servo myServo;
int aTime = 0; //make a timer
String UUID = "Network Name"; // replace with the UUID for your hotspot
String password = "Password"; // replace with the password for our hotspot
void setup() {
//start monitoring wifi signal values
Serial.begin(9600);
myServo.attach(2);
//save credentials of hotspot
WiFi.on();
WiFiCredentials credentials(UUID, WPA2);
credentials.setPassword(password);
credentials.setCipher(WLAN_CIPHER_AES);
//connects to the internet
WiFi.connect();
waitFor(WiFi.ready, 30000);
Particle.connect();
waitFor(Particle.connected, 30000);
}
void loop() {
if(Particle.connected && WiFi.ready()) //detects if the argon is connected to your hotspot
{
//declares WiFiSignal sig and gives the object the details of your wifi network
WiFiSignal sig;
sig = WiFi.RSSI();
//returns strength and quality of the WiFi signal
float quality = sig.getQualityValue();
float strength = sig.getStrengthValue();
Serial.println("Time elapsed: " + String(aTime)); //keeps track of everytime the object sig updates
Serial.println("Str value : " + String(strength));
//returns a number between -90 and 0. The closer it is the 0, the better the connection.
Serial.println("Quality value: " + String(quality));
Serial.println("");
Serial.println("");
if(strength < -25) { //can change the number based on how far/close you want it to run
myServo.write(93);
delay(5000);
aTime += 5;
}
else {
myServo.write(10);
delay(5000);
aTime +=5;
}
}
else
{
Serial.println("Not connected to cloud or not connected to wifi");
delay(1000);
}
}
Build Structural Components
If your servos couldn't reach your light switch like mine, you can hot glue cardboard onto your light switch to extend it. If the fins are too short, you could also hot glue cardboard onto that too.
When you've tested that the servo could turn the light switch, start taping the servo into a position that can turn the light switch. It may be helpful to unplug your Argon from the power source to stop it from turning randomly. Once you've set everything up correctly and flashed the code, it should start turning whenever you're near.