Apple iMac Hardware Test: 4SNS : VH1R
CNet has an article on the codes returned by the diagnostic test. http://www.cnet.com/news/how-to-invoke-and-interpret-the-apple-hardware-tests/

According to that VH... means voltage on the hard disk.

At a big guess you might have a dodgy connection to your hard-disk. If its intermittent then the voltage may drop, triggering the safety feature of the fans running at max speed.