So when I started this contest I had thebiggest expectations: seen here. Now obviously, that's not the project I'm submitting. While the scope of this project is a lot smaller than that originally proposed. I could also sit here all day and give excuses for not living up to the height of my expectations; but I am not going to do that. Instead I am here to convince you that my project is a great showcase of what the particle is capable of.
Coming up with the idea.<cliché> So I was laying in bed and suddenly it hit me </cliché> not even a joke I had the idea to use haptic feedback to test distance. but what would make a good target audience for a device that lets you feel the world around you. Aha! blind people!! they like cant see and stuff... right? wait. Its not like I have access to blind people though... well I can always worry about that after I build the project.
Building the device.I will structure the build of this device as a tutorial. Now; the first thing I did and you should do if you want to build this for yourself is to attach the distance sensor and check that it is working.
to attach it the vcc pin on the hc-sr04 should go to the usb pin on the particle. likewise, "trig" goes to pin a0, echo goes to sda and "gnd" should go to your ground pin on the particle. if done right this step should look like this
Does that look right? Great! Lets finish the circuit and get to coding! The last thing to add is the haptic feedback. attach the positive lead to pin A1 and attach the negative lead to "gnd" here's the final picture of the circuit.
Now that you have the circuit made, lets write the code!
writing the code.The source code for this app can be found at the end of the article along with the parts list. but for now lets go over what the code does and how to modify it to suit your needs.
#include "HC-SR04.h"
// trigger / echo pins
const int triggerPin = A0;
const int echoPin = D0;
const int vibrapin = A1;
HC_SR04 rangefinder = HC_SR04(triggerPin, echoPin);
void setup()
{
Serial.begin(9600);
rangefinder.init();
}
void loop()
{
unsigned long start = micros();
float inch = rangefinder.distInch();
unsigned long calcTime = micros() - start;
Serial.printf("Range finding duration: %lu | Distance in inches: %.2f\n", calcTime, inch);
delay(100);
if (calcTime <= 45500) {
digitalWrite(vibrapin, HIGH);
delay(200);
digitalWrite(vibrapin, HIGH);
}
}
the above code is the entirety of the project
it checks if you are at or within 2.5 ft and if so turns on the vibrator for a small amount of time. for debug purposes it also draws the distance and range to the serial which was invaluable in debugging this project
sadly I was not able to get this working with my motor but was able to get it working with a led.
final thoughts.This was made in like 2 weeks by an early teen. It has already shown its usefulness in some small extents. Imagine what could happen if an adult with more experience made my project better.
That is why I grant free of charge to anyone, 100% irrevocable rights to do whatever you want with my code. just credit me. :p anyways that's what I can make with my time using particle. what can you?
Comments