Hydrides are simple compounds containing one or a few hydrogen atoms bonded to a heavier atom. They are fundamental precursor molecules in cosmic chemistry and many hydride ions have become observable in high quality for the first time thanks to the Herschel Space Observatory. Ionized hydrides, such as CH+ and OH+, and also HCO+ that affect the chemistry of molecules such as water, provide complementary information on irradiation by far UV (FUV) or X-rays and gas temperature. The targeted lines of CH+, OH+, H2O+, C+ and CH are detected mostly in blue-shifted absorption. H3O+ and SH+ are detected in emission and only toward some high-mass objects. The observed line parameters and correlations suggest two different origins, related to gas entrained by the outflows and to the circumstellar envelope. The column density ratios of CH+/OH+ are estimated from chemical slab models, assuming that the H2 density is given by the specific density model of each object at the beam radius. For the low-mass YSOs the observed ratio can be reproduced for an FUV flux of 2-400 times the ISRF at the location of the molecules. In two high-mass objects, the UV flux is 20-200 times the ISRF derived from absorption lines, and 300-600 ISRF using emission lines. If the FUV flux required for low-mass objects originates at the central protostar, a substantial FUV luminosity, up to 1.5 L_sun, is required. There is no molecular evidence for X-ray induced chemistry in the low-mass objects on the observed scales of a few 1000 AU. For high-mass regions, the FUV flux required to produce the observed molecular ratios is smaller than the unattenuated flux expected from the central object(s) at the Herschel beam radius. This is consistent with an FUV flux reduced by circumstellar extinction or by bloating of the protostar.