FSR - the best bed occupancy sensor

I’m excited to work on this soon.

For those who have built this using two FSR strips, how did you wire and configure them? Did they both go into the same ESP32?

Additionally, has anyone who typically shares a bed with a partner had success setting the resistors so they can detect occupancy both a) when sleepers are in a specific side of the bed, and b) when just one sleeper is sleeping in the middle? How did you determine the resistor value (for the calculations in the OP) for that?

Yes that has already been suggested:

Yes I know it was previously suggested but the follow-up posts suggest it didn’t work…

BTW, I have just completed rewiring my D1 mini to support 2 independent bed sensors. Granted, they are only on/off and would preclude one from determining whether you are laying down or sitting up but for me, in-bed yes/no is sufficient. I used two 2N2222 NPN transistors and had to change my main resistor from 20K to 100K to feed the base of the transistor with the right voltage in combination with my FSR range of 5K-80K connected to ground. I wired GPIO pins 12 to the transistor collector and the emitter to ground and paralled that wiring with GPIO 13 for the other side.

esphome:
  name: bed-sensor
esp8266:
  board: d1_mini
# Enable logging
logger:
# Enable Home Assistant API
api:
ota:
  password: ""
wifi:
  <redacted>
  ap:
    <redacted>
captive_portal:

binary_sensor:
  - platform: gpio
    pin:
      number: 12
      inverted: False
      mode: 
        input: True
        pullup: True
    name: "Master Bed Right Occupied"
    id: mb_r

  - platform: gpio
    pin:
      number: 13
      inverted: False
      mode: 
        input: True
        pullup: True
    name: "Master Bed Left Occupied"
    id: mb_l

I don’t see that, could you link to it please?

Post 146:

That was before the suggestion to use restore.

The suggestions did not mention adding restore_from_flash: true to esp8266:, which was the point of my post. Those more experienced with ESPHome might know that but I did not and therefore restore_value: did not work for me when I first tried it.

Ah now I understand. Thanks for the clarification.

1 Like

just as an update: I have a working breadboard prototype with the Lolin C3 Pico and just ordered the PCB. I’m now in the process of making a 3d printed case. If it’s working as intended I’ll put the files on GitHub.


You can also look at it with AR: file: FSR-bed-sensor-Lolin-ESP32-C3/v3.usdz at main · fhb/FSR-bed-sensor-Lolin-ESP32-C3 · GitHub viewer: https://www.usdz-viewer.net

Yes, I have 4 outputs for the ESP32. Vcc, GND and 2 ADC inputs. I have the FSRs wires so they share GND, the rest is effectively the same as in the OP, so a pull-up resistor for each sensor.

Yep, I have two FSR strips wired to an ESP32 along with two RGB light strips to act as path lighting at night. The automation for the path lighting is handled via Node Red, but If you wanted to, I imagine you could code the automation in to ESPHome right on the ESP32. Depends on what your end goal is.

Our bed is a split king, so neither one of us sleeps in the center of the bed, ever. But you could certainly check to see what both sensors read while someone is in the middle of the bed and set up an automation to extrapolate from the two readings that someone is in the middle of the bed.

That being said, an ESP32 could easily support a third sensor located in the middle of the bed.

I keep getting spikes during the night probably caused by movement registering as un unoccupied bed:
image
The fsr are placed in the middle of each side on about lower back height. Is anybody seeing similar issues? Any recommendations regarding the fsr placement?

They don’t look like solid slats that the FSR can be squashed against?

You are right, they do bend a little under weight, maybe too much depending on the body position. But this kind of bed slats are quite common? Are you using slats like these? image

I’ll try fixing a plank on one of the slats and see what the sensor results will be.

I have finished changing my D1 Mini from 2N2222 transistors to a LM358 dual op-amp design configured as FSR variable force threshold switches.
image
image

The left & right FSR’s share a common +3.3v and are arranged in voltage dividers with 47K RM. An op-amp, LM358, is used as a comparator. The output of U1 is either high or low and connects to DI Mini pins D6 & D7. The non-inverting input of the op-amp is driven by the output of the divider, which is a voltage that increases with force. At zero force, the output of the op-amp will be low. When the voltage at the non-inverting input of the op-amp exceeds the voltage of the inverting input, the output of the op-amp will toggle high. The triggering voltage, and therefore the force threshold, is set at the inverting input by two 47K pots R1. The hysteresis, 47K R2, acts as “debouncers”, eliminating any multiple triggerings of the output that might occur.

That seems WAY more complicated to me than just using a properly sized resistor as a voltage divider.

Is there something I missed that required all of the additional electronics?

It adds hysteresis, but I’ve never needed it. The voltage swing is wide and fast enough to get by without it.

Yeah, I have two dual side sensors (two FSR’s on one ESP) setup and it’s never been an issue for me on either one.

Well, maybe I have missed something but I am using a D1 Mini which only has 1 analog pin so I am using two of the digital pins on the mini. The LM358 & socket is cheap and you still need other resistors anyway, and the pots are for ease of fine tuning …