Bed occupancy sensor, using parts you have

I take your point. Testing needed!

1 Like

My sensors on two beds have been working reliably for the past week. Another Reddit user also reported success using the sensor under his mattress. Although the change in capacitance is not significant, for this use case it is enough. :grinning:

Does the sensor detect a large non-conductive weight placed in the bed?

E.g. a suitcase full of clothes?

Yes, probably. The conductivity does not matter, it is the weight that changes the capacitance. Depending on how heavy the item is, the sensor value would change.

Rather than guessing, would you mind actually testing it?

This is the core of determining how the sensor works.

The weight has to be non conductive for the test.

This is a very interesting idea/solution for me, so 2 days ago I made a test sheet and put it under my mattress. Let me share my experiences.

I chose the threshold value of 5 after some testing with setup_mode enabled. This is very low, considering without anything attached to the ESP32 pin, it was in the 1000 range, and when touching the pin, it went down to ~100 for me. With this tinfoil setup I initially got ~12 unloaded and ~0-3 when on the bed. This let me reliably detect when I was on or off the bed. However today, after the second night, the sensor was stuck “ON”, and had to decrease the threshold to 2.

This makes me think that indeed the reason it works is the two sides getting closer together, and 2 nights of sleeping on it made it compress more. I was trying to test with a non-conductive weight, as @tom_l suggested, but I don’t have anything comparably heavy and non-conductive to do it. I tried to put a wooden drawer with some clothes on it, but it was only a few kg, and it didn’t trigger the sensor.

I’m wondering if using something more springy between the two sheets, like some bubble wrap or foam would increase a bit the range between loaded and unloaded capacitance to have a bigger difference for detection of the loaded state, which seems to be only 2-4 numerical values.

Also, it seems necessary to readjust the threshold after a “bedding in period” (pun intended), or already start with a lower threshold than originally seems necessary.

Still, awesome idea and simple and cheap implementation, and so far good accuracy for me. Thanks @N-l1!

1 Like

Thank you @attila_ha @tom_l :smiley:

However, I do not understand why conductivity would matter in this case. The two pieces of tin foil with the paper in between forms a basic capacitor. By no means am I an expert on capacitors, but a capacitor works as two conductive plates (in this case, the two pieces of tin foil) are separated by a dielectric/insulant (in this case, the paper). Charges cannot pass through the dielectric, hence positive charges accumulate on one plate while negative charges accumulate on the other. However, the distance between the two plates affects the capacitance. If there is a large distance between the plates, even a single charge on a plate would repel further charges to enter the plate. As the distance between plates decreases, they can hold more charges due to attraction from the oppositely charged plate. With the minimum distance between the plates, the max attraction between them enables both to hold the max amount of charges. That is why sitting on the bed (decreasing the distance between the two plates) changes the capacitance.

I don’t see how the conductively of an object would affect the capacitance. In other words, a non-conductive object with the same weight as a conductive object would alter the capacitance by the same amount.

As to the threshold of the sensor, I don’t have a solution for that either. Maybe some tweaking with the ESPHome capacitance detection setting would help shorten the range, resulting in a more significant difference in when you are sitting on the bed or not. After a week and so of sleeping, I have starting to notice that my difference from “on bed” to “not on bed” has started to decrease as well…

1 Like

Why do you think the conductivity of an object on the bed would affect the capacitance of a capacitor underneath the mattress? I am not following your logic.

It will form a third plate with parasitic capacitances to earth. It’s how touch sensors work.

https://www.arrow.com/en/research-and-events/articles/how-touch-sensors-work

You all seem to think it works by compressing the paper. I just don’t see that happening under a mattress.

1 Like

Hi @tom_l,

I disagree. Yes, a capacitive touch sensor/screen works when a conductor (your finger) disrupts the electrostatic field. However, it is near impossible for a touch to register through a mattress. As I explained in my previous post, the capacitance of this sensor change because of the change in distance between the two plates. The paper is not compressing, it is the tin foils that are pushed together. Although the change might be slight, it is enough to tell the difference.

The original poster linked to this blog for making the pressure mats, more info can also be found there.

Thank you for your thoughts! :grinning:

The weight of the mattress will compress the foil hard up against the paper. There would be no “gap” to change. Even if there was a gap initially, the sensor should become unresponsive over time.

If it does indeed work this way, bubble wrap (as suggested earlier) would make a much better dialectic.

1 Like

I totally agree, there should be further experimentation with different dielectrics.

Edit: I can confirm, a large non-conductive weight (plastic laundry basket filled will clothes) does trigger the sensor.

2 Likes

Well that’s that sorted then.

So a more responsive sensor would require a flexible dielectric that won’t compress over time.

Open cell foam would be bad.

Closed cell foam would compress a bit initially but retain some 'springyness". Tiny bubble wrap would probably work too, though the flat surface of closed cell foam would make it easier to construct.

Hi folks,

So I cut open my tinfoil sensor on one side and put a piece of foam in it.

It made the sensing range go to about 40 unloaded and 10-30 loaded, based on how closely I lay on top of it. It’s definitely sensing the pressure, not the capacitance of my body, as I can’t really change the value if I just move my body around it without pressure on it. I settled on a threshold of 20, and added a delayed_on_off: 1s filter for it, to not spam HA with events during the transition, or when it’s close to the threshold.

I was thinking about making an alternative sensor design, based on how Espressif recommends it. Sort of a big circular tinfoil part going to the sensing pin, and then another part of ground around it for noise isolation. But I foresee it as something a lot more fiddly, susceptible to electrical noise and harder to make.

I think the original design with the addition to something springy between the sheets of foils is a really great solution for a pressure sensor. :+1:

Another idea for cabling is that probably the ground cable can be daisy-chained between the multiple pads, reducing the amount of cables needed to connect to the node to n+1, instead of 2n.

2 Likes

That appears to be open cell foam. It will compress over time. See if you can find some closed cell foam.

Using the adhesive copper sheet I linked to in an earlier post could help with construction of this. It would be a truly capacitive sensor between the body and touch plate. It might help to make the sensing electrode at least as wide as your mattress is thick. Doesn’t have to be round. Square with rounded corners should also work.

You’re right, I’ll see if I can find some closed cell one. I agree that making this the “proper” touch sensitive way sounds like a fun project, however using those fancy copper sheets would make this project’s cost a lot higher, especially if you want to have multiple sensing areas. I don’t see the taped on wire ends going anywhere, but it’s definitely not that elegant. :grinning:

Spray adhesive and the foil then. Glue it to a backing sheet of thick card and cut out a 3-5mm strip round the inner electrode foil (not all the way through the card!).

The capacitive sensor between the body and touch plate seems like a very interesting idea. However, I just don’t think the body would ever trigger the sensor through the mattress. Different dielectrics seems to increase the accuracy of the sensor though. In the original blog, I saw someone mention using plastic chip bags, might be interesting to try.

Thank you for sharing. I really liked the idea and will try it out once our lockdown is over and we can buy stuff.

1 Like

I also made it and it works really good, had to decrease th threshold to 3 after one night.
What does removing setup mode do?