Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. Troubleshooting
  3. Help with bed occupancy-sketch using preassure sensor

Help with bed occupancy-sketch using preassure sensor

Scheduled Pinned Locked Moved Troubleshooting
2 Posts 1 Posters 681 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Cliff KarlssonC Offline
    Cliff KarlssonC Offline
    Cliff Karlsson
    wrote on last edited by Cliff Karlsson
    #1

    I am going to try to place an fsr-preassure sensor in my bed to check if it can be used as a bed occupancy sensor. But I really suck at coding and just tried to modify an existing sketch into this:

    #define MY_RADIO_NRF24
    #include <MyConfig.h>
    #include <MySensors.h>
    
    #include <SPI.h>
    
    
    #define NODE_ID 1
    #define OPEN 1
    #define CLOSE 0
    
    MyMessage msg(NODE_ID, V_TRIPPED);
    int FSR_Pin = A0; //analog pin 0
    uint8_t value = OPEN;
    
    void presentation()
    {
      present(NODE_ID, S_DOOR);
    }
    
    void loop()
    {
     int FSRReading = analogRead(FSR_Pin); 
     if(FSRReading > 300)
     {
    value=CLOSE;
     } 
    else
    {
    value=OPEN;
    }  
    send(msg.set(value)); 
    sleep(10000);
    }
    

    I don't really know the what FSR reading I will have to use but I am starting with 800 (value goes from 0- ~1000)

    Will this sketch trigger as soon as the FSR rading is above 800 and stay triggered until reading drops under 800 ?

    1 Reply Last reply
    0
    • Cliff KarlssonC Offline
      Cliff KarlssonC Offline
      Cliff Karlsson
      wrote on last edited by
      #2

      This is a regular basic sketch that uses the sensor.

      int FSR_Pin = A0; //analog pin 0
      
      void setup(){
        Serial.begin(9600);
      }
      
      void loop(){
        int FSRReading = analogRead(FSR_Pin); 
      
        Serial.println(FSRReading);
        delay(250); //just here to slow down the output for easier reading
      }
      
      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      15

      Online

      11.7k

      Users

      11.2k

      Topics

      113.2k

      Posts


      Copyright 2025 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • MySensors
      • OpenHardware.io
      • Categories
      • Recent
      • Tags
      • Popular