Why it shows d2 was not declared in scope
Arduino pins are defined only by a simple number, with the exception that the analog pins are also named as 'A0' through 'A8' (or however many analog pins the specific processor has). Thus, D2 is not defined. If you mean to refer to Arduino pin 2, its name is just '2'. So:
#define ONE_WIRE_BUS D2  -&gt;  #define ONE_WIRE_BUS 2