Hackster is hosting Hackster Holidays, Ep. 6: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Monday!Stream Hackster Holidays, Ep. 6 on Monday!
Amaan Javed
Published

M5Stack MULTI-TOOL

M5Stack Multi-Tool has Distances measurement, Spirit level, Voltage sensor, Find my phone, Torch, Home automation controls

IntermediateFull instructions provided1 hour2,173
M5Stack MULTI-TOOL

Things used in this project

Hardware components

Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1
LED (generic)
LED (generic)
×3
Banana Test Connector, Insulated
Banana Test Connector, Insulated
×2
ESP32 Basic Core IoT Development Kit
M5Stack ESP32 Basic Core IoT Development Kit
×1
NodeMCU ESP8266 Breakout Board
NodeMCU ESP8266 Breakout Board
×1
Inertial Measurement Unit (IMU) (6 deg of freedom)
Inertial Measurement Unit (IMU) (6 deg of freedom)
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Code

M5STACK

Arduino
#define M5STACK_MPU6050
#include<M5Stack.h>
#include <WiFi.h>
#include <HTTPClient.h>
const char* host = "maker.ifttt.com";
const char* ssid     = "";//PUT YOUR WIFI SSID  
const char* password = "";//PUT YOUR WIFI PASS
const int trigPin = 3;
const int echoPin = 1;
const int vr = 35;
float vo = 0.0;
float vi = 0.0;
float r1 = 30000.0;
float r2 = 7500.0;
int val = 0;
long dur;
int program = 0;
float pitch = 0.0F;
float roll  = 0.0F;
float yaw   = 0.0F;
float dis;
void setup() {
  M5.begin();
  M5.Power.begin();   
  M5.IMU.Init();
  for(uint8_t t = 4; t > 0; t--) {
        Serial.printf("[SETUP] WAIT %d...\n", t);
        Serial.flush();
        delay(1000);}
        WiFi.begin(ssid,password);
    while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
    }
  pinMode(trigPin, OUTPUT); 
  pinMode(echoPin, INPUT);
   pinMode(16,OUTPUT);
  M5.Lcd.fillScreen(BLUE);
  M5.Lcd.setTextColor(WHITE);
  M5.Lcd.setTextSize(3);
  M5.Lcd.setCursor(65, 10);
  M5.Lcd.print("POWER TOOL:");
  M5.Lcd.setCursor(3, 35);
  M5.Lcd.println("A FOR DIS");
  M5.Lcd.println("B FOR LEVEL");
  M5.Lcd.println("C FOR VM");
  M5.Lcd.println("AL FOR FMP/LIT");
  M5.Lcd.println("BL FOR RLITS");
  digitalWrite(2,0);
}

