Thanks again guys,
It sounds like the Arduino is beyond my skills.
Letting go the throttle, shifting, and applying the throttle again makes sense.
Presumably stopping pedaling will also shut off the motor quickly.
So I will leave out fitting the gear sensor and see how I get on with that...