Bed occupancy sensor = Force sensing resistor (FSR) + Raspberry Pi Zero WH + AnalogZero pHAT

Hey,

I just used standard cable ties like: https://www.midcoglobal.com/wp-content/uploads/MIDCO_ReversableCableTie.jpg


This was an early photo, I’ve since tightened up those cable ties as far as I can - I have each one on the same beam but on the left side or the right side (that beam you see in the pic that everything is screwed to is the central beam running from the head to the bottom of the bed - the other beams you see are running from left to right.

My mattress is very thick, and it works fine

1 Like

Thanks a lot for sharing this! I will try the same and see if it improves reporting quality.

I apologize for resurrecting an old post. There was a lot of discussion around difficulties with the FSR connections. I’m doing a similar project and found these connectors which should make FSR connections much easier and more reliable.

1 Like

Any expierience with force sensible resistors? I wanted to build a similar bed occupancy sensor as described here using a FSR and an ESP32 configured via ESP Home.
I is connected as follows:

  • One leg of the FSR is connected to the 5V output of the ESP32.
  • The other leg goes into a 10K Ohm potentiometer, which is then connected to GPIO15 (Touch).
The ESP configuration is as follows:
substitutions:
  friendly_name: Bed Occupancy

esphome:
  name: bed_occupancy
  platform: ESP32
  board: nodemcu-32s

# The Temperature sensor that is connected to D2.
sensor:
  - platform: dht
    pin: GPIO23 #D2
    model: DHT22
    temperature:
      name: "Bedroom Temperature"
      id: temperature
    humidity:
      name: "Bedroom Humidity"
      id: humidity
    update_interval: 60s

# Setting up the pressure mats
esp32_touch:
# Activate debug messages to calibrate sensor
   setup_mode: true
# Definition of pressure mats
binary_sensor:
#   - platform: esp32_touch
#     pin: GPIO14
#     name: "Bed Occupancy Left"
#     id: bed_occ_left
#     threshold: 5
   - platform: esp32_touch
     pin: GPIO15
     name: "Bed Occupancy Right"
     id: bed_occ_right
     threshold: 5
# The accumulated bed occupancy sensor
#   - platform: template
#     name: "Bed Sensor"
#     lambda: |-
#       if (id(bed_occ_left).state || id(bed_occ_right).state) {
#         return true;
#       } else {
#         return false;
#       }


wifi:
  ssid: !secret WIFI_SSID
  password: !secret WIFI_PASSWORD

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: $friendly_name Fallback Hotspot
    password: !secret ESPHOME_FALLBACK_AP_PASSWORD

captive_portal:

# Enable logging
logger:

# Enable Home Assistant API
api:
  password: !secret ESPHOME_API_PASSWORD

ota:
  password: !secret ESPHOME_API_PASSWORD

Now if I put the FSR on a table “curled up” on its side it gives readout values of about 70, no matter how the poti is positioned. As soon as I lay the FSR out flat on the table, or bed in a matter of fact, the read out drops immediatly to 0. The potentiometer again does not change this behaviour. This means currently the sensor allways evaluates to true.
How could I improve the situation? Do I need to wire it differently? Any help is appreciated.

I have a very similar setup for my bed sensors. Minus the potentiometer!

The only way i was able to get stable readings was to solder the strip and the wires onto the connector. Before that the readings would be all over the place.

It makes sense, as this is only the test setup I tried to keep it flexible using jumper wires for now. But I get a steady 0, regardless of the pressure on the bed. As the readout is steadily zero already when I even roll out the FSR on a table.

Btw: I initially had the FSR connected directly to the ESP without a poti in-between, but the result was the same.

I measured the FSR and if laid out flat on the table the restiance is in the Megaohm area, if I press on it, it is reduced to some Kiloohm or even lower. So the FSR itself is working just fine.

I have now done the following setups, all resulted in the Sensor Outputting ‘0’ and the Bed Sensor always set to ‘On’.:

  1. Direct connection:
  2. Trying to increase the total resistance:
  3. Downpull the feedback as described by martikainen87:

Admittedly I am still using simple jumper wires to test the configuration, but so far I did not even get unstable read-outs. Am I doing something wrong in the setup?

Set it up like this with Vout connected to one of the ADC inputs:

1M Ohm for R1 should give you a good range.

You should be ok with 5V as the reference voltage. As long as your FSR does not go much higher than 1M Ohm ( —> 2.5V with a 1M Ohm resistor for R1).

I think you should stop using the 5 volt pin.
The input pins on an ESP is not 5 volt tolerant, so you could damage the ESP.
Use the 3.3 volt pin instead.

Perhaps that is what has already happened?

He can use it in the example I showed as there will be a divide by 2 resistive divider.

But yeah 5V direct to a GPIO or ADC is a big no-no.

I’ve done this accidentally and the ESP survived, but there is no guarantee.

The examples he has showed will be current limited by the FSR, so probably hasn’t done any damage. :crossed_fingers:

Yes. That is a different matter.

But the first image gives me the chills. If you press hard enough then the resistance could be very low and you have a short circuit

1 Like

I have a DHT22 connected to the same ESP, which is still working. Also if I unplug the FSR (open circuit) the readout increases to some unstable number in the region of 1000. So I assume that my ESP survived sofar… Thanks for the hint :wink: I will have a go with @tom_l suggestion, when I have the time.

Could you send me a picture of what the soldering looks like?
With the FSR, it was always said that we shouldn’t solder it, but I thought that this was the only possible way as well.

I’ve tried this and it was always pulled out.

I tried the Resistance Sensor proposed.

ESPHome YAML Config
# Example configuration entry
  - platform: resistance
    sensor: source_sensor
    configuration: DOWNSTREAM
    resistor: 10kOhm
    reference_voltage: 5V
    name: Resistance Sensor

# Example source sensor:
  - platform: adc
    id: source_sensor
    pin: GPIO33

I used the following connections (5V, GPIO33 and GND)
Resistor_Connections

Regardless of me pushing onto the FSR, or not the readout in ESP Home was a constant 1.1V and 2810Ohm, although my multimeter provided readouts in MOhm area when the FSR is not touched and a much smaller value in the KOhm or several houndreds of Ohm, when pushing on the FSR.
The multimeter did change its value, when pushing on the FSR.

PS: When I capped the connection between the 10KOhm resistor and GPIO33, the readout changed to 0V & 0Ohm.
Resistance

@Spurious Although I did not yet have luck with my overall setup of the sensor, I am using the exact same clamps on the FSR and at least this connection is sollid for me. I used pliers to create sufficient force on the clamps for them to close.

It’s very important you get the R1 value correct.
What is the range of resistance you get from the FSR during the intended use?

Didn’t check that yet, thought I first test the general setup that way, before calibrating it. It’s hard to read the multimeter, when lying on the bed :smiley: At least not whilst alone.

You just invite a girl for some “experiments in bed”.
She’ll be surprised for sure.

Sure, here is how I soldered them together. I’ve circled them for clarity. And just to be thorough I’ve included my circuit diagram.

The Ground wire is connected to a 220 Ohms resistor, That isn’t shown properly in the diagram for some reason.

FYI I’m using a D1 Mini to periodically poll the sensor value of each FSR. I have two attached, one for each bed occupant.

I use a technique called multiplexing (I think that’s what it’s called). Here are the basics of it ESP8266 ADC - Multiple Analog Sensors : 3 Steps - Instructables

P.S. To keep the FSR’s from moving I used duct tape on one bed and thick double-sided tape on another, both work fine.

1 Like