Trigger tone function when a condition is met from another arduino board (BT)

Hey, so I’m clearly new to this. But anyway, there are two boards each with a HC-05 module and a speaker - with an LIS3DH accelerometer on one. My plan is to trigger the master board speaker when the slave experiences an x direction acceleration over a certain value. I can get a single board to trigger itself when accelerating with the following code, but not trigger the other board.

 #include <Wire.h>
#include <SPI.h>
#include <Adafruit_LIS3DH.h>
#include <Adafruit_Sensor.h>



// Used for software SPI
#define LIS3DH_CLK 13
#define LIS3DH_MISO 12
#define LIS3DH_MOSI 11
// Used for hardware & software SPI
#define LIS3DH_CS 10


// software SPI
//Adafruit_LIS3DH lis = Adafruit_LIS3DH(LIS3DH_CS, LIS3DH_MOSI, LIS3DH_MISO, LIS3DH_CLK);
// hardware SPI
//Adafruit_LIS3DH lis = Adafruit_LIS3DH(LIS3DH_CS);
// I2C
Adafruit_LIS3DH lis = Adafruit_LIS3DH();


#if defined(ARDUINO_ARCH_SAMD)
// for Zero, output on USB Serial console, remove line below if using programming port to program the Zero!
   #define Serial SerialUSB
#endif



void setup() {
#ifndef ESP8266
  while (!Serial);     // will pause Zero, Leonardo, etc until serial console opens
#endif

  Serial.begin(9600);
 
  Serial.println("LIS3DH test!");
  
  if (! lis.begin(0x18)) {   // change this to 0x19 for alternative i2c address
    Serial.println("Couldnt start");
    while (1);
  }
  Serial.println("LIS3DH found!");
  
  lis.setRange(LIS3DH_RANGE_4_G);   // 2, 4, 8 or 16 G!
  
  Serial.print("Range = "); Serial.print(2 << lis.getRange());  
  Serial.println("G");
}

void loop() {
  lis.read();      // get X Y and Z data at once
  // Then print out the raw data
  Serial.print("X:  "); Serial.print(lis.x); 
  Serial.print("  \tY:  "); Serial.print(lis.y); 
  Serial.print("  \tZ:  "); Serial.print(lis.z); 

  /* Or....get a new sensor event, normalized */ 
  sensors_event_t event; 
  lis.getEvent(&event);
  
  /* Display the results (acceleration is measured in m/s^2) */
  Serial.print("\t\tX: "); Serial.print(event.acceleration.x);
  Serial.print(" \tY: "); Serial.print(event.acceleration.y); 
  Serial.print(" \tZ: "); Serial.print(event.acceleration.z); 
  Serial.println(" m/s^2 ");

  Serial.println();

if (lis.x > 400){
  tone(9,300,3000);
}

}

How would I go about coding the other board to trigger when lis.x>400? Thanks in advance!

First get the two boards talking to each other.

Then plan a communications scheme. Like send a "T" for "tone on!" and "S" for "Stop!".

Then program the master to send those codes and check that you get the right codes at the other end.

Finally, add the buzzer.

Even simpler than the other answer, tie a digital output from the triggering board to a digital input on the other board. Have the triggering board set the output pin to LOW until it wants a sound to be played, then switch it HIGH.

On the receiving board, when the pin goes high, begin playing the tone.
(Every time through your loop, check the state of that pin. If it goes high, start playing a tone. If it goes low, stop. Or make it so that the receiving board plays a sound for a fixed interval when it detects a pulse from the sending board.)

MorganS:
First get the two boards talking to each other.

Then plan a communications scheme. Like send a “T” for “tone on!” and “S” for “Stop!”.

Then program the master to send those codes and check that you get the right codes at the other end.

Finally, add the buzzer.

I kind of got it working. The bluetooth communication is working, except that the speaker on the master board goes off randomly - not when there’s a vibration in the slave. Any suggestions?

Code to send slave data (lis.x is the reading from the accelerometer from before in the whole sketch):

if (lis.x > 500){
Serial.write(‘1’);
}
else if (lis.x < 500) {
Serial.write(‘0’);
}

Code to receive data from slave:

if (Serial.available() > 0) {
data = Serial.read();
}
if (data == ‘1’) {
tone(9,300);
}

if (data == ‘0’) {
noTone(9);
}

Please post all the code. In code tags.

I would try to print everything the slave gets from Bluetooth to your Serial Monitor. Maybe the Bluetooth module is sending other information like "Connected on 1 channel".