// If more than 100 bytes have been received, the string is not valid. Reset and "try again" (wait for $ to indicate start of new string).
else if (serial_index > 100) {
serial_index = 0;
string_started = 0;
}

}

else if (Serial.read() == '$') {
string_started = 1;
}

}

// if "read_sensors" flag is set high, read sensors and update
if (read_sensors == 1) {