ESP8266 - Force Sensor

This tutorial instructs you how to use ESP8266 with the force sensor. In detail, we will learn:

As a typical application, You can put your things on the force sensor, and then if the ESP8266 detects a change in force, it means someone has grabbed your belongings.

Hardware Preparation

1×ESP8266 NodeMCU
1×Micro USB Cable
1×Force Sensor
1×10 kΩ resistor
1×Breadboard
1×Jumper Wires
1×(Optional) 5V Power Adapter for ESP8266
1×(Optional) ESP8266 Screw Terminal Adapter

Or you can buy the following sensor kits:

1×DIYables Sensor Kit (30 sensors/displays)
1×DIYables Sensor Kit (18 sensors/displays)
Disclosure: Some of the links provided in this section are Amazon affiliate links. We may receive a commission for any purchases made through these links at no additional cost to you. We appreciate your support.

Overview of Force Sensor

Force sensor pinout

The force sensor is referred to as a force sensing resistor, force sensitive resistor, or simply FSR. It is essentially a resistor that alters its resistive value in response to the amount of pressure applied. The force sensor has the following characteristics:

  • It is inexpensive and simple to use.
  • It is effective at detecting physical pressure and squeezing.
  • It is not suitable for determining the weight it is bearing.

The force sensor is used in a variety of portable electronics, such as electronic drums, mobile phones, and handheld gaming devices.

The Force Sensor Pinout

A force sensor has two pins, and due to it being a type of resistor, there is no need to differentiate between them. Both pins are symmetrical.

How It Works

The force sensor is essentially a resistor that alters its resistance depending on the amount of pressure applied. The greater the pressure, the lower the resistance between the two pins will become.

Wiring Diagram

The wiring diagram between ESP8266 NodeMCU and Force

This image is created using Fritzing. Click to enlarge image

See more in ESP8266's pinout and how to supply power to the ESP8266 and other components.

How To Program For Force Sensor

We can connect the force sensor to an analog input pin of ESP8266, and then use analogRead() function to read the analog value from the pin. This allows us to determine how much the force sensor has been pressed.

ESP8266 Code

/* * This ESP8266 NodeMCU code was developed by newbiely.com * * This ESP8266 NodeMCU code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/esp8266/esp8266-force-sensor */ #define FORCE_SENSOR_PIN A0 // The ESP8266 pin ADC0: the FSR and 10K pulldown are connected to A0 void setup() { Serial.begin(9600); } void loop() { int analogReading = analogRead(FORCE_SENSOR_PIN); Serial.print("The force sensor value = "); Serial.print(analogReading); // print the raw analog reading if (analogReading < 10) // from 0 to 9 Serial.println(" -> no pressure"); else if (analogReading < 200) // from 10 to 199 Serial.println(" -> light touch"); else if (analogReading < 500) // from 200 to 499 Serial.println(" -> light squeeze"); else if (analogReading < 800) // from 500 to 799 Serial.println(" -> medium squeeze"); else // from 800 to 1023 Serial.println(" -> big squeeze"); delay(1000); }

Detailed Instructions

To get started with ESP8266 on Arduino IDE, follow these steps:

  • Check out the how to setup environment for ESP8266 on Arduino IDE tutorial if this is your first time using ESP8266.
  • Wire the components as shown in the diagram.
  • Connect the ESP8266 board to your computer using a USB cable.
  • Open Arduino IDE on your computer.
  • Choose the correct ESP8266 board, such as (e.g. NodeMCU 1.0 (ESP-12E Module)), and its respective COM port.
  • Copy the code and open it with the Arduino IDE.
  • Click the Upload button in the IDE to transfer the code to the ESP8266.
  • Press the force sensor.
  • Check the output on the Serial Monitor.
COM6
Send
Force sensor reading = 0 -> no pressure Force sensor reading = 0 -> no pressure Force sensor reading = 132 -> light touch Force sensor reading = 147 -> light touch Force sensor reading = 394 -> light squeeze Force sensor reading = 421 -> light squeeze Force sensor reading = 607 -> medium squeeze Force sensor reading = 791 -> medium squeeze Force sensor reading = 921 -> big squeeze Force sensor reading = 987 -> big squeeze Force sensor reading = 0 -> no pressure Force sensor reading = 0 -> no pressure
Autoscroll Show timestamp
Clear output
9600 baud  
Newline  

Video Tutorial

Learn More

※ OUR MESSAGES

  • As freelancers, We are AVAILABLE for HIRE. See how to outsource your project to us
  • Please feel free to share the link of this tutorial. However, Please do not use our content on any other websites. We invested a lot of effort and time to create the content, please respect our work!