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 }
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login