With the rapid development of machine learning, an increasing number of domains begin to utilize machine learning methods to simplify part of assignments, which can relieve humans' stress. In traditional domains, like medicine, machine learning methods have great potential to play a significant role in detecting diseases. Some machine learning methods have been deployed to analyze electrocardiograms (ECG) because of the impressive accuracy and speediness, which is meaningful and convenient to the medical domain. Detecting disease in ECG accurately is beneficial to prevent and cure some fatal diseases, which may save thousands of lives. In this paper, the machine learning method is used to detect Atrial fibrillation (AF), a severe heart disease damaging people's health. The model used in this paper is Convolutional Neural Network (CNN), a deep learning model. Apart from building a model to detect AF, this paper will also explore and extend the possibility of using CNN in dealing with one-dimensional data. After dealing with a large amount of original ECG data and feed them with labels to the CNN model with some specific parameters adjusted manually, the CNN model with 91.8% accuracy is trained and can be used on some specific occasions to find exceptions of the heart.