Nero: A Smart Glove That Controls Remote Devices

Operate inaccessible and remote devices using a smart glove from anywhere on Earth.

AdvancedFull instructions provided5 hours6,828

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
WIZ750SR-TTL-EVB Kit
WIZnet WIZ750SR-TTL-EVB Kit
×1
NodeMCU ESP8266 Breakout Board
NodeMCU ESP8266 Breakout Board
×1
Breadboard (generic)
Breadboard (generic)
×2
Hall Effect Sensor
Hall Effect Sensor
×2
GY-521 MPU-6050 3 Axis Gyroscope + Accelerometer Module For Arduino
×1
Magnet
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Servo motors
×1

Software apps and online services

ISP Tool
Coolterm
Arduino IDE
Arduino IDE
MQTT fx

Hand tools and fabrication machines

double sided tape
scissor

Story

Read more

Schematics

Publishing Schematics

The sensors send the data to the arduino which then sends it to the wiznet wiz750SR board. It then publishes the data to the MQTT broker

Subscription Schematics

The nodeMCU subscribes to the MQTT broker and receives the published values. The servo motors are operated according to the received values.

Code

Receiving NodeMCU Code

C/C++
This code subscribes to the MQTT broker, receives the values and operates the servo motors according to the values.
/*
 This code basically sets up an ESP8266 board as a MQTT client and helps in subscribing to desired topics that are published.

 It is required that the board in the 'Tools' section must be selected to NodeMCU and the ESP8266 drivers are installed.
 The baud rate must be set at 115200
 Here we are operating three servo motors using the nodeMCU based on the values received via the MQTT topic
 
*/

#include <ESP8266WiFi.h>
#include <PubSubClient.h>
#include <Servo.h>
// Creating objects for the 3 servo motors
Servo servo;
Servo servo1;
Servo servo2;
// The pins we have used for the servo motors are D1,D2 and D3
// Update these with values suitable for your network.

const char* ssid = "CDI";
const char* password = "Cdi*1717";
const char* mqtt_server = "172.16.73.4";

WiFiClient espClient;
PubSubClient client(espClient);
long lastMsg = 0;
char msg[50];
int value = 0;
char old ;

void setup() {
  //Initial Setup Code
  Serial.begin(115200);
  setup_wifi();
  client.setServer(mqtt_server, 1883);
  client.setCallback(callback);
  delay(1000);
}
//Code for connecting to the wifi
void setup_wifi() {

  delay(10);
  // We start by connecting to a WiFi network
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);

  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }

  Serial.println("");
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
}

