Things used in this project

Hardware components:
econo wood
×2
nylon strap
×1
12757 01
SparkFun RedBoard
×1
RGB LED weatherproof flexi-strip
×1
0.5 inch diameter force sensitive resistor
×1
LSM303 triple axis accelerometer
×1
1491 00
Adafruit HUZZAH CC3000 WiFi Shield with Onboard Antenna
×1
9 V batteries
×2
N-Channel MOSFET
×3
One pair of crutches
×1
GPS Module
×1

Code

enabLEDgps.inoINI
Arduino GPS Code
#include <SoftwareSerial.h>

#include <TinyGPS.h>

/* This sample code demonstrates the normal use of a TinyGPS object.
   It requires the use of SoftwareSerial, and assumes that you have a
   4800-baud serial GPS device hooked up on pins 4(rx) and 3(tx).
*/

TinyGPS gps;
SoftwareSerial ss(4, 2);

static void smartdelay(unsigned long ms);
static void print_float(float val, float invalid, int len, int prec);
static void print_int(unsigned long val, unsigned long invalid, int len);
static void print_date(TinyGPS &gps);
static void print_str(const char *str, int len);

void setup()
{
  Serial.begin(115200);
  
  Serial.print("Starting...");
  
  ss.begin(57600);
}

void loop()
{
  float flat, flon;
  unsigned long age, date, time, chars = 0;
  unsigned short sentences = 0, failed = 0;

  gps.f_get_position(&flat, &flon, &age);
  print_float(flat, TinyGPS::GPS_INVALID_F_ANGLE, 10, 6);
  print_float(flon, TinyGPS::GPS_INVALID_F_ANGLE, 11, 6);

  Serial.println();
  
  smartdelay(1000);
}

static void smartdelay(unsigned long ms)
{
  unsigned long start = millis();
  do 
  {
    while (ss.available())
      gps.encode(ss.read());
  } while (millis() - start < ms);
}

static void print_float(float val, float invalid, int len, int prec)
{
  if (val == invalid)
  {
    while (len-- > 1)
      Serial.print('*');
    Serial.print(' ');
  }
  else
  {
    Serial.print(val, prec);
    int vi = abs((int)val);
    int flen = prec + (val < 0.0 ? 2 : 1); // . and -
    flen += vi >= 1000 ? 4 : vi >= 100 ? 3 : vi >= 10 ? 2 : 1;
    for (int i=flen; i<len; ++i)
      Serial.print(' ');
  }
  smartdelay(0);
}

static void print_int(unsigned long val, unsigned long invalid, int len)
{
  char sz[32];
  if (val == invalid)
    strcpy(sz, "*******");
  else
    sprintf(sz, "%ld", val);
  sz[len] = 0;
  for (int i=strlen(sz); i<len; ++i)
    sz[i] = ' ';
  if (len > 0) 
    sz[len-1] = ' ';
  Serial.print(sz);
  smartdelay(0);
}

static void print_date(TinyGPS &gps)
{
  int year;
  byte month, day, hour, minute, second, hundredths;
  unsigned long age;
  gps.crack_datetime(&year, &month, &day, &hour, &minute, &second, &hundredths, &age);
  if (age == TinyGPS::GPS_INVALID_AGE)
    Serial.print("********** ******** ");
  else
  {
    char sz[32];
    sprintf(sz, "%02d/%02d/%02d %02d:%02d:%02d ",
        month, day, year, hour, minute, second);
    Serial.print(sz);
  }
  print_int(age, TinyGPS::GPS_INVALID_AGE, 5);
  smartdelay(0);
}

static void print_str(const char *str, int len)
{
  int slen = strlen(str);
  for (int i=0; i<len; ++i)
    Serial.print(i<slen ? str[i] : ' ');
  smartdelay(0);
}
wifi_enabLED_crutches.inoPlain text
/*****************************************************************
This code uploads acceleration and force data from a wifi enabled
crutch to a data.sparkfun.com datastream for use. It is based on
code from the post "Pushing Data to Data.SparkFun.com" written
by Jim Lindblum and created on July 3, 2014. It is designed for
use with Sparkfun's data stream server system (phant), an
Arduino, and a CC3000 Shield. ~ Lee Hamstra


*****************************************************************/
// SPI and the pair of SFE_CC3000 include statements are required
// for using the CC300 shield as a client device.
#include <SPI.h>
#include <SFE_CC3000.h>
#include <SFE_CC3000_Client.h>
// Progmem allows us to store big strings in flash using F().
// We'll sacrifice some flash for extra DRAM space.
#include <Progmem.h>

