Help with bed occupancy-sketch using preassure sensor



  • 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 ?



  • 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
    }
    

Log in to reply
 

Suggested Topics

  • 3
  • 2
  • 8
  • 1
  • 5

55
Online

11.4k
Users

11.1k
Topics

112.6k
Posts