Arduino stops running code after disconnecting from computer

I want to make a digital clock with RTC and LCD. It works but when I disconnect it from the computer ıt doesn't works. A 4.5 volt power supply is connected to the Arduino. LCD's light is on but code doesn't works.

#include <virtuabotixRTC.h>
#include <LiquidCrystal.h>   

int CLK_PIN = 6; 
int DAT_PIN = 7; 
int RST_PIN = 8;
virtuabotixRTC myRTC(CLK_PIN, DAT_PIN, RST_PIN); 
int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2; 
LiquidCrystal lcd(rs, en, d4, d5, d6, d7); 
void setup() {
  lcd.begin(16, 2); 
  pinMode(10,HIGH);                                
}
void loop() {
  analogWrite(10,900);
  myRTC.updateTime();okuyoruz
  lcd.clear(); 
  lcd.setCursor(0, 0); 
  lcd.print(myRTC.dayofmonth); 
  lcd.print("/");
  lcd.print(myRTC.month); 
  lcd.print("/");
  lcd.print(myRTC.year); 
  lcd.setCursor(0, 1);
  lcd.print(myRTC.hours); /
  lcd.print(":");
  lcd.print(myRTC.minutes);    
  lcd.print(":");
  lcd.print(myRTC.seconds); 
  delay(1000); 
}

That is my code.

The posted code has several errors. Please post code that compiles and runs.

Also, post a wiring diagram (hand drawn is fine).


This diagram with a RTC
Code runs.

Vin must be between 7V and 12V

I will try it.

Vin must be 7V or greater.

You could try connecting 4.5V to the 5V pin (which won't damage the Arduino, if it is not connected to the PC), but fix the errors in the code first.

6 AA batteries would be good. A 9V battery would be OK but it may only last a few hours
A 5V power bank connected to the USB connector would also work

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.