Will this work correctly?
Hard to say just yet. Their is no labeling on the two connectors to the Mega. Nor is their any indication what the "device" actually is.Not sure how you get 17V from a 3V battery, is their an inverter?R1 should be 1K and R2 depends on how much you need to limit the current. Too many unknowns at the moment.