//This function is responsible for subscribing to a topic and receiving the values from it 
void callback(char* topic, byte* payload, unsigned int length) {
  Serial.print("Message arrived [");
  Serial.print(topic);
  Serial.print("] ");
 
  old = (char)payload[0];
  //detach each time to avoid jitter of the servo motors
  servo2.detach();
  servo.detach();
  servo1.detach();
 for (int i = 0; i < length; i++) {
  Serial.println("Received message is :");
  Serial.println((char)payload[i]);
  servo.detach();
  servo1.detach();
  servo2.detach();
  if((char)payload[i] == '1')
  {

    servo.detach();
    servo2.detach();
    servo1.detach();
    servo.attach(0);
    servo.write(89);
    delay(1000);
    servo.detach();
    servo1.attach(4);
    servo1.write(89);
    delay(1000);
    servo1.detach();
    servo2.detach();
    old='1';
    break;
  }
if((char)payload[i] == '2')
  {
    servo.detach();
    servo2.detach();
    servo1.detach();
    servo1.attach(4);
    servo1.write(89);
    delay(1000);
    servo1.detach();
    servo2.detach();
    old='2';
    break;
  }
 if((char)payload[i] == '3')
  {
    servo.detach();
    servo2.detach();
    servo1.detach();
    servo.attach(0);
    servo.write(89);
    delay(1000);
    servo.detach();
    servo2.detach();
    old='3';
    break;
  }
 if((char)payload[i] == '4')
  {
    servo.detach();
    servo1.detach();
    servo2.detach();
    servo.attach(0);
    servo.write(180);
    delay(1000);
    servo.detach();
    servo1.attach(4);
    servo1.write(180);
    delay(1000);
    servo1.detach();
    servo2.detach();
    old='4';
    break;
  }
  if((char)payload[i]=='5')
  {
    servo2.detach();
    servo2.attach(5);
    servo2.write(179);
    delay(1000);
    servo2.detach();
  }
  if((char)payload[i]=='6')
  { servo2.detach();
    servo2.attach(5);
    servo2.write(89);
    delay(1000);
    servo2.detach();
   }
  if((char)payload[i]=='7')
  { servo2.detach();
    servo2.attach(5);
    servo2.write(2);
    delay(1000);
    servo2.detach();
  }
    servo2.detach();
  }

    servo.detach();
    servo1.detach();
    servo2.detach();
}
//This function is to reconnect once the connection is lost
void reconnect() {
  // Loop until we're reconnected
  while (!client.connected()) {
    Serial.print("Attempting MQTT connection...");
    // Attempt to connect
    if (client.connect("ESP8266Client")) {
      Serial.println("connected");
      // Once connected, publish an announcement...
      
      // ... and resubscribe
      client.subscribe("Ultrasonic");
    } else {
      Serial.print("failed, rc=");
      Serial.print(client.state());
      Serial.println(" try again in 5 seconds");
      // Wait 5 seconds before retrying
      delay(5000);
    }
  }
}
void loop() {

  if (!client.connected()) {
    reconnect();
  }
  client.loop();

 
}

Wiznet code

C/C++
This code receives the values from the arduino serially and publishes it to the MQTT broker via ethernet.
#include "mbed.h"
#include "MQTTEthernet.h"
#include "MQTTClient.h"
#define ECHO_SERVER_PORT   7
 Serial a(D1,D0);
    Serial s(USBTX, USBRX);

int arrivedcount = 0;
 
void messageArrived(MQTT::MessageData& md)
{
    MQTT::Message &message = md.message;
    printf("Message arrived: qos %d, retained %d, dup %d, packetid %d\n", message.qos, message.retained, message.dup, message.id);
    printf("Payload %.*s\n", message.payloadlen, (char*)message.payload);
    ++arrivedcount;
}

void baud(int baudrate) {
    s.baud(baudrate);
}

int main (void)
{
    
    baud(9600);
    printf("Wait a second...\r\n");
    char* topic = "Ultrasonic";
    MQTTEthernet ipstack = MQTTEthernet();
    
    MQTT::Client<MQTTEthernet, Countdown> client = MQTT::Client<MQTTEthernet, Countdown>(ipstack);
    
    char* hostname = "172.16.73.4";
    int port = 1883;
    
    int rc = ipstack.connect(hostname, port);
    if (rc != 0)
        printf("rc from TCP connect is %d\n", rc);
        
    printf("Topic: %s\r\n",topic);
    
    MQTTPacket_connectData data = MQTTPacket_connectData_initializer;       
    data.MQTTVersion = 3;
    data.clientID.cstring = "parents";

    if ((rc = client.connect(data)) != 0)
        printf("rc from MQTT connect is %d\n", rc);
 
    if ((rc = client.subscribe(topic, MQTT::QOS0, messageArrived)) != 0)
        printf("rc from MQTT subscribe is %d\n", rc); 
        
    MQTT::Message message;
    char buf[100];
    while (true) 
    {
        char b;
        int i=0;
        char q[100];
        if(a.readable())
        { 
            for(i=0;i<=1;i++)
            {
            b= a.getc();
            q[i]=b;
            s.printf("%c",q[i]);
            }
            
        sprintf(buf,"%s",q);
        message.qos = MQTT::QOS1;
        message.retained = false;
        message.dup = false;
        message.payload = (void*)buf;
        message.payloadlen = strlen(buf);
        rc = client.publish("Ultrasonic", message);
        client.yield(2000);
    
            }
        
            }
}

Transmitting Arduino Code

