Getting error after succesful complilation and upload.

Hello Great Minds,

I am new to arduinos, I got this code online and it was running well, but today all of a sudden it started giving error and refused to complile. Please help........

This is the error code............

Arduino: 1.8.5 (Windows Store 1.8.10.0) (Windows 10), Board: "Arduino/Genuino Uno"

C:\Users\RS\AppData\Local\Temp\cc63fwV5.ltrans0.ltrans.o: In function `twi_init':

C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.10.0_x86__mdqgnx93n4wtt\hardware\arduino\avr\libraries\Wire\src\utility/twi.c:76: undefined reference to `digitalWrite'

C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.10.0_x86__mdqgnx93n4wtt\hardware\arduino\avr\libraries\Wire\src\utility/twi.c:77: undefined reference to `digitalWrite'

C:\Users\RS\AppData\Local\Temp\cc63fwV5.ltrans0.ltrans.o:(.rodata+0x18): undefined reference to `Print::write(unsigned char const*, unsigned int)'

c:/program files/windowsapps/arduinollc.arduinoide_1.8.10.0_x86__mdqgnx93n4wtt/hardware/tools/avr/bin/../lib/gcc/avr/4.9.2/../../../../avr/lib/avr5/crtatmega328p.o:(.init9+0x0): undefined reference to `main'

collect2.exe: error: ld returned 1 exit status

exit status 1 Error compiling for board Arduino/Genuino Uno.

This code is currently running ok on the board.

If it compiled before are you sure you have not inadvertently made a change.

You should post your code, make sure you enclose it in the </> tags.

Try closing all Arduino IDE windows and then restart the Arduino IDE. This will clear the cache and hopefully solve the problem.

#include <LiquidCrystal_I2C.h>
#include <Wire.h>
#define DS3231_I2C_ADDRESS 0x68
LiquidCrystal_I2C lcd(0x3F,2,1,0,4,5,6,7);  // Set the LCD I2C address

////Convert normal decimal numbers to binary coded decimal.
byte decToBcd(byte val)
{
return ( (val/10*16) + (val%10) );
}

////Convert binary coded decimal to normal decimal numbers.
byte bcdToDec(byte val)
{
return ( (val/16*10) + (val%16) );
}

////Stops the clock, but it has the side effect of setting seconds to 0.
/*void stopDs1307()
{
Wire.beginTransmission(DS1307_I2C_ADDRESS);
Wire.write(0);
Wire.writeWire.writeWire.write(0x80);
Wire.endTransmission();
}*/

////1) Sets date and time on the clock.
////2) Starts the clock.
////3) Sets hour mode to 24 hours.
void setDS3231time(
byte second, ////0-59
byte minute, ////0-59
byte hour, ////1-23
byte dayOfWeek, ////1-7
byte dayOfMonth, ////1-28/29/30/31
byte month, ////1-12
byte year) ////0-99
{
Wire.beginTransmission(DS3231_I2C_ADDRESS);
Wire.write(0);
Wire.write(decToBcd(second)); ////0 to bit 7 starts the clock
Wire.write(decToBcd(minute));
Wire.write(decToBcd(hour)); ////If you want 12 hours (am/pm) you need to set
////bit 6 (also need to change getDateDs1307)
Wire.write(decToBcd(dayOfWeek));
Wire.write(decToBcd(dayOfMonth));
Wire.write(decToBcd(month));
Wire.write(decToBcd(year));
Wire.endTransmission();
}

////Reads date and time from the clock,
void readDS3231time(
byte *second,
byte *minute,
byte *hour,
byte *dayOfWeek,
byte *dayOfMonth,
byte *month,
byte *year)
{

////Reset the register pointer.
Wire.beginTransmission(DS3231_I2C_ADDRESS);
Wire.write(0);
Wire.endTransmission();
Wire.requestFrom(DS3231_I2C_ADDRESS, 7);

////A few of these need masks because certain bits are control bits.
*second = bcdToDec(Wire.read() & 0x7f);
*minute = bcdToDec(Wire.read());
*hour = bcdToDec(Wire.read() & 0x3f); ////Need to change this for 12 hours (am/pm)
*dayOfWeek = bcdToDec(Wire.read());
*dayOfMonth = bcdToDec(Wire.read());
*month = bcdToDec(Wire.read());
*year = bcdToDec(Wire.read());
}

////Define pump pin outs.
int motorPin1 = 8; //Pump 1 – Flourish Excel
int motorPin2 = 9; //Pump 2 – Flourish Iron
int motorPin3 = 10; //Pump 3 – Flourish
int motorPin4 = 11; //Pump 4 – Flourish
int motorPin5 = 12; //Pump 5 – Flourish

int actled = 13; //Status Led

void setup() ////One time run at each execution.
{
lcd.begin (16,2); // for 16 x 2 LCD module
lcd.setBacklightPin(3,POSITIVE);
lcd.setBacklight(HIGH);
byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;


pinMode(motorPin1, OUTPUT);
pinMode(motorPin2, OUTPUT);
pinMode(motorPin3, OUTPUT);
pinMode(motorPin4, OUTPUT);
pinMode(motorPin5, OUTPUT);
pinMode(actled, OUTPUT);
Wire.begin();
Serial.begin(9600);

////Set date and time on the clock.
////You only need to run this the first time you setup your RTC.
////Set the correct value below and un comment it to run it.

//DS3231 seconds, minutes, hours, day, date, month, year
//setDS3231time(50,33,12,2,14,5,18);
}

////Main programm loop.
void loop()
{

byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
////Serial Monitor Output.

//-----------------------
readDS3231time(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);
Serial.print("Date: ");
Serial.print(dayOfMonth, DEC);
Serial.print("/");
Serial.print(month, DEC);
Serial.print("/");
Serial.print(year, DEC);
Serial.println(" ");
Serial.print(" Day of week: ");
switch(dayOfWeek){
case 1:
 Serial.println("Sunday");
 break;
case 2:
 Serial.println("Monday");
 break;
case 3:
 Serial.println("Tuesday");
 break;
case 4:
 Serial.println("Wednesday");
 break;
case 5:
 Serial.println("Thursday");
 break;
case 6:
 Serial.println("Friday");
 break;
case 7:
 Serial.println("Saturday");
 break;
}
Serial.println(" ");
Serial.print("Time: ");
Serial.print(hour, DEC);
Serial.print(":");
Serial.print(minute, DEC);
Serial.print(":");
Serial.print(second, DEC);
Serial.println(" ");

lcd.home (); 
if(dayOfMonth<10)
lcd.print('0');
lcd.print(dayOfMonth, DEC);
lcd.print("/");
if(month<10)
lcd.print('0');
lcd.print(month, DEC);
lcd.print("/");
if(year<10)
lcd.print('0');
lcd.print(year, DEC);

lcd.print(" ");
switch(dayOfWeek){
case 1:
 lcd.println("Sunday ");
 break;
case 2:
 lcd.println("Monday ");
 break;
case 3:
 lcd.println("Tue");
 break;
case 4:
 lcd.println("Wed");
 break;
case 5:
 lcd.println("Thur");
 break;
case 6:
 lcd.println("Fri");
 break;
case 7:
 lcd.println("Sat");
 break;
 }

lcd.setCursor ( 0, 1 );        // go to the next line   
lcd.print("Time: ");
if(hour<10)
lcd.print('0');
lcd.print(hour, DEC);
lcd.print(":");
if(minute<10)
lcd.print('0');
lcd.print(minute, DEC);
lcd.print(":");
if(second<10)
lcd.print('0');
lcd.print(second, DEC);

delay(500);
analogWrite(actled, 255);
delay(500);
////Pump Operation
////Everyday: IRON

if((dayOfWeek !=7)&&(hour == 17)&&(minute == 31)&&(second == 10)){

////Start Iron pump 1.5ml
Serial.print("Iron Pump 1.5ml");
Serial.println("");
Serial.println("On");
analogWrite(motorPin1, 255);
delay(1500); // 1000 = aprox 1 ml
analogWrite(motorPin1, 0);
Serial.println("");
Serial.println("Off");

////Monday: kno3, kho2s4, pso4
if(dayOfWeek == 2){

////Start kno3 7.5ml
Serial.print(" Flourish Excel Pump 7.5ml");
Serial.println("");
Serial.println("On");
analogWrite(motorPin2, 255);
delay(7500); // 1000 = aprox 1 ml
analogWrite(motorPin2, 0);
Serial.println("");
Serial.println("Off");

////Start kho2s4  1.5ml
Serial.print("kho2s4 Pump 1,5ml");
Serial.println("");
Serial.println("On");
analogWrite(motorPin3, 255);
delay(1500); // 1000 = aprox 1 ml
analogWrite(motorPin3, 0);
Serial.println("");
Serial.println(" Off");

////Start kho2s4  1.5ml
Serial.print("kho2s4 Pump 1,5ml");
Serial.println("");
Serial.println("On");
analogWrite(motorPin4, 255);
delay(1500); // 1000 = aprox 1 ml
analogWrite(motorPin4, 0);
Serial.println("");
Serial.println(" Off");

}

////TUESDAY
if(dayOfWeek == 2){

////Start Micro pump
Serial.print(" Micro Pump 1,5ml");
Serial.println(" ");
Serial.println("On");
analogWrite(motorPin3, 255);
delay(1500); // 1000 = aprox 1 ml
analogWrite(motorPin3, 0);
Serial.println("");
Serial.println("Off");

}


////Wednesday: kno3, kho2s4, pso4
if(dayOfWeek == 3){

////Start kno3 7.5ml
Serial.print(" Flourish Excel Pump 7.5ml");
Serial.println("");
Serial.println("On");
analogWrite(motorPin2, 255);
delay(7500); // 1000 = aprox 1 ml
analogWrite(motorPin2, 0);
Serial.println("");
Serial.println("Off");

////Start kho2s4  1.5ml
Serial.print("kho2s4 Pump 1,5ml");
Serial.println("");
Serial.println("On");
analogWrite(motorPin3, 255);
delay(1500); // 1000 = aprox 1 ml
analogWrite(motorPin3, 0);
Serial.println("");
Serial.println(" Off");

////Start kho2s4  1.5ml
Serial.print("kho2s4 Pump 1,5ml");
Serial.println("");
Serial.println("On");
analogWrite(motorPin4, 255);
delay(1500); // 1000 = aprox 1 ml
analogWrite(motorPin4, 0);
Serial.println("");
Serial.println(" Off");

}

////Thursday
if(dayOfWeek == 4){

////Start Micro pump
Serial.print(" Micro Pump 1,5ml");
Serial.println(" ");
Serial.println("On");
analogWrite(motorPin3, 255);
delay(1500); // 1000 = aprox 1 ml
analogWrite(motorPin3, 0);
Serial.println("");
Serial.println("Off");

}


////Friday: kno3, kho2s4, pso4
if(dayOfWeek == 5){

////Start kno3 7.5ml
Serial.print(" Flourish Excel Pump 7.5ml");
Serial.println("");
Serial.println("On");
analogWrite(motorPin2, 255);
delay(7500); // 1000 = aprox 1 ml
analogWrite(motorPin2, 0);
Serial.println("");
Serial.println("Off");

////Start kho2s4  1.5ml
Serial.print("kho2s4 Pump 1,5ml");
Serial.println("");
Serial.println("On");
analogWrite(motorPin3, 255);
delay(1500); // 1000 = aprox 1 ml
analogWrite(motorPin3, 0);
Serial.println("");
Serial.println(" Off");

////Start kho2s4  1.5ml
Serial.print("kho2s4 Pump 1,5ml");
Serial.println("");
Serial.println("On");
analogWrite(motorPin4, 255);
delay(1500); // 1000 = aprox 1 ml
analogWrite(motorPin4, 0);
Serial.println("");
Serial.println(" Off");

}


////Saturday
if(dayOfWeek == 6){

////Start Micro pump
Serial.print(" Micro Pump 1,5ml");
Serial.println(" ");
Serial.println("On");
analogWrite(motorPin3, 255);
delay(1500); // 1000 = aprox 1 ml
analogWrite(motorPin3, 0);
Serial.println("");
Serial.println("Off");

}
}

else{

Serial.println ("Pump Status:Off");

////Backup Close Pump
analogWrite(motorPin1, 0);
analogWrite(motorPin2, 0);
analogWrite(motorPin3, 0);
analogWrite(motorPin4, 0);
analogWrite(actled, 0);

}

// delay(1000);

}

Please always do a Tools > Auto Format on your code before posting it. This will make it easier for you to spot bugs and make it easier for us to read. If you're using the Arduino Web Editor you will not have access to this useful tool. I recommend you to use the standard IDE instead.

Sorry about that, I was unaware of that tool....

It's super handy. It is a really good troubleshooting tool. If you're ever having a problem, do an auto format and then look over your code to see if the automatic formatting matches your expected program structure. You can use the Ctrl + T shortcut key to make it even easier to do an Auto Format.

Got the solution.......

It's not the code but the windows 10 OS which is actually preventing the code from compiling. The same code has no problem in compiling on windows 7 pc.

Solution...

Just need to run IDE in compatibility mode for windows 7, and things would work fine.

Thanks