loading

This instructable will show you how to build a versatile robot trigger that can move something such as a button, switch, or dial on various devices when you (with your phone or a beacon in your pocket) are nearby. This means it could automatically unlock and re-lock a door latch as *only you* pass by, shut off a sprinkler valve so you can pass through the water unscathed like a sort of suburban Moses, lower speaker volume while you are in the garage band room, trigger a iPod playing a dramatic entry tune or tell a joke (Jaden Smith tweet?) while you are in the room, or pause a movie when you get up to use the restroom.

This project does not require soldering or special tools!

If you enjoy this instructables enough, please consider voting for this instructable in the Robotics 2017 contest!

Step 1: Acquire the Hardware Parts.

You will need:

If you don't have a smartphone with a mobile hotspot feature, you will also need:

  • ESP-01 module about $2.50 USD free shipping on DealExtreme, GearBest, Ebay, or Aliexpress.
  • 1 Pair AAA batteries
  • dual AAA battery holder with switch

Step 2: Quick Start

This step contains a quick start guide in case you like that sort of thing. The rest of this instructable goes step by step and adds more in-depth information.

//Shopping list:
//NodeMCU V3 (Lolin) ESP8266 microcontroller

//SG90 9G Servo Motor

//USB Power Bank or USB wall adapter.

//Micro USB data/charge cable

//Arduino male to female type jumper wires

//BEFORE YOU START:

//1. If you haven't already downloaded the Arduino IDE, get it for free (donation optional) at: https://www.arduino.cc/en/Main/Software

//2. open the Arduino IDE (if you aren't reading this in the Arduino IDE already!)...

//3. Go to files and click on the preference in the Arduino IDE...

//4. copy the below code in the Additional boards Manager: //http://arduino.esp8266.com/stable/package_esp8266com_index.json

//5. click OK to close the preference tab...

//6. Go to tools and board, and then select board manager...

//7. Navigate to esp8266 by esp8266 community and install the software for Arduino...

//8. You may need to download and install the CH340 driver if you are unable to get the NodeMCU talking with your Arduino IDE: https://www.wemos.cc/downloads

//Once all the above process been completed we are read to program our esp8266 NodeMCU microcontroller with the Arduino IDE.

//9.select NodeMCU V1.0 ESP12E from the board menu /

/10. Select the COM port you are using.

//11. select the code (download from www.makersa.ga )and click upload. /

/12. Plug the servo into the NodeMCU using jumper wires. D0 to signal, ground to ground, +VCC to VO or 3V. /

/13. Adjust the servo horn using a screwdriver.

//14. Adjust the maximum and minimum degrees of movement using the code.

//15. Re-upload to the NodeMCU whenever the code is updated.

//You may find it important to figure out which NodeMCU version you have. Heres a comparison guide:

http://frightanic.com/iot/comparison-of-esp8266-no... // NodeMCU v1 pinout diagram: http://frightanic.com/iot/comparison-of-esp8266-no... // NodeMCU v2 pinout diagram: http://frightanic.com/iot/comparison-of-esp8266-no... // NodeMCU v3 pinout diagram: http://frightanic.com/iot/comparison-of-esp8266-no...

//Explanation of the rigs:

//Made from NodeMCU ESP8266 microcontroller, battery or USB power supply, and SG90 Servo

//You can use a 2nd unmodified esp8266 module as a beacon hotspot AP instead of using a smartphone, no programming necessary.

Step 3: Acquire the Software Parts

You will first need to download the free Arduino IDE

The Arduino Web Editor doesn't work with the NodeMCU at the time I'm writing this, so you will have to install the IDE to your computer instead.

You will also need to grab the NearBot files from www.MakerSa.ga - The file download link for this project is listed on that site.

Step 4: Install Drivers and Board Profiles

Inside the NearBot zip you downloaded and unzipped will be the drivers for the NodeMCU module. Install those to your computer.

If those do not work for you, you may be able to find CH340G drivers at wemos.cc/downloads

Your NodeMCU might not use CH340G chip, so you may need to comment with the driver you are looking for, and I'll reply with the download link for that driver.

  1. Next, open the Arduino IDE and go to File--> Preferences-->Additional Boards Manager in the Arduino IDE.
  2. Paste the following code there: http://arduino.esp8266.com/stable/package_esp8266...
  3. Click OK to close the preference tab.
  4. Go to tools and board, and then select board manager.
  5. Navigate to "esp8266 by esp8266 community" and install the software for Arduino.

Once all the above process been completed we are ready to program our esp8266 NodeMCU microcontroller with the Arduino IDE!

Step 5: Some Helpful Info

You may find it handy to figure out which NodeMCU version you have. Here is a comparison guide:

http://frightanic.com/iot/comparison-of-esp8266-nodemcu-development-boards/