void loop() {
  M5.update();
  M5.IMU.getAhrsData(&pitch,&roll,&yaw);
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  dur = pulseIn(echoPin, HIGH);
  dis= dur*0.034/2;
   switch (program) {  
case 0:
  if (M5.BtnA.wasReleased()) {
          program = 1;
          m5.Lcd.clear();
          delay(500);
          }
    break;
case 1:         
  M5.Lcd.fillScreen(BLUE);
  M5.Lcd.setTextColor(WHITE);
  M5.Lcd.setTextSize(3);
  M5.Lcd.setCursor(65, 10);
  M5.Lcd.print("Dis: ");
  M5.Lcd.setCursor(3, 35);
  M5.Lcd.println("DIS(cm):");
  M5.Lcd.setTextSize(9);
  M5.Lcd.setCursor(140, 70);
  M5.Lcd.print(dis);
  delay(100);
if (M5.BtnB.wasReleased()) {
          program = 2;         
          M5.Lcd.clear();
          delay(500);
        }
         break;
  case 2:         
if(roll >= 10){
        M5.Lcd.fillScreen(RED);      
    } 
    if(roll <= -10){
        M5.Lcd.fillScreen(RED);      
    }    
    else{
       M5.Lcd.fillScreen(GREEN);
      }
if (M5.BtnC.wasReleased()) {
          program = 3;        
          M5.Lcd.clear();
          delay(500);
        }
         break;    
case 3:
M5.Lcd.setCursor(65, 10);
M5.Lcd.setTextSize(3);
M5.Lcd.fillScreen(BLUE);
M5.Lcd.setTextColor(WHITE);
M5.Lcd.print("Vin > 25V");
val = analogRead(vr);
vo = (val * 5.0) / 1024.0;
vi = (vo / (r2/(r1+r2)))-3;
M5.Lcd.setCursor(3, 35);
M5.Lcd.print(vi);
M5.Lcd.print("V");
  delay(500);
    if (M5.BtnA.wasReleasefor(700)) {
          program = 4;       
          M5.Lcd.clear();
          delay(500);
        }
         break; 
case 4:  
M5.Lcd.fillScreen(BLUE);
  M5.Lcd.setTextColor(WHITE);
  M5.Lcd.setTextSize(3);
  M5.Lcd.setCursor(3, 35);
  M5.Lcd.println("A FOR FMP");
    M5.Lcd.println("B FOR LIT");
    delay(100);
if (M5.BtnA.wasReleased()) {        
    M5.Lcd.clear(BLUE);
  M5.Lcd.setTextColor(WHITE);
  M5.Lcd.setTextSize(2);
  M5.Lcd.setCursor(65, 10);
  M5.Lcd.println("FINDING");
  //WiFi.begin(ssid, password); 
       while (WiFi.status() != WL_CONNECTED) {
       delay(500);
       }
       WiFiClient client;
       const int httpPort = 80;
       if (!client.connect(host, httpPort)) {
        M5.Lcd.println("Weak Network");
       return;
       }
       String url = ""; //PUT THE URL HERE
       client.print(String("GET ") + url + " HTTP/1.1\r\n" + "Host: " + host + "\r\n" + "Connection: close\r\n\r\n"); 
       delay(1000);
       client.stop();
       for (int i = 0; i <= 11; i++) {
         m5.Lcd.print(". ");
         delay(1000);
  }  
  //setup();
}
if (M5.BtnB.wasReleased()) {
  digitalWrite(16,1);
  M5.Lcd.clear(BLUE);
  M5.Lcd.setTextColor(WHITE);
  M5.Lcd.setTextSize(2);
  M5.Lcd.setCursor(65, 10);
  M5.Lcd.println("LIT");
} 
if (M5.BtnB.wasReleasefor(700)) {
          program = 5;          
          M5.Lcd.clear();
          delay(500);
        }
         break;   
case 5:
if((WiFi.status() == WL_CONNECTED)) {

        HTTPClient http;  
M5.Lcd.fillScreen(BLUE);
  M5.Lcd.setTextColor(WHITE);
  M5.Lcd.setTextSize(3);
  M5.Lcd.setCursor(3, 35);
  M5.Lcd.println("A FOR 1ON");
    M5.Lcd.println("B FOR 2ON");
    M5.Lcd.println("AL FOR 1OFF");
    M5.Lcd.println("BL FOR 2OFF");
    delay(100);
    
    if (M5.BtnA.wasReleased()) {
        http.begin("http://192.168.1.6/1ON");//put nodemcu ip here 
        int httpCode = http.GET();
        http.end();
    }
    else if (M5.BtnB.wasReleased()) {
        http.begin("http://192.168.1.6/2ON");//put nodemcu ip here 
        int httpCode = http.GET();
        http.end();    }else if (M5.BtnA.wasReleasefor(700)) {
        http.begin("http://192.168.1.6/1OFF");//put nodemcu ip here 
        int httpCode = http.GET();
        http.end();
    }else if (M5.BtnB.wasReleasefor(700)) {
        http.begin("http://192.168.1.6/2OFF");//put nodemcu ip here 
        int httpCode = http.GET();
        http.end();
    }
}
   break;      
}
}

Nodemcu

Arduino
#include <ESP8266WiFi.h>  
const char* ssid = "";//put your ssid
const char* password = "";//put your pass
int ledPin = 5; 
int led = 4;
WiFiServer server(80);
void setup() {
  WiFi.softAPdisconnect (true);
  Serial.begin(115200);
  delay(10);
  pinMode(ledPin, OUTPUT);
  digitalWrite(ledPin, LOW);
  pinMode(led, OUTPUT);
  digitalWrite(led, LOW); 
  Serial.println(ssid);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print("."); 
  }
  server.begin();
  Serial.print("go here to connect: ");// if it says "Yeah its working" then its working
  Serial.print("http://");
  Serial.print(WiFi.localIP());
  Serial.println("/");
}
 
void loop() {
  WiFiClient client = server.available();
  if (!client) {
    return;
  }
  while(!client.available()){
    delay(1);
  }
  String request = client.readStringUntil('\r');
  Serial.println(request);
  client.flush();
  if (request.indexOf("/1ON") != -1)  {
    digitalWrite(ledPin, HIGH);
  }
  if (request.indexOf("/1OFF") != -1)  {
    digitalWrite(ledPin, LOW);
  }if (request.indexOf("/2ON") != -1)  {
    digitalWrite(led, 1);
  }if (request.indexOf("/2OFF") != -1)  {
    digitalWrite(led, LOW);
  }
  client.println("HTTP/1.1 200 OK");
  client.println("Content-Type: text/html");
  client.println("");
  client.println("<!DOCTYPE HTML>");
  client.println("<html>"); 
  client.print("Yeah its working");
  Serial.println("Client disonnected");
  Serial.println("");
}

Credits

Amaan Javed

Amaan Javed

19 projects • 4 followers
Student

Comments