The present disclosure relates to a device and method for controlling a solenoid valve of a portable medical device. The portable medical device comprises a power source; an electrically actuated valve, a control unit for regulating at least one of a control voltage and a control current for actuation of the valve, and at least one inertial sensor for detecting and transmitting motion signals representative of external motions applied to the portable medical device. The control unit is configured to regulate the at least one of the control voltage and the control current of the valve as a function of the motion signals of the at least one inertial sensor.