Each version has different pin arrangements. I purchased the v3 (Lolin) version because it has 5V output pins to power the Servo motor. I ultimately instead used the 3 volt power pins instead for safety (The NodeMCU I/O pins are not 5V tolerant), but you might want to use the 5V pins because technically these kinds of servo motors are specified for 4.5 to 5 volt power.

Step 6: Load the Code Onto the NodeMCU

  1. Plug the NodeMCU into your computer using any micro USB cable.
  2. Open the Arduino IDE, and under "Boards", select "ESP12E", and the COM port for the NodeMCU.
  3. In the IDE, go to File-->Open--> and browse the zip folder previously downloaded from makersa.ga to open the Arduino sketch called "ProximityActuator013017DonovanMagryta.ino"
  4. Then, edit the line of code containing this to add the name and password of your WiFi beacon. More on that below! For example:
const char* ssid = "mywifi"; //Put your hotspot name inside the quotes
const char* password = "mywifipassword"; //Put your hotspot password inside the quotes

Then click "upload" to flash the code onto the NodeMCU board.

The NearBot uses a pocketable WiFi beacon to identify you and estimate distance. Just like the proximity keys some newer cars have that unlock the door to the car as you approach.

You can use your smartphone mobile hotspot as a beacon, or alternatively use a cheap ESP-01 WiFi module powered by a pair of AAA batteries or a small lithium 3.7v battery. No need to program the ESP-01, it defaults to hotspot mode stock when it is powered on. The circuit diagram for that is shown on this step.

Step 7: Attach the Servo to the NodeMCU

You will need some jumper wires to plug the servo into the NodeMCU V3.

The circuit diagram is simple.

Pin D0 to the signal in lead (lightest color wire on the servo. usually yellow or white.)

Pin 3V or pin VO to the 5V input lead (second lightest color wire on the servo, usually red or orange.)

Pin GND to the ground lead (darkest colored wire on the servo, usually brown or black.)

Step 8: Fine Tune the NearBot

The code converts signal strength to distance estimation. It works reliably for reaction distances less than 2 meters or 6.5 feet. Because it is a direct conversion, it is not as smooth for farther distances than 3 meters as it could potentially be with a better calculation method. More on that later.

You may want to adjust where the servo horn (the little white arm that moves) is positioned. This is done by simply unscrewing the servo arm with a screwdriver, and re-positioning it.

The next part is to adjust the maximum and minimum degrees of movement using the code.

This can be done by changing the numbers contained in lines that look like this:

 myservo.write(10); //moves servo arm to 10 degrees rotation 

You can also adjust the signal strength sensitivity by changing the negative numbers in lines that look like this:

