The son of Helen Whytt and the Rev Andrew Melville, minister of Monimail (d. 29 July 1736), Melvill was a student at the University of Glasgow. In 1749, with Alexander Wilson, his landlord and later the first professor of astronomy at the University, they made the first recorded use of kites in meteorology. They measured air temperature at various levels above the ground simultaneously with a train of kites.
He most notably delivered a lecture entitled Observations on light and colours to the Medical Society of Edinburgh in 1752, in which he described what has been seen as the first flame test. In it he described how he had used a prism to observe a flame coloured by various salts. He reported that a yellow line was always seen at the same place in the spectrum; this was derived from the sodium which was present as an impurity in all his salts. Because of this, he is sometimes described as the father of flame emission spectroscopy, though he did not identify the source of the line, or propose his experiment as a method of analysis. 
He also proposed that light rays of different colours travelled at different speeds to explain the action of a prism, and suggested that this could be verified if the moons of Jupiter appeared as slightly different colours at different stages of their orbit. An experiment by James Short failed to confirm his hypothesis. 
Melvill died in Geneva in 1753, aged 27.