Issue with RCT alimentation

I am a French engineere (sorry for the mistakes/poor English). My team and I are working on a project to detect the COVID thanks to breathing samples. We are testing devices to capture the volatil organic copounds. During those tests, we need to monitor the temperature and the humidity.
We are using a sensor, a SD card to store our temperature and humidity. We use a RTC ( DS1307) to indicate inside the file the time of the test.
I already have set the time of the RTC thanks to a sketch and it works perfectly when still on the computeur. The RTC has a batterie, so when the arduino is unpluged then re pluged, it doesn't need us to give it the time again. However, when using a alimentation, it only gives this :
Help please?
Here is my code, inspired by this Mesure de la température avec la carte Arduino Uno [Partie 2] |
#include <SPI.h>
#include <SD.h>
#include <Wire.h>
#include <DS1307.h>
#include <DHT.h>

DS1307 clock;
DHT dht(A0, DHT22);


byte degree[8] = {

unsigned long TOTAL_MESURE = 120000; // 2 min

unsigned long WRITE_INTERVAL = 10000; // 10000 Millisecondes

unsigned long lastWrite = 0; //dernier temps oĂą on a Ă©crit

unsigned long initialisation = 1; //pour n'écrire l'heure qu'une seule fois au début et après on met cette variable à 0

void setup() {

Serial.begin(9600); // Initialiser l’interface séquentielle

// Initialiser la carte SD

int selectedChip = 4;

if (!SD.begin(selectedChip)) {

Serial.println("SD-Card failed or is missing");

} else {

Serial.println("SD-Card initialized.");


dht.begin(); // Établir le lien avec le capteur

clock.begin(); // Établir le lien avec l’horloge temps réel


void loop() {

String TEMPS_DEBUT = String(getTime());

if (initialisation) {
initialisation = 0;

while (millis()<TOTAL_MESURE) {

if (millis() - lastWrite > WRITE_INTERVAL) {
//premièrement lecture et vérification qu'on peut lire

float humidity = dht.readHumidity();

float temperature = dht.readTemperature();

if (isnan(temperature) || isnan(humidity)) {

Serial.println("Failed to read from DHT");

return; // Aucune donnée --> loop() quitter à nouveau à ce stade


String line = String(temperature) + ";" + String(humidity);


lastWrite = millis();




String getTime() {

clock.getTime(); // Interroger le temps Ă  partir du microprocesseur

String t = String(clock.dayOfMonth, DEC);

t += String("/");

t += String(clock.month);

t += String("/");

t += String(clock.year);

t += String("_");

t += String(clock.hour);

t += "h";

t += String(clock.minute);

t += "min";

t += String(clock.second);

return t;


void writeToSD(String line) {

File dataFile ="datalog.csv", FILE_WRITE);

if (dataFile) {

dataFile.println(line); // Enregistrer sur la carte SD


Serial.println(line); // Enregistrer également au niveau de l’interface séquentielle pour résoudre les anomalies


else {

Serial.println("Error opening datafile");



You can post your code inline and more people will see it.

Your code doesn't look like the GitHub examples for a DS1307 in the library I found. Try some the examples for your library and see if you can get sensible results from the clock.

Now the code is more accessible, is that what you had in mind or is there a better way to do it ?
I already have results from the clock when it the arduino alimented through the USB. It only doesn't work when the arduino is alimented by the jack port. (I will look at the GitHub examples too, thanks for the tip).

Can you show how your system is wired up?

Here is a picture. Beneath is the arduino Uno, in the middle the SD card shield and on top the Base shield. The sensor is on A0 and the clock on I2C.
The power is from an alim at 5V.
I looked a few exemples on github, but they didn't seem so different (RTC_DS1307/SetTimeAndDisplay.ino at master · Seeed-Studio/RTC_DS1307 · GitHub). Maybe I am only looking at things to confort my opinion, so if you could send me the link to were you find someone using the librairy differently I would be gratefull.
Just as a side note, I am also setting the time in a different program, but the idea is to not need to do it every time.

The one I was looking at was here.

But if that exact code works with USB power, obviously you're using your version of the library correctly.

Maybe your power supply is insufficient. What voltage is it and how much current can it provide?

Edit: Oh, your power supply is 5V - that isn't enough for the barrel jack.

Then, I can increase the voltage to either 6, 7.5 , 9 or 12 V. On what ground should I base my decision ? (It will always be 1.0 A for the output)

IIRC correctly, the ideal range for the barrel jack is 7-12. Less is better because then the voltage regulator will have less work to do and it has no heatsink so it gets hot.

These days, supplying power via USB or 5V to the 5V pin is preferred. I usually use an old USB phone charger.


It works perfectly with the 7,5V setting. Thank you a lot for your answers and your quick replies.
Have a nice day !