Hi all, im have problems getting my Nano to trigger sequences on a Polou Mini Maestro. The goal is to have sequences triggered when the pir senses movement. I have run code to check that the pir is working via the serial monitor and is sending the command to the maestro to trigger a sequence and that looks fine, but no sequences are actually being triggred. I have double checked that TX is going to Rx on the Maestro , 9600 fixed is selected on the maestro and I have a common ground.
Any advice would be much appreciated.
#include <SoftwareSerial.h>
const int pirPin = 7; // PIR motion sensor pin
const int numSequences = 5; // Number of Pololu Maestro sequences
SoftwareSerial maestroSerial(6, 5); // 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(300000); // 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.");
}