Controlling speed of dc motor

Those resistors are 126M not 10k but they are not required. Also, pinMode() has an INPUT_PULLUP option, so you won't need a resistor for the switch. You should use four diodes like in the image below.

Untitled.png