////////////////////////////////////
// CC3000 Shield Pins & Variables //
////////////////////////////////////
// Don't change these unless you're using a breakout board.
#define CC3000_INT      3   // Needs to be an interrupt pin (D2/D3)
#define CC3000_EN       5   // Can be any digital pin
#define CC3000_CS       10  // Preferred is pin 10 on Uno
#define IP_ADDR_LEN     4   // Length of IP address in bytes

////////////////////
// WiFi Constants //
////////////////////
char ap_ssid[] = "secret";                // SSID of network
char ap_password[] = "invention";        // Password of network
unsigned int ap_security = WLAN_SEC_WPA2; // Security of network
// ap_security can be any of: WLAN_SEC_UNSEC, WLAN_SEC_WEP, 
//  WLAN_SEC_WPA, or WLAN_SEC_WPA2
unsigned int timeout = 30000;             // Milliseconds
char server[] = "data.sparkfun.com";      // Remote host site

// Initialize the CC3000 objects (shield and client):
SFE_CC3000 wifi = SFE_CC3000(CC3000_INT, CC3000_EN, CC3000_CS);
SFE_CC3000_Client client = SFE_CC3000_Client(wifi);

/////////////////
// Phant Stuff //
/////////////////
const String publicKey = "6JjNWXjGO9h4GMo3jYZ2";
const String privateKey = "WweP2qeBEgsNZ2DlGjpW";
const byte NUM_FIELDS = 2;
const String fieldNames[NUM_FIELDS] = {"acceleration", "force"};
String fieldData[NUM_FIELDS];

//////////////////////////////////////////////////////
// Accelerometer, force sensor, and LED strip setup //
//////////////////////////////////////////////////////
#include <Wire.h>
#include <Adafruit_LSM303.h>

Adafruit_LSM303 lsm;

const int RED = 6;      // Red controlled through pin 3
const int GREEN = 9;    // Green controlled through pin 5
const int BLUE = 2;     // Blue on pin 2

int red = 0;            // Variables for storing color values
int green = 0;       

const int FORCE = 0;    // Force sensor on analog pin 0
int force = 0;          // Variable to store force values
unsigned long force_data = 0;    // For storing acceleration data over time
int force_avg = 0;

int accel_x = 0;        // Initializing variable to store acceleration data
unsigned long n = 0;    // Number of times acceleration has been stored since
unsigned long accel_data = 0;    // For storing acceleration data over time
int accel_avg = 0;
unsigned long now = 0;
unsigned long then = 0;

void setup()
{
  Serial.begin(115200);

  // Set Up WiFi:
  setupWiFi();
  
  if (!lsm.begin())
  {
    Serial.println("Oops ... unable to initialize the LSM303. Check your wiring!");
    while (1);
  }
  
  // Set LED color pins as outputs
  pinMode(RED, OUTPUT);
  pinMode(GREEN, OUTPUT);
  pinMode(BLUE, OUTPUT);
  
  Serial.println("Beginning");

}

void loop()
{
  lsm.read();
  accel_x = abs((int)lsm.accelData.x);
  accel_data = accel_data + accel_x;
  force = analogRead(FORCE);
  force_data = force_data + force;
  n = n + 1;
  now = millis();
  
   // Control green value based on current acceleration
  if (accel_x < 80)
  {
    accel_x = 80;
  } else if (accel_x > 350)
  {
    accel_x = 350;
  }
  green = map(accel_x, 80, 350, 0, 255);
  
  // Adjust red according to current force
  if (force < 750)
  {
    force = 750;
  }else if (force <= 1023 && force > 900)
  {
    force = 900;
  }
  red = map(force, 900, 750, 0, 255);
  
  // set colors
  analogWrite(RED, red);
  analogWrite(GREEN, (int)green);
  
  
  if (now - then > 18000)
  {
    analogWrite(RED, 0);
    analogWrite(GREEN, 0);
    digitalWrite(BLUE, HIGH);
    
    
    accel_avg = (int)(accel_data/n);
    fieldData[0] = String(accel_avg);
    Serial.print("Average acceleration:"); 
    Serial.print(accel_avg);
    Serial.print(" ");
    
    force_avg = (int)(force_data/n);
    fieldData[1] = String(force_avg);
    Serial.print("Average force:"); 
    Serial.println(force_avg);
    
    n = 0;
    then = now;
    accel_data = 0;
    force_data = 0;
    
    // Post the data online
    postData();
    Serial.println("Posted!");
    
    digitalWrite(BLUE, LOW);
  }
  
 
  
}

