How can I set a signal range for standard firmatta

Hi, I have combined a standard firmata with heartbeat sensor code in an attempt to turn a device on or off in ableton.

I am able to turn the sensor on, but due to the signal being so high I can’t turn it off.

Is there a way to do this? how would I go about introducing an if statement to control this?

Is there some other way?

my connections are

VIN - 5V
SDA - A4
SCL - A5

I have attached the code

I would very much appreciate some help on this!


heartbeat_firmatta.ino (27.5 KB)

Am I headed in the right direction?

I dont think I was actually getting a response from ableton with my original code.

I have merged simpler versions of the code now, I still cannot use the sensor as an input but Im wondering if this is because the two codes I merged use serial 9600 and 57600.

Would I be looking at millis and storing values in “long”?

This is what i’ve got, i can make a piezo react to ableton but not the heart sensor.

 * Firmata is a generic protocol for communicating with microcontrollers
 * from software on a host computer. It is intended to work with
 * any host computer software package.
 * To download a host software package, please click on the following link
 * to open the list of Firmata client libraries in your default browser.

/* This firmware supports as many analog ports as possible, all analog inputs,
 * four PWM outputs, and two with servo support.
 * This example code is in the public domain.
#include <Servo.h>
#include <Firmata.h>
//below is sensor code
#include <Wire.h>
#include "MAX30105.h"

MAX30105 particleSensor;

#define debug Serial //Uncomment this line if you're using an Uno or ESP
//#define debug SerialUSB //Uncomment this line if you're using a SAMD21

/* servos */
Servo servo9, servo10; // one instance per pin
/* analog inputs */
int analogInputsToReport = 0; // bitwise array to store pin reporting
int analogPin = 0; // counter for reading analog pins
/* timer variables */
unsigned long currentMillis;     // store the current value from millis()
unsigned long previousMillis;    // for comparison with currentMillis


void analogWriteCallback(byte pin, int value)
  switch (pin) {
    case 9: servo9.write(value); break;
    case 10: servo10.write(value); break;
    case 3:
    case 5:
    case 6:
    case 11: // PWM pins
      analogWrite(pin, value);
// -----------------------------------------------------------------------------
// sets bits in a bit array (int) to toggle the reporting of the analogIns
void reportAnalogCallback(byte pin, int value)
  if (value == 0) {
    analogInputsToReport = analogInputsToReport & ~ (1 << pin);
  else { // everything but 0 enables reporting of that pin
    analogInputsToReport = analogInputsToReport | (1 << pin);
  // TODO: save status to EEPROM here, if changed

 * SETUP()
void setup()
  Firmata.attach(ANALOG_MESSAGE, analogWriteCallback);
  Firmata.attach(REPORT_ANALOG, reportAnalogCallback);

  //below is sensor code
  debug.println("MAX30105 Basic Readings Example");

  // Initialize sensor
  if (particleSensor.begin() == false)
    debug.println("MAX30105 was not found. Please check wiring/power. ");
    while (1);

  particleSensor.setup(); //Configure sensor. Use 6.4mA for LED drive

 * LOOP()
void loop()
    debug.print("] IR[");

 // above debug is sensor code
  while (Firmata.available())
  currentMillis = millis();
  if (currentMillis - previousMillis > 20) {
    previousMillis += 20;                   // run this every 20ms
    for (analogPin = 0; analogPin < TOTAL_ANALOG_PINS; analogPin++) {
      if ( analogInputsToReport & (1 << analogPin) )
        Firmata.sendAnalog(analogPin, analogRead(analogPin));


Use one serial rate or the other but using two would be no good unless one was a soft serial rate which I dont think you want.

Other post/duplicate DELETED
Please do NOT cross post / duplicate as it wastes peoples time and efforts to have more than one post for a single topic.

Continued cross posting could result in a time out from the forum.

Could you take a few moments to Learn How To Use The Forum.
It will help you get the best out of the forum in the future.
Other general help and troubleshooting advice can be found here.