Is possible notify if a led have fault enegy or if he disconnect?

Hello everybody, this is my first post here.
So I'm relative new in Arduino, and I'm a trainee in a company, they are introducing me arduino, and i have to notify by SMS, if led is disconnected or has fault energy and if i click a button he notify the change, but at now i can't make him notify if he loss connection or have fault energy of the LED. Hope someone can give me some Tips, cause I'm really new on this. :frowning: :confused:

Here is my code:

#include <SoftwareSerial.h>
SoftwareSerial mySerial(8, 9);
#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal.h>
#include <LiquidCrystal_I2C.h>

#define I2C_ADDR 0x3F
LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);

const int buttonPin = 7;
int buttonState = 0;
int ledPin = A0;
int val = 0;

void setup(){
lcd.begin(16,2);
lcd.backlight();
lcd.setCursor(0,0);
lcd.print("");
Serial.begin(9600);
mySerial.begin(9600);
pinMode(ledPin, OUTPUT);
delay(1000);
}

void loop(){

val = analogRead(ledPin);
if(val != analogRead(ledPin)){

lcd.setCursor(0,0);
lcd.print("");
lcd.setCursor(0,0); //First line
lcd.print(" WARNING !!");
warningMessage();

}

while (digitalRead(buttonPin) == LOW ){

if(buttonState == 0) {

// EnviaSMS1();
Serial.print(buttonState);
lcd.setCursor(0,0);
lcd.print("");
lcd.setCursor(0,0); //First line
String BtnState = "Button state ";
lcd.print(BtnState + buttonState);

buttonState = 1;

digitalWrite(ledPin, HIGH);

}

}

while (digitalRead(buttonPin) == LOW ){

if(buttonState == 1) {

// EnviaSMS1();
Serial.print(buttonState);
lcd.setCursor(0,0);
lcd.print("");
lcd.setCursor(0,0); //First line
String BtnState = "Button state ";
lcd.print(BtnState + buttonState);

buttonState = 0;

digitalWrite(ledPin, HIGH);

}

}

}

void warningMessage(){

mySerial.println("AT+CMGF=1");
delay(100);
mySerial.println("AT+CMGS="+XXXXXXXXXXXX"");
delay(100);
mySerial.print("Led turn off!");
delay(500);
mySerial.print(char(26));
delay(100);
mySerial.println("");
delay(100);

}

void EnviaSMS1(){
mySerial.println("AT+CMGF=1");
delay(100);
mySerial.println("AT+CMGS="+XXXXXXXXXXXX"");
delay(100);
mySerial.print("Value 0!");
delay(500);
mySerial.print(char(26));
delay(100);
mySerial.println("");
delay(100);
}

void EnviaSMS2(){
mySerial.println("AT+CMGF=1");
delay(100);
mySerial.println("AT+CMGS="+XXXXXXXXXXXX"");
delay(100);
mySerial.print("Value 1!");
delay(500);
mySerial.print(char(26));
delay(100);
mySerial.println("");
delay(100);
}

Best regards :slight_smile:

To make it easy for people to help you please modify your post and use the code button </>
codeButton.png

so your code looks like this and is easy to copy to a text editor. See How to use the Forum

Your code is too long for me to study quickly without copying to my text editor. The text editor shows line numbers, identifies matching brackets and allows me to search for things like all instances of a particular variable or function.

Also post a clear wiring diagram so we can see how everything is connected.

I don't understand what you mean by "has fault energy"

Also when you say "if led is disconnected" do you mean that someone might have removed it ?
OR
do you mean that the LED has failed?

...R

or do you mean that the LED is perfectly OK and is connected but just happens to be turned off by the program ?

Rather than posting a large, complicated program perhaps you could post a small but complete example of what you want to do