if (rssi > -30 && rssi < -5) { //If signal strength is stronger than -30, and weaker than -5. then do the following...

Step 9: How It Works

  1. The NearBot first connects to the hotspot in advance as a users approaches.
  2. It scans the RSSI (received signal strength) and converts that to approximate distance.
  3. While the distance is within the specified range, it moves the servo motor arm to position 1.
  4. Otherwise, the servo motor is moved to position 2.

When I tested this, this RSSI tuning (-50) moves the servo to position 1 while the distance is 0 to 1.5 meter with the ESP-01 beacon or phone hotspot in my pocket.

The RSSI typically falls within a range of -90 to -20, with -20 being the strongest signal strength.

If you open the Arduino IDE Serial Monitor while the NearBot is plugged into the computer, it will display the signal strength and trigger points in real time for you to have handy feedback.

Here is the complete code:

//BEFORE YOU START:
//1. If you haven't already downloaded the Arduino IDE, get it for free (donation optional) at: <a href="https://www.arduino.cc/en/Main/Software" rel="nofollow"> https://www.arduino.cc/en/Main/Software
</a>
//2. open the Arduino IDE (if you aren't reading this in the Arduino IDE already!)...
//3. Go to files and click on the preference in the Arduino IDE...
//4. copy the below link in the Additional boards Manager:
//http://arduino.esp8266.com/stable/package_esp8266com_index.json
//5. click OK to close the preference tab...
//6. Go to tools and board, and then select board manager...
//7. Navigate to esp8266 by esp8266 community and install the software for Arduino...
//8. You may need to download and install the CH340 driver if you are unable to get the NodeMCU talking with your Arduino IDE: <a href="https://www.wemos.cc/downloads" rel="nofollow"> https://www.arduino.cc/en/Main/Software
</a>
//Once all the above process been completed we are read to program our esp8266 NodeMCU microcontroller with the Arduino IDE.

You may want to figure out which NodeMCU version you have. Heres a comparison guide: <a href="http://frightanic.com/iot/comparison-of-esp8266-nodemcu-development-boards/" rel="nofollow"> https://www.arduino.cc/en/Main/Software
</a>
//Made from NodeMCU ESP8266 microcontroller, battery or USB power supply, and SG90 Servo
//You can use a 2nd unmodified esp8266 module as a beacon hotspot AP instead of using a smartphone.


//NearBot Circuit:
//D0 pin to Servo signal wire (lightest color wire)
//3V pin to servo 5v wire (middle wire) (spliced in parallel to usb cable or the VO pin on the NodeMCU if you have V3.
//USB power to USB plug on the NodeMCU
//GND pin to Servo Ground wire (darkest color wire)


// Note lines start with  two forward slashes, and are ignored by the computers. Notes are just for us humans!
#include 
#include  //May be needed for serial printing.
#include  //Servo library
#define D0 16 //Defines pins to make assigning pins easier.
#define D1 5 // I2C Bus SCL (clock)
#define D2 4 // I2C Bus SDA (data)
#define D3 0
#define D4 2 // Same as "LED_BUILTIN", but inverted logic
#define D5 14 // SPI Bus SCK (clock)
#define D6 12 // SPI Bus MISO 
#define D7 13 // SPI Bus MOSI
#define D8 15 // SPI Bus SS (CS)
#define D9 3 // RX0 (Serial console)
#define D10 1 // TX0 (Serial console)
Servo myservo; //Create a servo object named myservo
//Phone or additional ESP8266 module set to hotspot AP mode:
const char* ssid = " "; //Put your hotspot name inside the quotes
const char* password = " "; //Put your hotspot password inside the quotes

void setup(){
     Serial.begin(115200); //sets serial baud rate so the microcontroller can talk to the serial print interface in the Arduino IDE - You may need to change it to 9600 instead!
     myservo.attach(D0);  // attaches the servo on pin D0 aka GPIO16 to the servo object - See more at: <a href="http://www.esp8266.com/viewtopic.php?f=32&t=8862#sthash.WYxX3IFE.dpuf" rel="nofollow"> http://www.esp8266.com/viewtopic.php?f=32&t=8862#...</a>
     myservo.write(10); //moves servo arm to 10 degrees rotation 
     Serial.println("Locked");  //output the the serial monitor the word "Locked" 
     WiFi.mode(WIFI_STA); //Sets wifi to Station mode
     WiFi.begin(ssid, password); //Connects to hotspot beacon
} 

 void loop() { //The loop runs over and over again rapidly
    
    if (WiFi.status() != WL_CONNECTED) { //If wifi is NOT connected, do the following...
    Serial.println("Couldn't get a wifi connection");
    myservo.write(10); //Moves servo arm to 10 degrees 
    Serial.println("Locked");
    
    } 
  else { //If WiFi IS connected, then do the following...

  long rssi = WiFi.RSSI(); //Creates a variable named rssi and assign it to the function that returns the signal strength reading of the hotspot beacon
  Serial.print(rssi); //outputs the rssi reading to the serial monitor
   
  if (rssi > -50 && rssi < -5) { //If signal strength is stronger than -50, and weaker than -5. then do the following...
   myservo.write(170); //Rotate servo arm to 170 degrees
   Serial.println("Unlocked");
   }
   
  else { //If the above conditions aren't met then do the following...
   myservo.write(10); //Rotates servo arm back to 10 degrees.
   Serial.println("Locked");
   }
  }
 }

Step 10: You Ought to Know...

Disclaimer:

The current iteration of the NearBot code works reliably for distances less than 2 meters or 6.5 feet. Beyond that, it gets less precise, but still works.

This can be fixed, but at the moment I don't know how to do so. I would love it if someone would work with me so I can update this instructables with more precise method of calculating distance!

These links might be handy: YouTuber CNLohr developed a distance and position sensing firmware for the ESP8266 with limited success: https://github.com/cnlohr/esp8266rawpackets

Espressif developed a Time of Flight distance detection function which would work with Arduino IDE for the ESP8266, but never released it: http://bbs.espressif.com/viewtopic.php?t=467

SubPos positioning system uses ESP8266 modules and Path Loss Calculation, which is what I don't know how to implement in Arduino IDE: http://wiki.subpos.org/index.php?title=Path_Loss_Calculation

I found a example in Java language, but I don't know how to replicate this is Arduino IDE:

double distance = Math.pow(10.0,(((double)(tx_pwr/10)) - rx_pwr - 10*Math.log10(4*Math.PI/(c/frequency)))/(20*mu));

Step 11: That Is All!

If you make your own NearBot, post your "I made it" in the comments below!

If you have any more ideas for what to use the Versatile NearBot platform for, please comment your ideas! It could be great inspiration for other instructables users!

If you enjoy this tutorial, please consider voting for this instructable in contests!

<p>Pretty neat. I like simple! :)</p>
<p>Thanks!</p>

About This Instructable

2,072views

27favorites

License:

Bio: We are two brothers who like to make things.
More by Maker Saga:Cheap Music Reactive Light Show Instructable Hit Announcer Bot  Versatile NearBot 
Add instructable to: