A sensor device for determining an orientation (α,β) of a magnet having an axis, the sensor device comprising: - a silicon substrate comprising a plurality of magnetic sensors; - a processing circuit configured for: a) determining a first magnetic field gradient (dBx/dx; dBz/dx) of a first magnetic field component (Bx; Bz) oriented in a first direction parallel to the silicon substrate or oriented in a third direction perpendicular to said substrate, along said first direction; b) determining a second magnetic field gradient (dBy/dy; dBz/dy) of a second magnetic field component (By; Bz) oriented in a second direction parallel to the silicon substrate and perpendicular to the first direction or oriented in the third direction perpendicular to said substrate, along said second direction; c) determining a first angle (α) as a function of said first magnetic field gradient (dBx/dx; dBz/dx) and a first correction value (D1, D2, D3, D5, D7); d) determining a second angle (β) as a function of said second magnetic field gradient (dBy/dy; dBz/dy) and a second correction value (D1, D2, D4, D6, D8); characterised in that step a) comprises: determining a first magnetic field gradient (dBz/dx) of a magnetic field component (Bz) oriented perpendicular to the silicon substrate, along said first direction; and step b) comprises: determining a second magnetic field gradient (dBz/dy) of said magnetic field component (Bz) oriented perpendicular to the substrate, along said second direction; and wherein the first and the second correction value (D1, D2, D3, D4) are selected from the group consisting of: a predefined function of temperature, a sum of squares of three orthogonal magnetic field components (Bx, By, Bz), a sum of squares of three orthogonal magnetic field gradients (dBx/dx, dBy/dx, dBz/dx) along the first direction, and a sum of squares of three orthogonal magnetic field gradients (dBx/dy, dBy/dy, dBz/dy) along the second direction. - a silicon substrate comprising a plurality of magnetic sensors; - a processing circuit configured for: a) determining a first magnetic field gradient (dBx/dx; dBz/dx) of a first magnetic field component (Bx; Bz) oriented in a first direction parallel to the silicon substrate or oriented in a third direction perpendicular to said substrate, along said first direction; b) determining a second magnetic field gradient (dBy/dy; dBz/dy) of a second magnetic field component (By; Bz) oriented in a second direction parallel to the silicon substrate and perpendicular to the first direction or oriented in the third direction perpendicular to said substrate, along said second direction; c) determining a first angle (α) as a function of said first magnetic field gradient (dBx/dx; dBz/dx) and a first correction value (D1, D2, D3, D5, D7); d) determining a second angle (β) as a function of said second magnetic field gradient (dBy/dy; dBz/dy) and a second correction value (D1, D2, D4, D6, D8); a) determining a first magnetic field gradient (dBx/dx; dBz/dx) of a first magnetic field component (Bx; Bz) oriented in a first direction parallel to the silicon substrate or oriented in a third direction perpendicular to said substrate, along said first direction; b) determining a second magnetic field gradient (dBy/dy; dBz/dy) of a second magnetic field component (By; Bz) oriented in a second direction parallel to the silicon substrate and perpendicular to the first direction or oriented in the third direction perpendicular to said substrate, along said second direction; c) determining a first angle (α) as a function of said first magnetic field gradient (dBx/dx; dBz/dx) and a first correction value (D1, D2, D3, D5, D7); d) determining a second angle (β) as a function of said second magnetic field gradient (dBy/dy; dBz/dy) and a second correction value (D1, D2, D4, D6, D8); step a) comprises: determining a first magnetic field gradient (dBz/dx) of a magnetic field component (Bz) oriented perpendicular to the silicon substrate, along said first direction; and step b) comprises: determining a second magnetic field gradient (dBz/dy) of said magnetic field component (Bz) oriented perpendicular to the substrate, along said second direction; and wherein the first and the second correction value (D1, D2, D3, D4) are selected from the group consisting of: a predefined function of temperature, a sum of squares of three orthogonal magnetic field components (Bx, By, Bz), a sum of squares of three orthogonal magnetic field gradients (dBx/dx, dBy/dx, dBz/dx) along the first direction, and a sum of squares of three orthogonal magnetic field gradients (dBx/dy, dBy/dy, dBz/dy) along the second direction.