Arduino temperature and FSR sensor

Here, we discover the use of other sensors with Arduino. The FSR and temperature sensors are used in conjunction to capture both pressure and temperature information. The temperature sensor used here is a solid-state non-contact type of sensor, which measures the radiation of a heat source through changes in the base-emitter junction of the transistor. Therefore, the amplitude of the signal is proportional to the changes in the temperature. The FSR (Force Sensitive Resistor) is a passive contact type of sensor, which measures the weight through physically asserting pressure to change the resistive value. Therefore, the resistance is inversely proportional to the force applied to the FSR.

Schematic: Arduino Script:

const int FSR_PIN = A1;
const float VCC = 4.98;
const float R_DIV = 1000.00;

const int tempPIN = A0;
const int LEDR = 8;
const int LEDG = 10;

void setup() {
Serial.begin(9600);
pinMode(FSR_PIN, INPUT);
pinMode(tempPIN, INPUT);
pinMode(LEDR, OUTPUT);
pinMode(LEDG, OUTPUT);
}

void loop() {

{
float fsrR = R_DIV *((VCC - fsrV) / fsrV); //from voltage divide equation

float tempV = tempADC * VCC / 1023; // 10 bit
float degC = tempV / 0.01; // LM35 transfer function Vout = 10 mV/C * Temp

if (degC = 23)
{
digitalWrite(LEDR, HIGH);
delay(250);
digitalWrite(LEDR, LOW);
delay(250);
}
else
{
digitalWrite(LEDG, HIGH);
delay(250);
digitalWrite(LEDG, LOW);
delay(250);
}
Serial.print("Reistance: " + String(fsrR) + " ohms");
Serial.println(" Deg: " + String(degC) + " C ");
}
}

Python plot script:

import serial #Library for serial comm
import numpy as np #Library for array
import matplotlib.pyplot as plt #Library for plotting
from drawnow import *

arduinoData = serial.Serial('com3', 9600)
Tarray = [] #empty array for arduino data
Rarray = []
plt.ion() #Tell matplotlib you want interactive mode to plot live data
cnt = 0

def makeFig(): #create function to make plot
plt.ylim(20, 30)
plt.title('My real-time sensor data')
plt.grid(True)
plt.ylabel('Temp C')
plt.xlabel('N point')
plt.plot(Tarray,'ro-', label='Degrees C')
plt.legend(loc='upper left')

plt2 = plt.twinx() #create twin of plt
plt2.plot(Rarray, 'b^-', label='Resistance ohm')
plt.ylim(2800,3000)
plt2.set_ylabel('Resistance ohms')
plt2.legend(loc='upper right')
plt2.ticklabel_format(useOffset = False) #Force matplotlib to not autoscale yaxis.

while True: #While loop that loops forever
while(arduinoData.inWaiting() == 0): #Wait until there is data
pass #do nothing
dataArray = arduinoString.split(',') #split into array
R = float(dataArray)
T = float(dataArray)
Tarray.append(T) #build array
Rarray.append(R)
drawnow(makeFig) #call function
plt.pause(0.000001) #pause drawnow for short time
cnt = cnt + 1
if (cnt = 50):
Tarray.pop(0)
Rarray.pop(0)

Testing:

• Measure the temperature from temperature sensor and the resistance from the FSR. We are unable to convert to resistance to force because we don’t have weights to perform the calibration.
• The temperature is relatively stable at 25 C, while the resistance has a higher fluctuation.  