Control connectivity of resistors in voltage divider arrangement
Use an N-channel MOSFET with low \$R_{DS-ON}\$ at \$V_{GS}=5V\$ on each ground connection.







simulate this circuit &ndash; Schematic created using CircuitLab

Also, you will want to buffer the signal through a voltage follower with a very high input impedance since the 1MΩ resistance range will give incorrect results due to it being too high an impedance for the ADC to reliably measure.  The maximum recommended impedance for an ADC is usually in the 5kΩ - 10kΩ range.  In fact, inspecting the datasheet, you can see:


  21.1 A/D Acquisition Requirements
  
  ...
  The maximum recommended impedance for analog sources is 2.5 kΩ.
  ...