In the last 2 decades, more than 3000 exoplanets have been discovered orbiting stars other than the Sun. Many of them have been identified with the Doppler spectroscopy or radial velocity method, which consists in detecting the reflex motion of the star caused by the gravitational effect of an unseen planetary companion in orbit. Current technology is not precise enough to find small rocky planets similar to our Earth in Sun-like stars, but we can detect such planets in the habitable zone of M dwarfs, the most abundant type of stars in the galaxy, which are smaller and cooler than the Sun. The main source of noise when it comes to detecting exoplanets in cool stars is stellar activity. Due to their magnetic fields, stars show dark spots on their surface which can hide a true exoplanet signal or even mimic it and mislead us into a false detection. My research focuses on stellar activity in cool stars, and I study it by analyzing data acquired with the CARMENES instrument, a spectrograph specially designed to observe M dwarfs. The aim of this flash talk is to briefly explain how we use spectrographs to detect exoplanets, why we study M dwarfs as potential exoplanet hosts and point out the importance understanding stellar activity.