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. Servo-Motion Multisensor - Release 2.0

Servo-Motion Multisensor - Release 2.0

Scheduled Pinned Locked Moved Troubleshooting
1 Posts 1 Posters 547 Views 2 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.
  • manuM Offline
    manuM Offline
    manu
    wrote on last edited by
    #1

    Hello everybody,
    I try to bring a multi sensor with 2.0 release to run. Containing a servo and a motion sensor.
    The sketch is compiled without errors
    But unfortunately only the motion sensor works.
    The servo motor does not react. I have tried a lot but without success
    Could someone help me please?
    Many thanks for any help

    // Enable debug prints to serial monitor
    #define MY_DEBUG 
    
    // Enable and select radio type attached
    #define MY_RADIO_NRF24
    //#define MY_RADIO_RFM69
    
    #include <SPI.h>
    #include <MySensors.h>
    #include <Servo.h> 
    
    #define SERVO_DIGITAL_OUT_PIN 3
    #define SERVO_MIN 0 // Fine tune your servos min. 0-180
    #define SERVO_MAX 180  // Fine tune your servos max. 0-180
    #define DETACH_DELAY 900 // Tune this to let your movement finish before detaching the servo
    #define CHILD_SERVO 1   // Id of the sensor child
    #define CHILD_MOTION 2
    
    unsigned long SLEEP_TIME = 120000; // Sleep time between reports (in milliseconds)
    #define DIGITAL_INPUT_SENSOR 2   // The digital input you attached your motion sensor.  (Only 2 and 3 generates interrupt!)
    
    MyMessage msgMOTION(CHILD_MOTION, V_TRIPPED);
    MyMessage msgSERVO(CHILD_SERVO, V_DIMMER);
    
    Servo myservo;  // create servo object to control a servo 
                    // a maximum of eight servo objects can be created Sensor gw(9,10);
    unsigned long timeOfLastChange = 0;
    bool attachedServo = false;
    
    void setup() 
    { 
      // Request last servo state at startup
      request(CHILD_SERVO, V_DIMMER);
      
      pinMode(DIGITAL_INPUT_SENSOR, INPUT);
    } 
    
    void presentation()  {
      // Send the sketch version information to the gateway and Controller
      sendSketchInfo("Servo_Motion", "1.0");
    
      // Register all sensors to gw (they will be created as child devices)
      present(CHILD_SERVO, S_COVER);
      present(CHILD_MOTION, S_MOTION);
    }
    
    void loop() 
    { 
      
        if (attachedServo && millis() - timeOfLastChange > DETACH_DELAY) {
         myservo.detach();
         attachedServo = false;
       
      }
    
        // Read digital motion value
         bool tripped = digitalRead(DIGITAL_INPUT_SENSOR) == HIGH;
    
         Serial.println(tripped);
         send(msgMOTION.set(tripped?"1":"0"));  // Send tripped value to gw 
    
          // Sleep until interrupt comes in on motion sensor. Send update every two minute.
         sleep(digitalPinToInterrupt(DIGITAL_INPUT_SENSOR), CHANGE, SLEEP_TIME);
     
    } 
    
    void receive(const MyMessage &message) {
      myservo.attach(SERVO_DIGITAL_OUT_PIN);   
      attachedServo = true;
      if (message.type==V_DIMMER) { // This could be M_ACK_VARIABLE or M_SET_VARIABLE
         int val = message.getInt();
         myservo.write(SERVO_MAX + (SERVO_MIN-SERVO_MAX)/100 * val); // sets the servo position 0-180
         
         // Write some debug info
         Serial.print("Servo changed. new state: ");
         Serial.println(val);
       } else if (message.type==V_UP) {
         Serial.println("Servo UP command");
         myservo.write(SERVO_MIN);
         send(msgSERVO.set(100));
       } else if (message.type==V_DOWN) {
         Serial.println("Servo DOWN command");
         myservo.write(SERVO_MAX); 
         send(msgSERVO.set(0));
       } else if (message.type==V_STOP) {
         Serial.println("Servo STOP command");
         myservo.detach();
         attachedServo = false;
    
       }
       timeOfLastChange = millis();
    }
    
    1 Reply Last reply
    0

    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
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    11

    Online

    12.1k

    Users

    11.2k

    Topics

    113.4k

    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