 		}
 		else
 			if (tmp_str[j] == 'I' || tmp_str[j] == 'i') {// infrared
-				int sensor_index;
-				int num_read = sscanf(tmp_str + j + 1, "%d", &sensor_index);
+				uint8_t sensor_index;
+				int num_read = sscanf(tmp_str + j + 1, "%hhu", &sensor_index);
+				if (num_read != 1) {
+					strcpy(tmp_serial_out, "E#");
+					i += 2;
+					return;
+				}
 				if (motor_type == 'S' || motor_type == 's') // attach to stepper motors controller
 					steppers_controller.add_sensor(motor_index, INFRARED_ANALOG, sensor_index, 0, 0, 0, 0);
 				else

		else
			// button
			if (tmp_str[i + 1] == 'B' || tmp_str[i + 1] == 'b') {
				int sensor_index;
				int num_read = sscanf(tmp_str + i + 2, "%d", &sensor_index);
				// Serial.println(sensor_index);
				int sensor_value = buttons_controller.get_state(sensor_index);
				sprintf(tmp_serial_out, "RB%d %d#", sensor_index, sensor_value);

	pinMode(CLK, OUTPUT);

	for (int k = 0; k < num_as5147; k++) {
		uint8_t _out_pin;
		int num_read = sscanf(tmp_str + i + total_num_consumed, "%hhu%n", &_out_pin, &num_consumed);
		if (num_read != 1) {
			strcpy(tmp_serial_out, "E#");
			i += 2;
			return;
		}
		as5147s_controller.set_params(k, _out_pin);
		total_num_consumed += num_consumed + 1;
	}

	strcpy(tmp_serial_out, "CA#");
	i += total_num_consumed;
}
//--------------------------------------------------
void parse_and_execute_create_infrared_commands(char* tmp_str, byte str_length, byte &i, char *tmp_serial_out)
{
	uint8_t num_infrareds = 0;

	int num_consumed = 0;
	int num_read = sscanf(tmp_str + i + 3, "%hhu%n", &num_infrareds, &num_consumed);
	if (num_read != 1) {
		strcpy(tmp_serial_out, "E#");
		i += 2;
		return;
	}

	int total_num_consumed = 3 + num_consumed;
	infrared_analog_sensors_controller.set_num_sensors(num_infrareds);
	for (int k = 0; k < num_infrareds; k++) {
		uint8_t out_pin;
		int num_read = sscanf(tmp_str + i + total_num_consumed, "%hhu%n", &out_pin, &num_consumed);
		if (num_read != 1) {
			strcpy(tmp_serial_out, "E#");
			i += 2;
			return;
		}
		infrared_analog_sensors_controller.set_params(k, out_pin);
		total_num_consumed += num_consumed + 1;
	}
	strcpy(tmp_serial_out, "CI#");
	i += total_num_consumed;
}
//--------------------------------------------------
void parse_and_execute_create_buttons_commands(char* tmp_str, byte str_length, byte &i, char *tmp_serial_out)
{
	uint8_t num_buttons = 0;
	int num_consumed = 0;
	int num_read = sscanf(tmp_str + i + 3, "%hhu%n", &num_buttons, &num_consumed);
	if (num_read != 1) {
		strcpy(tmp_serial_out, "E#");
		i += 2;
		return;
	}

	int total_num_consumed = 3 + num_consumed;
	buttons_controller.set_num_sensors(num_buttons);
	for (int k = 0; k < num_buttons; k++) {
		uint8_t _pin;
		int num_read = sscanf(tmp_str + i + total_num_consumed, "%hhu%n", &_pin, &num_consumed);
		if (num_read != 1) {
			strcpy(tmp_serial_out, "E#");
			i += 2;
			return;
		}
		buttons_controller.set_params(k, _pin);
		total_num_consumed += num_consumed + 1;
	}
	strcpy(tmp_serial_out, "CB#");
	i += total_num_consumed;
}
//--------------------------------------------------
void parse_and_execute_create_LIDAR_commands(char* tmp_str, byte str_length, byte &i, char *tmp_serial_out)
{
	int num_consumed = 0;
	uint8_t _dir_pin, _step_pin, _enable_pin, _infrared_pin;
	int num_read = sscanf(tmp_str + i + 2, "%hhu%hhu%hhu%hhu%n", &_dir_pin, &_step_pin, &_enable_pin, &_infrared_pin, &num_consumed);
	if (num_read != 4) {
		strcpy(tmp_serial_out, "E#");
		i += 2;
		return;
	}
	tera_ranger_one_lidar = new t_tera_ranger_one_lidar(_dir_pin, _step_pin, _enable_pin, _infrared_pin);

	strcpy(tmp_serial_out, "CL#");
	i += num_consumed + 2;
}
//--------------------------------------------------
