We developed an end-to-end automatic algorithm for the detection of signs of COVID-19 virus infection in ECGs. We analyzed 12-lead ECGs from patients infected by COVID-19 (C-group) and from a control group (NC-group). The C-group (896 cases) included patients (age range [19-96] years) hospitalized at Ospedale San Matteo in Pavia (Italy) during the first 2020 pandemic outbreak. Infection was confirmed by nasal swab testing. The NC-group (also 896 cases) was built by collecting ECG in sinus rhythm from 3 datasets: Georgia ECG (USA), PTB-XL (Germany) and CPSC 2018 (China). Control ECGs were matched by gender, age and heart rate. An additional control group, only used for testing, was extracted from the Ningbo (China) database. A 4-layers convolutional neural network (CNN), with increasing filter size plus a final fully connected (FC) layer, was designed to classify C vs NC-group. The CNN was trained and k-fold cross validated (k=7) on 1536 ECGs (1316 for testing-220 for validation). Every fold model was used to classify the remaining, separate common test set of 256 ECGs. The accuracy was 0.86 ± 0.01 on validation, 0.86 ± 0.01 on the test set. The FPR on the NC-group was 0.14± 0.03 on validation, 0.13± 0.02 on test and 0.10± 0.01 on the Ningbo test set (p>0.05, ns) showing that no bias was induced by the selection of datasets.