The series of events involved in the perception of pain in which a stimulus is received and converted into a molecular signal