void postData()
{

  // Make a TCP connection to remote host
  if ( !client.connect(server, 80) )
  {
    // Error: 4 - Could not make a TCP connection
    Serial.println(F("Error: 4"));
  }

  // Post the data! Request should look a little something like:
  // GET /input/publicKey?private_key=privateKey&light=1024&switch=0&time=5201 HTTP/1.1\n
  // Host: data.sparkfun.com\n
  // Connection: close\n
  // \n
  client.print("GET /input/");
  client.print(publicKey);
  client.print("?private_key=");
  client.print(privateKey);
  for (int i=0; i<NUM_FIELDS; i++)
  {
    client.print("&");
    client.print(fieldNames[i]);
    client.print("=");
    client.print(fieldData[i]);
  }
  client.println(" HTTP/1.1");
  client.print("Host: ");
  client.println(server);
  client.println("Connection: close");
  client.println();

  while (client.connected())
  {
    if ( client.available() )
    {
      char c = client.read();
      Serial.print(c);
    }      
  }
  Serial.println();
}

void setupWiFi()
{
  ConnectionInfo connection_info;
  int i;

  // Initialize CC3000 (configure SPI communications)
  if ( wifi.init() )
  {
    Serial.println(F("CC3000 Ready!"));
  }
  else
  {
    // Error: 0 - Something went wrong during CC3000 init!
    Serial.println(F("Error: 0"));
  }

  // Connect using DHCP
  Serial.print(F("Connecting to: "));
  Serial.println(ap_ssid);
  if(!wifi.connect(ap_ssid, ap_security, ap_password, timeout))
  {
    // Error: 1 - Could not connect to AP
    Serial.println(F("Error: 1"));
  }

  // Gather connection details and print IP address
  if ( !wifi.getConnectionInfo(connection_info) ) 
  {
    // Error: 2 - Could not obtain connection details
    Serial.println(F("Error: 2"));
  }
  else
  {
    Serial.print(F("My IP: "));
    for (i = 0; i < IP_ADDR_LEN; i++)
    {
      Serial.print(connection_info.ip_address[i]);
      if ( i < IP_ADDR_LEN - 1 )
      {
        Serial.print(".");
      }
    }
    Serial.println();
  }
}

Credits

10648390 10204488058819224 414736839847051584 o
Brian C Ly

Hi my name is Brian and I am a CS student who is interested in how technology has changed how we interact with each other.

Contact

Replications

Did you replicate this project? Share it!

Love this project? Think it could be improved? Tell us what you think!

Give feedback

Comments

Similar projects you might like

LetterBot
  • 21,794
  • 63

Work in progress

Every Home Should Have One.

Magoo
  • 5,364
  • 27

Work in progress

An obstacle-detection and GPS-enabled navigation wearable for the visually impaired.

Magoo

4 members

Open source Nest-alike learning thermostat
  • 12,717
  • 72

Full instructions

Start a $3.2 billion company by building your own learning thermostat with the Spark Core.

Magic Morse on Arduino
  • 19,625
  • 23

Full instructions

Learn or sharpen your Morse Code skills with Magic Morse implemented on Arduino!

Weather Wand
  • 9,945
  • 19

Work in progress

Magic wand to paint with color light based on temperature.

Garage Parking Sensor
  • 6,309
  • 12

Full instructions

Visual aid to parking in a two-car garage

Sign up / LoginProjectsPlatformsTopicsContestsLiveAppsBetaFree StoreBlog