Project tutorial
Hacking STEM Flex/Pressure Sensor

Hacking STEM Flex/Pressure Sensor

A simple, low-cost flex and pressure sensor!

  • 7 views
  • 0 comments
  • 0 respects

Components and supplies

Necessary tools and machines

Apps and online services

About this project

This is one of our favorite sensors! Originally designed as a low-cost physical interface for robotics, this simple pressure and flex sensor has found its way into an wide variety of projects!

Our sensor uses velostat, a piezoelectric material that changes resistance based on pressure, and copper tape sandwiched between two pieces of cardstock. Using this basic design, you can create different shapes and sizes to fit your specific needs. Long, narrow pressure sensors are great as finger flex sensors, while square pads are better for detecting and measuring changes in relative pressure.

Here is a quick overview on how to build the pressure sensor:

Once you have built your sensor, connect it to Arduino, micro:bit, or another microcontroller that can print data to the serial monitor. Then write a simple program to read the analog value of the sensor and print it to serial (or use ours included in the next step!). Finally, open Excel and enable Data Streamer to get real-time pressure and flexion data!

Full build instructions for the sensor and a custom Excel workbook can be found here: https://www.microsoft.com/en-us/education/hackingstem/pressuresensor

Please reach out to us if you have any questions. Once it's up and running, we would love to see your creations and applications with this sensor, so please share away!

Happy making!

Code

Pressure SensorArduino
An Arduino sketch that reads in analog data from a pressure sensor and prints into Excel via the Data Streamer add-in.
// ----------------------------------------------------------------------------
// Pressure Sensor Code for use with the Sensor Library Materials
// available from Microsoft Education Workshop at http://aka.ms/data-streamer 
// 
// This project uses an Arduino UNO microcontroller board. More information can
// be found by visiting the Arduino website: 
// https://www.arduino.cc/en/main/arduinoBoardUno 
//  
// This code reads in analog voltage from a pressure sensor on pin A0
// then prints the data to an Excel workbook via the Data Streamer add-in.
// 
// Comments, contributions, suggestions, bug reports, and feature requests 
// are welcome! For source code and bug reports see: 
// http://github.com/[TODO github path to Hacking STEM] 
// 
// Copyright 2019, Jen Fox, Microsoft EDU Workshop - HackingSTEM 
// 
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights to
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
// of the Software, and to permit persons to whom the Software is furnished to do
// so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 
// SOFTWARE. 
// ----------------------------------------------------------------------------

// Program variables ----------------------------------------------------------
int exampleVariable = 0;
int sensorPin = A0;

// Serial data variables ------------------------------------------------------
const byte kNumberOfChannelsFromExcel = 6; //Incoming Serial Data Array
// IMPORTANT: This must be equal to number of channels set in Data Streamer

const char kDelimiter = ',';    // Data Streamer expects a comma delimeter
const int kSerialInterval = 50;   // Interval between serial writes
unsigned long serialPreviousTime; // Timestamp to track serial interval

char* arr[kNumberOfChannelsFromExcel];

// SETUP ----------------------------------------------------------------------
void setup() {
  // Initializations occur here
  Serial.begin(9600);  
}

// START OF MAIN LOOP --------------------------------------------------------- 
void loop()
{
  // Process sensors
  processSensors();

  // Read Excel variables from serial port (Data Streamer)
  processIncomingSerial();

  // Process and send data to Excel via serial port (Data Streamer)
  processOutgoingSerial();

//   if ( strcmp ("Apple", arr[0]) == 0){ // Compares STR1 to STR2 returns 0 if true.
//       Serial.println("working");
//   }
}

// SENSOR INPUT CODE-----------------------------------------------------------
void processSensors() 
{
  // Add sensor processing code here
  exampleVariable = analogRead( sensorPin );
}

// Add any specialized methods and processing code here

// OUTGOING SERIAL DATA PROCESSING CODE----------------------------------------
void sendDataToSerial()
{
  // Send data out separated by a comma (kDelimiter)
  // Repeat next 2 lines of code for each variable sent:

  Serial.print(exampleVariable);
  Serial.print(kDelimiter);
  
  Serial.println(); // Add final line ending character only once
}

//-----------------------------------------------------------------------------
// DO NOT EDIT ANYTHING BELOW THIS LINE
//-----------------------------------------------------------------------------

// OUTGOING SERIAL DATA PROCESSING CODE----------------------------------------
void processOutgoingSerial()
{
   // Enter into this only when serial interval has elapsed
  if((millis() - serialPreviousTime) > kSerialInterval) 
  {
    serialPreviousTime = millis(); // Reset serial interval timestamp
    sendDataToSerial(); 
  }
}

// INCOMING SERIAL DATA PROCESSING CODE----------------------------------------
void processIncomingSerial()
{
  if(Serial.available()){
    parseData(GetSerialData());
  }
}

// Gathers bytes from serial port to build inputString
char* GetSerialData()
{
  static char inputString[64]; // Create a char array to store incoming data
  memset(inputString, 0, sizeof(inputString)); // Clear the memory from a pervious reading
  while (Serial.available()){
    Serial.readBytesUntil('\n', inputString, 64); //Read every byte in Serial buffer until line end or 64 bytes
  }
  return inputString;
}

// Seperate the data at each delimeter
void parseData(char data[])
{
    char *token = strtok(data, ","); // Find the first delimeter and return the token before it
    int index = 0; // Index to track storage in the array
    while (token != NULL){ // Char* strings terminate w/ a Null character. We'll keep running the command until we hit it
      arr[index] = token; // Assign the token to an array
      token = strtok(NULL, ","); // Conintue to the next delimeter
      index++; // incremenet index to store next value
    }
}

Schematics

Arduino Schematic
Use the wiring diagram to connect your homemade or commercial pressure sensor to an Arduino Uno.
Uploads2ftmp2f9ad48078 2691 41d3 bcc4 cd7e2f820ff62farduinoschematic b5hzravtur

Comments

Similar projects you might like

DHT11 Temperature/Humidity Sensor

Project tutorial by Zachary Haslam

  • 36,404 views
  • 3 comments
  • 48 respects

Temperature sensor

Project tutorial by Grant

  • 21,502 views
  • 6 comments
  • 36 respects

Simple Obstacle Sensor with Arduino

Project tutorial by muhammed shameel k.v

  • 8,583 views
  • 2 comments
  • 11 respects

Displaying Sensor Values on LCD

by Wimpie van den Berg

  • 59,846 views
  • 5 comments
  • 43 respects

Ultra-Sonic "Ping" Sensor

by MicroBob

  • 30,229 views
  • 6 comments
  • 40 respects
Add projectSign up / Login