PIR sensor + Arduino not triggering maestro sequences

Hi all I’m trying to trigger maestro sequences via an Arduino nano. I have 8 sequences working on the maestro. The idea is to have a pir sensor trigger a random sequence when motion is detected ever 5 minutes. The serial monitor is showing that the pir is working and sequences are being triggered but the maestro is doing nothing? I’m not getting any red fault lights on the maestro. I have tried different maestros but all doing the same. I’m not to good with code and suspect that’s were the issue is, any help would be much appreciated.

### Sequence subroutines: ###

# Sequence 0
sub Sequence_0
  500 5024 7119 0 0 0 0 
  0 0 0 0 0 0 frame_0..11 # Frame 0
  500 6864 5181 frame_0_1 # Frame 1
  500 5357 6864 frame_0_1 # Frame 2
  500 0 0 frame_0_1 # Frame 3
quit
  return
# Sequence 1
sub Sequence_1
  500 5357 5024 0 0 0 0 
  0 0 0 0 0 0 frame_0..11 # Frame 0
  500 7354 frame_1 # Frame 1
  500 4653 frame_1 # Frame 2
quit
  return
# Sequence 2
sub Sequence_2
  500 5142 5925 0 0 0 0 
  0 0 0 0 0 0 frame_0..11 # Frame 0
  500 6962 frame_0 # Frame 1
  500 5064 frame_0 # Frame 2
  500 7471 frame_0 # Frame 3
  500 5964 frame_0 # Frame 4
quit
  return
# Sequence 3
sub Sequence_3
  500 7569 4613 0 0 0 0 
  0 0 0 0 0 0 frame_0..11 # Frame 0
  500 5083 7099 frame_0_1 # Frame 1
  500 6000 6000 frame_0_1 # Frame 2
quit
  return
# Sequence 4
sub Sequence_4
  500 4829 6000 0 0 0 0 
  0 0 0 0 0 0 frame_0..11 # Frame 0
  500 7373 frame_0 # Frame 1
  500 5259 frame_0 # Frame 2
quit
  return
# Sequence 5
sub Sequence_5
  500 0 4711 0 0 0 0 
  0 0 0 0 0 0 frame_0..11 # Frame 0
  500 7256 frame_1 # Frame 1
  500 6000 6000 frame_0_1 # Frame 2
quit
  return
# Sequence 6
sub Sequence_6
  500 5318 6903 0 0 0 0 
  0 0 0 0 0 0 frame_0..11 # Frame 0
  500 6000 6000 frame_0_1 # Frame 1
quit
  return
# Sequence 7
sub Sequence_7
  500 3968 3968 0 0 0 0 
  0 0 0 0 0 0 frame_0..11 # Frame 0
  500 8000 8000 frame_0_1 # Frame 1
  500 6000 6000 frame_0_1 # Frame 2
quit
  return

sub frame_0..11
  11 servo
  10 servo
  9 servo
  8 servo
  7 servo
  6 servo
  5 servo
  4 servo
  3 servo
  2 servo
  1 servo
  0 servo
  delay
  return

sub frame_0_1
  1 servo
  0 servo
  delay
  return

sub frame_1
  1 servo
  delay
  return

sub frame_0
  0 servo
  delay
  return
#include <SoftwareSerial.h>

const int pirPin = 7; // PIR motion sensor pin
const int numSequences = 8; // Number of Pololu Maestro sequences
SoftwareSerial maestroSerial(10, 11); // RX, TX

void setup() {
  pinMode(pirPin, INPUT);
  maestroSerial.begin(9600); // Initialize serial communication with Pololu Maestro
  Serial.begin(9600); // Initialize serial communication for debugging
  randomSeed(analogRead(0)); // Seed the random number generator
}

void loop() {
  if (digitalRead(pirPin) == HIGH) {
    int sequence = random(0, numSequences); // Generate a random sequence number
    Serial.print("Motion detected! Triggering sequence: ");
    Serial.println(sequence);
    triggerMaestroSequence(sequence);
    delay(3000); // Wait for 5 minutes (300000 milliseconds)
  } else {
    Serial.println("No motion detected.");
  }
  delay(500); // Check the PIR sensor every 500 milliseconds
}

void triggerMaestroSequence(int sequence) {
  maestroSerial.write(0xAA); // Pololu protocol header
  maestroSerial.write(0x12); // Device number (change if needed)
  maestroSerial.write(0x01); // Command byte: Start sequence
  maestroSerial.write(sequence); // Sequence number
  Serial.print("Sequence ");
  Serial.print(sequence);
  Serial.println(" triggered.");
}

Hello.

The command byte for the “Restart Script at Subroutine” command when using the Pololu protocol is 0x27 (not 0x01).

If correcting that does not fix the problem, could you post a copy of your Maestro settings file along with some pictures that show all of your connections? You can save a copy of your settings file from the “File” drop-down menu of the Maestro Control Center software while the controller is connected.

By the way, you might consider using our Maestro library for Arduino.

Brandon

Thanks for the reply, that did not work unfortunately, I used Chat Ai in the end and it came up with a different Arduino sketch that works fine :+1: