Why contrast matters more than colour
A scanner converts the image to greyscale and then decides, module by module, whether each square is dark or light. It does not care what the colours are, only how far apart they are in brightness. Two colours that look distinct to you, such as red and green, can have almost identical brightness and scan terribly.
Do this
Deep purple modules (#4B3FBF) on cream. Ratio about 8 to 1.
Not this
Coral modules (#FF7F50) on white. Ratio about 2.5 to 1. Fails in low light.
Try it in QR Studio
QR Studio measures this for every design automatically and refuses to let a failing combination reach the export screen without a warning.
▸How the ratio is calculated
Each colour is converted to relative luminance using the sRGB formula, then the ratio is (lighter + 0.05) ÷ (darker + 0.05). It is the same calculation the Web Content Accessibility Guidelines use for text, which is why the thresholds 4.5 and 7 will look familiar.
Try it yourself
Pick two colours above and scan the preview with your phone. Then read the guide for the cases the ratio alone does not catch, such as glossy paper and backlit screens.