C/C++
This code receives the value from the sensors and transmits it serially to the Wiznet Wiz750sr
// defines pins numbers
#include <SoftwareSerial.h>
#include "Wire.h"

// I2Cdev and MPU6050 must be installed as libraries, or else the .cpp/.h files
// for both classes must be in the include path of your project
#include "I2Cdev.h"
#include "MPU6050.h"

// class default I2C address is 0x68
// specific I2C addresses may be passed as a parameter here
// AD0 low = 0x68 (default for InvenSense evaluation board)
// AD0 high = 0x69
MPU6050 accelgyro;

int16_t ax, ay, az;
int16_t gx, gy, gz;
SoftwareSerial mySerial(10, 11); // RX, TX
int hPin=9;
int value1;
int myInts[2];
const int trigPin = 3;
const int echoPin = 2;
long duration;
int distance;
int hPin1=6;
int hState1=0;
int value;
int hState=0;
int olds=0;
int od;
int olds1=0;

// accelerometer values
int accel_reading;
int accel_corrected;
int accel_offset = 200;
float accel_angle;
float accel_scale = 1; // set to 0.01
void setup() {
    // join I2C bus (I2Cdev library doesn't do this                                                                                                                      automatically)
Wire.begin();
 		accelgyro.initialize();
  		pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
pinMode(echoPin, INPUT); // Sets the echoPin as an Input

  	// put your setup code here, to run once:

Serial.begin(9600);
  		// put your setup code here, to run once:
pinMode(hPin,INPUT);
pinMode(hPin1,INPUT);

 		mySerial.begin(9600);
  		pinMode(LED_BUILTIN, OUTPUT);
olds=olds1=80;
}

void loop() {
  
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
// Sets the trigPin on HIGH state for 10 micro seconds
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Reads the echoPin, returns the sound wave travel time in microseconds
duration = pulseIn(echoPin, HIGH);
// Calculating the distance
distance= duration*0.034/2;
// Prints the distance on the Serial Monitor

accelgyro.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);

  		// accelerometer_X_Axis angle calc
  		accel_reading = ax;
  		accel_corrected = accel_reading - accel_offset;
  		accel_corrected = map(accel_corrected, -16800, 16800, -90, 90);
  		accel_corrected = constrain(accel_corrected, -90, 90);
  		accel_angle = (float)(accel_corrected *                     accel_scale);
  


  
 		 // put your main code here, to run repeatedly:
  		hState=digitalRead(hPin);
  		hState1=digitalRead(hPin1);

if(hState != olds || hState1 != olds1){
 
 			if (hState==LOW && hState1==LOW){

value=1;
olds = hState;
olds1 = hState1;
}
if (hState1==HIGH && hState==LOW){

value=2;
olds = hState;
olds1 = hState1; }
if (hState1==LOW && hState==HIGH){

value=3;
olds = hState;
olds1 = hState1;}

if (hState1==HIGH && hState==HIGH){
value=4;
olds = hState;
olds1 = hState1;
}
}


else{


 	 if(accel_angle>=0 && accel_angle<=30)
 	 {
  		value = 5;
  		od=value;
  	 }
  	else if(accel_angle>=30 && accel_angle<70)
  	{
    		value=6;
    		od=value;
  	}
  	else if(accel_angle>=70 && accel_angle<=90)
  	{
    		value=7;
    		od=value;
  	}
  	else{
    		if(od==0){
      			value=5;
    		}
    		else{
    			value=od;}
  	}
}

mySerial.println(value);

Serial.println(value);

delay(1000);



}

Credits

VARUN SHARMAN 1660484

VARUN SHARMAN 1660484

3 projects • 8 followers
A thinker, developer, and designer; continually re-imagining what’s possible to help bring in a change in the world.
Jival Jenson

Jival Jenson

0 projects • 5 followers
Shijith Mathew

Shijith Mathew

0 projects • 6 followers
SERAH VARGHESE 1660441

SERAH VARGHESE 1660441

0 projects • 2 followers
FALGUNI RATHORE 1660442

FALGUNI RATHORE 1660442

0 projects • 1 follower

Comments