void setup() { pinMode(A1,INPUT);//analog input for reading the data from the photoresistor. Serial.begin(9600);//creates a channel on Serial Monitor to communicate with the PC Arduino IDE.(NOTE:if your serial monitor is set in another value,you will not be able to read incoming data form Serial Monitor) pinMode(2,INPUT);//button for setting the natural light level pinMode(5,OUTPUT);//LED indication for calibrating the sensor pinMode(9,OUTPUT);//LED that informs you that a Lightning strike was detected the past second pinMode(6,OUTPUT);//LED to show that calibration has ended pinMode(3,OUTPUT);//LED to show number of lightnings } int table1[];//table to keep luminance data about each ligtning(can only be printed through Serial Monitor,not from the LED) int i;//The first counter int ii=0;//this determines the position of the luminance data on the lightning table int iii;//this is the counter of the Serial.print command,that runs a block of code(serial print) iii times int iiii=0;//this variable ensures that the first piece of code will just run once int iiiii;//this variable is to count the flashes of the indicating LED 2,that shows the number of lightnings detected. int a;//This is the calibration variable.When the button is pressed for the first time,it stores a value that is later deduced from the sensor reading to determine the "0 level" of readings. void loop() { if (iiii==0) //runs just one time,when the program starts { Serial.print("Program Started"); Serial.print("\n"); Serial.print("Waiting for calibration....."); Serial.print("\n"); for (i=0; i<50000; i++)//5000 is to delay the end of the whole process of checking if the button is pressed { if (digitalRead(2)==HIGH)//Button press { digitalWrite(5,HIGH);//indicates that calibration is ongoing a=analogRead(A1); delay(1000); digitalWrite(5,LOW); break; } } digitalWrite(6,HIGH);//LED indicates that clibration of the sensor is done delay(1000); Serial.print("Calibrated!");//Serial print for the same reason Serial.print("\n"); digitalWrite(6,LOW); iiii=1;//gives the "1" value to iiii to ensure that the first block of code never runs again(unless the programm is restardet,e.g. because you unplugged power or change powersource with a drop of voltage) } if ((analogRead(A1)-a)>10)//Checks if the luminance level is above the usual."10" Determines the sensitivity of the programm(bigger number,less sensitiva, and the opposite) { table1[ii]=analogRead(A1);//stores the value of the sensor to the table1, on position "ii" ii++; digitalWrite(9,HIGH);//LED flash to show that a lightning just detected delay(1000);//delay to ensure that the programm doesnt detect the same lightning twice(or more times,a lightning can last a few miliseconds,time enough for the programm to make a full cycle) digitalWrite(9,LOW); } if (digitalRead(2)==HIGH)//if button is pressed for second(or third,or fourth...) time,it displays both a serial print and an LED "print" of the times a lightning has been detected { Serial.print("Every individual Lightning: "); if(ii==0) Serial.print("No lightnings yet"); digitalWrite(6,HIGH); delay(500); digitalWrite(6,LOW); for (iii=0; iii