Enter Your Electronics & Design Project for a chance to win a $100 Shopping Cart! | Project14 Home | |
Monthly Themes | ||
Monthly Theme Poll |
Introduction & Idea
Hi, this will be my entry for the Wearable Tech competition. For this competition I wanted to design and make something that I will actually be using on a daily basis. The idea for my project are smart Bluetooth gloves, and here is how that idea came to life. Since it's winter it got pretty cold and also snowing here where I live. My daily commute includes a fair bit of walking plus public transport so I almost at all times have earphones in my ears listening to either music or audiobooks. All of the cold weather means I am usually wearing gloves and changing songs or adjusting the volume has become a hassle since my jacket is covering the pocket where my phone is, the earphone button is deep inside my jacket and so on. Plus trying to get the phone out while on icy surfaces can go wrong real fast. So I thought why not make a pair of smart gloves which could communicate via Bluetooth with my phone. The basic Idea is having gloves which can do the simplest of function, play/pause songs, next/previous song, volume up/down, and answering calls. The play/pause, and answering calls can be easily done with the use of the earphone button, so my first thought was to emulate that button and so on. I'll go now through the concept, prototypes and testing that in the end left me with something I plan on using on a daily basis.
Design & Concept
My first idea was mounting physical buttons to the gloves, while doable that just didn't seem like a neat enough solution for what I wanted. While looking around I found one really cool method that uses a Thermal array sensor for gesture controls, but the sensor itself is really expensive at the moment, and wouldn't make much sense for me to put it on a pair of gloves. I also thought of maybe using a combination of gyroscope + accelerometer for gesture controls, but again that seemed a little bit too complex to program to be intuitive and usable without falsely detecting gestures. The goal was designing something that is as intuitive but I also wanted to avoid physical buttons and stuff like that as much as possible. So in the end I came up with an idea of using a small magnet and hall effect sensors. Hall effect sensors (switches in my case more precisely) are great tiny components which are triggered with a magnetic field. The idea was arranging the hall effect sensors in a 3X3 grid and swiping a small magnet which would be in the fingertip of the other glove. By searching around and reading about them, this seemed like a possible solution so I went and gave it a try! Here is how the first prototype went down!
First Prototype
With the idea and concept sorted it was time to get to work. I went bought a dozen hall effect sensors and some prototype boards and started playing around with them. One more great thing about the hall effect sensors is they are really cheap. The ones without the board, so just the sensor itself, go for around 0.3$ a piece, but can't be found even cheaper than that easily. For the brain of the whole project I decided to go with an Arduino Nano, since it is a really compact board, with a lot of pins, and also doesn't cost that much, since my goal is to make something that anyone can easily make without spending too much. There are a lot of great tutorials online for hall effect sensor and Arduino, so I started going through them, all I needed was to get one sensor working as a switch and I would be set for the rest of the project, so let's start off with that.
Hall Sensor - First Test
By looking through a lot of tutorials I saw a few different approaches. Tested out a lot of them, but most didn't do for me what I wanted. I saw a lot of people also using interrupt pins which I wanted to avoid if I could. So in the end the method which proved to work perfectly for me is this which requires a single 10K resistor for each hall sensor. Here is how the connection looks like:
In this configuration, the sensor worked precisely as I wanted to, which is like a small button. With this part finished all that was left is to make a small board with 9 of these soldered to it, so that will be my next step in this build.
Making the 3X3 Grid
For the most part this was a pretty straight forward build with only 2 things to consider and that is what kind of connectors to use, which turned out to be only one option that I could find locally, as well as the size of the board itself. The goal was for the user not the notice that there is anything in the glove, but also I didn't want to make it impossible to use. By putting different sized board in one of my gloves which I picked for this project, I ended up with the size of around 4x4cm. I couldn't feel the board at all, but it also looked like pretty easy to use. So here is how the soldering process went:
{gallery} Hall sensor grid |
---|
Top Side: The top side of the board came out really clean |
Bottom Side: This is the bottom side before all of the connecting wires we put |
Finished grid: 8 out of 9 sensors worked perfectly, while one of them wasn't responding as it should. All of the connections are fine, but it possible got damaged from me heating it too much, or it didn't work from the beginning since I didn't test them all at the start. |
That would wrap up building the small grid, next thing to tackle would be Bluetooth.
Bluetooth - Arduino Side
The obvious contender for this would be the HC-05 or HC-06 Bluetooth module and I went with the HC-05. I've worked with module before so I thought it would be a simple straight forward job, but boy oh boy was I wrong. I connected the HC-05 using a voltage divider on the module RXD pin, since the board requires 3.3V for communication and downloaded a few different apps to test out if everything worked. It didn't. Using my phone I could see the Bluetooth device, and pair with it, but as soon as I tried connecting to it in any of the apps (which worked for me before) I would get an error could not connect to device. I spent hours upon hours of trying to troubleshoot this, went through all of the commands on the Bluetooth module, which all gave me responses that the module worked correctly. I went and bought a new Bluetooth module HC-06 not even thinking about it could be a problem with the phone. Tried the new module, same as with the old one. Then finally I tried troubleshooting the phone where everything seemed fine, but the things is, other phones were connecting properly to the modules without a single problem. I went and deleted all of the apps that had anything to do with Bluetooth on my phone, and that did the trick! The moment I saw the firs byte of data come from Bluetooth I was extremely happy knowing that I can actually continue on with the project! I still don't know what caused the problem but everything works great now. Here is how I connected and how I established communication between the Bluetooth module and the Arduino.
The voltage divider is made out of a 2K and 1K resistor. Communicating with the Bluetooth module HC-05 using an Arduino is really simple, since the module is connected to the Serial pins on the Arduino, all we need to do is read and write to the Serial to communicate with the module. The baudrate can differ from module to module, by reading the datasheets on these modules, most of them are in mode for accessing their commands at 38400, and for communicating at 9600. For the module that I own the baudrate that works is 38400, so that is just something to keep in mind if it doesn't work straight up. Also another important thing is to disconnect everything from the Arduinos RX and TX pins when uploading the sketch, or the upload will hit an error.
Android app
The next step is tackling the Android side of the project. There are 2 parts to this app which I later merged into one, one side of the project is controlling the volume,media and so on, and the other side is establishing a Bluetooth communication with the HC-05 and reading the data we get from it.
Media Control
This is the first part I tackled and arguably the much much easier part of the two. There is a lot of great documentation for this. To do this, I used android.media.AudioManager and and android.view.KeyEvent. Simply said, to control the things I wanted to control I had to create an AudioManager instance and use it's inbuilt functions dispatchMediaKeyEvent and adjustVolume. Here is how that part of the code look liked:
//.... AudioManager audioManager = null; Button button = null; KeyEvent mediaButton = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE); //... @Override protected void onCreate(Bundle savedInstances){ //... setVolumeControlStream(AudioManager.STREAM_MUSIC); button = (Button) findViewById(R.id.button); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view){ audioManager.dispatchMediaKeyEvent(mediaButton); } }); //...
The above code is all that's needed to simulate a media key (the earphone button). In the documentation is says that there should be key down and key up actions, but for me that gave a double click, so I just used key down and everything works great. For adjusting volume the principle is completely the same just instead of the disptachMediaKeyEvent when the button is clicked we use audioManager.adjustVolume(AudioManager.ADJUST_LOWER,AudioManager.FLAG_PLAY_SOUND); Here are some of the key events that are out there:
- KeyEvent mediaButton= new KeyEvent(KeyEvent.ACTION_DOWN,KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE); //Media button
- KeyEvent play = new KeyEvent(KeyEvent.ACTION_DOWN,KeyEvent.KEYCODE_MEDIA_PLAY); //Media Play
- KeyEvent pause = new KeyEvent(KeyEvent.ACTION_DOWN,KeyEvent.KEYCODE_MEDIA_PAUSE); //Media Pause
- KeyEvent next = new KeyEvent(KeyEvent.ACTION_DOWN,KeyEvent.KEYCODE_MEDIA_NEXT); //Next song
- KeyEvent previous = new KeyEvent(KeyEvent.ACTION_DOWN,KeyEvent.KEYCODE_MEDIA_PREVIOUS); //Previous song
And for adjusting volume, as shown in the above code, we can increase the volume using the same thing:
- audioManager.adjustVolume(AudioManager.ADJUST_RAISE, AudioManager.FLAG_PLAY_SOUND); //Raising the Volume
- audioManager.adjustVolume(AudioManager.ADJUST_LOWER, AudioManager.FLAG_PLAY_SOUND); //Lowering the Volume
- audioManager.adjustVolume(AudioManager.ADJUST_MUTE, AudioManager.FLAG_PLAY_SOUND); //Mute
- audioManager.adjustVolume(AudioManager.ADJUST_UNMUTE, AudioManager.FLAG_PLAY_SOUND); //Unmutes
- audioManager.adjustVolume(AudioManager.ADJUST_TOGGLE_MUTE, AudioManager.FLAG_PLAY_SOUND); //Toggles mute
To test this out, I just put a few buttons and ended up with an app that can control media without a problem, could be a useful thing, if the physical buttons go bad someday.
Bluetooth - Android
A few years go a friend and I had a project which included Bluetooth for Android and no matter what we did, we couldn't get it to work properly. I've looked around the net now and found this https://github.com/MEnthoven/Android-HC05-App.This was made by Maarten Enthoven, he did a really exceptional job of making an app that find, pair, connect to a Bluetooth device, and send/receive data and furthermore he put the whole source code on GitHub so anyone can see and use it. So I want to begin this part by saying thanks to him, because this made everything so much easier. I downloaded and ran his code on my phone, and it worked instantly without any problems, I could send and receive data over Bluetooth! That would wrap up the part that utilizes Bluetooth so all that's left is to merge the 2 into one.
To merge the 2 into one all I did was build on top of the working Bluetooth app. Since Arduino will be doing all of the gesture interpretation, all the app has to do is read the code sent by the Arduino and perform the given function wheter that's adjusting volume, or changing a song. To do this I went through the Bluetooth app code and found the place which to me looked like where the received message was printed out on the screen. I intercepted the message before printing and checking if the value matches some of the gestures I wanted, and then just did the function if it did. I put my code in BluetoothActivity.java in public void handleMesssage(Message msg) in the case Constants.MESSAGE_READ:, here is how that looked like:
case Constants.MESSAGE_READ: String readMessage = (String) msg.obj; if(readMessage != null && activity.showMessagesIsChecked){ ChatMessage messageRead = new ChatMessage(activity.device.getName(), readMessage.trim()); if(readMessage.trim().startsWith("#987")){audioManager.dispatchMediaKeyEvent(mediaButton);} if(readMessage.trim().startsWith("#741")){audioManager.adjustVolume(AudioManager.ADJUST_RAISE, AudioManager.FLAG_PLAY_SOUND);} if(readMessage.trim().startsWith("#258")){audioManager.adjustVolume(AudioManager.ADJUST_LOWER, AudioManager.FLAG_PLAY_SOUND);} if(readMessage.trim().startsWith("#123")){audioManager.dispatchMediaKeyEvent(next);} if(readMessage.trim().startsWith("#321")){audioManager.dispatchMediaKeyEvent(previous);} activity.addMessageToAdapter(messageRead); } break;
With this the Android app part of the project is finished for now. Next on the list is the Arduino.
Arduino
As I've already said, my board of choice is the Arduino Nano, since it has a lot of pins, is small and doesn't cost much. To communicate with the HC-05 I will be using the first two pins on it, the RX and TX pins which are used for serial communication (Whenever uploading a sketch to the Arduino make sure that those pins are disconnected from everything). The other connections for this project are straight forward, I dedicated one pin to each of the hall sensor output pins, where they are all connected as I've shown above, I've connected sensors from pin 2 and just continued upwards. The small hall sensor board is powered by the 5V coming from the Arduino and the HC-05 keeps it's connections as I've shown above. One last thing left is powering the whole device. For the first prototype I haven't sorted out this properly so I just went with a standard 9V battery which is pretty big. I thought it would cause problems, but honestly when the glove was on I couldn't feel it at all which was great. Here is the code for the Arduino:
const int sensorPin[9]={2,3,4,5,6,7,8,9,10}; int sequence[20]={0}; //Array for storing the sequence at which the hall effect sensors are triggered int currentState[9]={0}; //Current sensor state int previousState[9]={0}; //Previous sensor state int i=0; //Array position bool sequenceOver=false; //Flag for if we're done recording the sequence int timeThreshold=500; //Number of miliseconds of no activity after which the sequence will be looked at as finished unsigned long timerReset; bool sequenceStarted=false; String code="#"; void setup() { Serial.begin(38400); //The Baudrate at which my Bluetooth module worked pinMode(sensorPin[0],INPUT); //Setting up all of the pins pinMode(sensorPin[1],INPUT); pinMode(sensorPin[2],INPUT); pinMode(sensorPin[3],INPUT); pinMode(sensorPin[4],INPUT); pinMode(sensorPin[5],INPUT); pinMode(sensorPin[6],INPUT); pinMode(sensorPin[7],INPUT); pinMode(sensorPin[8],INPUT); } void loop() { if(!sequenceOver){ for(int j=0;j<9;j++){ currentState[j]=digitalRead(sensorPin[j]); if(currentState[j]!=previousState[j]){ if(currentState[j]==0){ //Serial.println(j+1); sequence[i++]=j+1; timerReset=millis(); previousState[j]=0; sequenceStarted=true; } else{ previousState[j]=1; } } } if(millis()-timerReset>=timeThreshold){ if(sequenceStarted){ sequenceOver=true; } } } else{ for(int k=0;k<20;k++){ code+=sequence[k]; //Serial.print(sequence[k]); //Serial.print("."); sequence[k]=0; } for(int k=0;k<9;k++){ currentState[k]=0; previousState[k]=0; } //Serial.println(); sequenceOver=false; sequenceStarted=false; timerReset=millis(); i=0; Serial.println(code); code="#"; } }
So here is how this code works. I needed a way to determine if the user was done with inputing a sequence or not, to do this I assumed that if any of the sensors is activated, or multiple of them activated, if there is a break of half a second with no activity that the user is done entering the sequence. As it can be seen from this code and the Android app code, for triggering functions I required the user to enter a specific sequence which I will talk about later in the summary for the first prototype. As for the rest of the code, it just adds the sensor number to a sequence as they are triggered and as I've said, if nothing happens for half a second the Arduino will assume we are done with entering the sequence and will go convert the code to a string and send it via Bluetooth to the Android app.
Test
All that's left to do now is test out how everything works. I powered up the glove, started the app and here are the results I got:
As it can be seen in the Android code, the #123 is next song, #321 is previous, #741 is volume up, #258 is volume down and #987 is media button. Everything worked great and as expected! Here is a picture of the glove (which I managed to cut slightly on accident while putting the components in), the small green dot that can be seen is the HC-05 LED.
I'll have videos of all of this at end of blog to not clutter up the whole blog!
Summary
And with that the first prototype for this project is complete! But as every first prototype it has a lot of things that need to be worked on. The glove itself works perfectly as I intended it to, but I didn't address some things properly which ruin the glove a bit, or make the whole project pretty pointless, in no particular order here all of those things in no particular order:
- Waterproofing
- These are gloves after all, they are supposed to keep hands warm in all conditions, of course I won't be soaking this into water but, this is the area where I plan on improving in the second prototype a lot. I could have went with skiing glove which are pretty water resistant, but my goal is making something I can use on daily basis. I've protected the circuits a bit but won't even count that, this will be addressed properly in the next prototype
- Battery
- I plan on using LiPo/LIon batteries, but I won't put this as a high high priority for now since it doesn't bother me that much, but is something that should be addressed for sure
- Gestures
- I hardcoded gestures so that the user has to hit an exact sequence every time he wants to do anything. I made those sequences to be in intuitive directions but some sensor can be missed or another triggered by mistake so it's not completely user friendly. I will tackle with this by using directions, since I don't have that many function that I want to cover, raising volume will be any gesture that goes up, lowering volume any sequence that goes down and so on. This will be an easy fix, but one that will make the device much much more usable.
- Android app
- The app does all of the things that I want to, but only when it's on. In other words, I need to find a way to keep the app running in the background and when the screen is off so the gloves are actually a usable product
- Magnet placement
- This is an easy fix, but one that will be an improvement nevertheless, initially, my idea was the magnet to be in the top of the index finger, but I will be changing that to the fourth finger. The reason for this is that magnets are known to damage screens and destroy all type of credit cards, while I am using a really small magnet, by putting it in the fourth finger which is almost never used to grab a card or touch the screen directly, I will be avoiding this problem.
- Other
- One more thing I wish to address is the positioning of the sensor board by tying it down a bit in the glove, since it moves around a lot now, and the sensors are never where you left them
That would be it for the first prototype, I'm gonna call it a great success since it does all of the things I want it to, but it needs a couple of touches for it to become a usable device for me. I will be trying to address all of the problems with the first prototype in the second prototype!
Second Prototype
Time to start on the second prototype! Since the first prototypes main functions worked great, I won't be making everything from the beginning, but rather upgrading the first prototype. First thing I tackled was waterproofing and here is how I managed that:
Waterproofing
Since these are gloves at the end of the day, I will be wearing in cold weather for the most part, with of course, the possibility of it raining/snowing. I won't be submerging them in water or anything like that, and in the season when I am wearing them it is usually snowing which is better than if it were raining for electronics. Nevertheless, I wanted to protect the electronics inside the best as I could without compromising the usability and size of the components (going with bulky enclosures etc). Naturally, I tried using some duct tape at first and honestly it worked pretty well but wanted to just add a little bit more, and then reinforce with duct tape if it's needed anywhere. My solution came in the form of an inflatable beach ball. This may sound a bit weird at first, but we are talking about a material which is designed to hold air, so why couldn't it be used to hold water out? With the material sorted the next thing on the list was making enclosures for the components. I experimented here a bit with various different techniques from sewing to gluing, but in the end a mix of many things appeared to be the best option. I found an old bag sealing machine which nobody was using (heats a wire which then melts the bag and creates a great seam). The material I used was a lot thicker than the bags, but it actually turned out great. Here are some pictures of the process:
{gallery} Waterproofing |
---|
Material: The small sensor board and the bag I started making for it |
Protected sensor board: The sensor board in it's water resistant cover |
Protected HC-05: HC-05 in its protective cover |
While this doesn't guarantee me any safety, it will be well protected from initial water droplets, at the ends where the wires are coming out I used a bit of double sided sticky tape to try and keep it closed, but will probably add some glue further on. Over this layer I will be adding on some parts a layer of duct tape, since I can sew into it and keep the components from moving around. That would be the first of the things addressed in the second prototype, next on is the power supply for the device.
Battery & Charger
For the first prototype I used a pretty bulky 9V battery, which worked great, but it's size and the fact that you can't charge it meant I had to change it. Instead of that battery I opted out on using one of the spare batteries I have for my old action cam. It's a 3.7V 1050mAh Li-ion battery. I already have a charger for it, but I had to modify it for charging the glove, which I will show soon, and besides that I added a small circuit to regulate the voltage at 5V as well as a micro USB port which will be used for charging with the circuit.
Disclaimer: To connect everything I soldered the wires directly to the pads of the battery which can be very dangerous! I worked with what I had and don't recommend or advise anyone doing this!
I connected everything, removed the big USB port, and added a small switch between the battery and regulator circuit. After that I added the water resistant cover and ended up with this:
{gallery} Battery |
---|
Components: The battery, micro USB port and the regulator circuit |
Everything connected: Assembled battery |
Comparison: Comparison with the 9V battery, while it doesn't look like a big of a difference in size, it is significant, because the new battery is much thinner which was the problem with the first one, and of course this one can be charged |
Finished battery: And here is the battery with the water resistant cover, one thing I am thinking about is maybe adding a small switch for charging, so if the water gets into the connector, which I wont be able to protect that good, the battery won't be ruined. |
That would wrap up the battery part, all that's left is to modify the charger that I have for these batteries.
The charger itself works by connecting it to a standard 5V phone charger via micro USB. To modify it so I can use it for the gloves as well I've added a USB port to the output of the charger so I can connect it to the battery module using a standard cable, here is how that went:
{gallery} Charger |
---|
Stock Charger: This is how the stock charger looks like without me having done anything to it |
Stock Charger: The other side of the stack charger, where the USB cables comes in from the phone charger |
Modded charger: Not so carefully with side cutters, I made a hole big enough to fit the USB port |
Internals: A piece lifts up revealing the contacts that go to the battery, the circuit itself is in the other compartment of the charger which I didn't open because I didn't really need to |
Soldering: I just soldered 2 wires on the inside and connected them to the USB port |
Assembled: Here is how the assembled charger looks like, I put it back together with the screws it came with, with a little help of hot glue to keep the USB port from moving around when plugging in and out the cable for the battery module |
Other modifications
I had a couple of more ideas to add to this version but since time is running out I just wanted it to work again. While testing out different stuff I noticed I was getting random values on my phone, turns out the wires going to the connectors weren't really doing great. I didn't have the pliers needed to crimp them properly so I went with soldering, which obviously didn't work out as well as I've hoped it would, so in the end i broke the connectors and just soldered the wires directly to the board.
Some of the other things I've changed is that I've now attached the small magnet to the fourth finger on the right glove, since I find I won't be grabbing any credit cards or the phone screen with that finger. All that was left now was to pack everything up with of course, a little bit of duct tape!
While not the prettiest thing in this state, I layed it out so it can pretty easily fit into the glove. The bottom part on the picture is the board with the hall effect sensors which will go on top of the hand, while the rest of the electronics will go around my wrist. The duct tape added a little more protection from water and also it was easier to secure some of the stuff using duct tape. I attached the small magnet using duct tape as well, since I could thread a line through the tape and attach it that way to the glove. With all of that complete, here is what I was left with!
Testing
Summary
That would be it for the Smart Gloves V1. This was a pretty fun project that I plan on developing further. As it can be seen in the video, while the app is open, everything works incredibly well. There is a lot of tweaking I want to do, but some bigger stuff as well. The thing I really wanted to do, but didn't manage in time, was to make the app run correctly in background, I thought it would be a simple process, but man was I wrong, so that is one of the things I will be working on the most. I plan on designing a PCB to house all of the electronics, but will look into that once I test some additional features that I would like to implement. If you have any suggestions or questions please write to me! Thank you for reading the blog, hope you liked it!
Milos
Top Comments