Juliette van der Pas
Published © CC BY

Measuring Stretch Forces With A Conductive Rubber Cord

Monitor stretch forces using Adafruit's conductive rubber cord and a NodeMCU ESP8266. We'll encode the output to a JSON string.

IntermediateProtip1 hour9,413
Measuring Stretch Forces With A Conductive Rubber Cord

Things used in this project

Hardware components

Adafruit Conductive Rubber Cord Stretch Sensor
×1
Jumper Wires with Alligator Clips
×2
Resistor 10k ohm
Resistor 10k ohm
×2
NodeMCU ESP8266 Breakout Board
NodeMCU ESP8266 Breakout Board
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Schematics of Conductive Rubber Cord Stretch Sensor

Attached to ESP 8266

Code

Conductive Rubber Cord Stretch Sensor Code full

Arduino
Code provides an easy way to calculate the voltage and resistance from a rubber stretch sensor. It also shows a way to encode the output to JSON using the ArduinoJson library.
   #include <ArduinoJson.h> 
   
   //This should be the same value of the used resistor  
   #define RESISTOR 10000 
   
   //This is the pin where the cord is connected to
   #define RUBBERCORDPIN A0  
   
   int raw = 0;           // Raw input value
   int vin = 5;           // Store input voltage, this should be 5
   float vout = 0;        // Store output voltage
   float refresistor1 = 10;  // Variable to store the R1 value
   float refresistor2 = 0;  // represents unknown resistor. Code                                     //will determine what value it is after the                                // voltage that falls across it has been measured
   float buffer = 0;    // buffer variable for calculation
      
   void setup(void) { 
     Serial.begin(9600); 
   } 
   
   void loop(void) { 
     ///////////////////ANALOGUE READINGS////////////////////
     int value; 
     value = analogRead(RUBBERCORDPIN); //Read value
     //Serial.print("Analog reading ");  
     //Serial.println(value); //Print value
     //delay(1000); 
      
      /////////////CALCULATE VOLTAGE AND RESISTANCE/////////
     //Source of following code: 
     //http://learningaboutelectronics.com/Articles/Arduino-ohmmeter.php
     vout = (5.0 / 1023.0) * value; // Calculates the voltage on the input PIN
     buffer = (vin / vout) - 1;
     refresistor2 = refresistor1 / buffer;
     
     //Print to serial monitor for debugging
     //Serial.print("Voltage: ");    
     //Serial.println(vout); //Outputs the information
     //Serial.print("Resistance: ");        
     //Serial.println(refresistor2);           
     delay(1000);

    ///////////////////ENCODE TO JSON/////////////////////
    //We need to reserve memory space first. 
    // It is preferred to use DynamicJsonBuffer and not StaticJsonBuffer 
    //for boards like ESP8266
    DynamicJsonBuffer jsonBuffer; 
     
     // Next we build our object tree in the reserved memory 
     // You can also add strings, integer, booleans, etc: 
     JsonObject& root = jsonBuffer.createObject(); 
     root["resistance"] = refresistor2; 
     root["voltage"] = vout; 

     //Generate the JSON string
     //prettyPrint gives us nice indention in the serial monitor. 
     //Use printTo in production, that's smaller.  
     root.prettyPrintTo(Serial); 
     
   } 

Credits

Juliette van der Pas

Juliette van der Pas

2 projects • 20 followers

Comments