I'm wondering how to make it so that if I pull out the connection of the Output pin to the LED that I want to use (the Green LED in this one), then the Arduino returns an Error in the Serial Monitor and does the same thing when I pull the GND connection from either my Breadboard or either LED. Is there a way to consistently detect this?
(code attached below)
Thanks in advance,
Emily
int Green = 2; // Green LED Pin 2
int Red = 4; // Red LED Pin 4
int Time = 2000; // Time for Fuction LED Blinking = 2s (2000ms)
int Time2 = 500; // Time for Error LED Blinking = 0.5s (500ms)
int GNDcheckGreen = 3; // GND Check Green on Pin 3
int GNDcheckRed = 5; // GND Check Red on Pin 5
//int GNDcheckBzz = 10; // GND Check Buzzer on Pin 10
int VoltcheckGreen = 7; // 5V Check Green on Pin 7
int VoltcheckRed = 8; // 5V Check Red on Pin 8
int Bzz = 9; // Buzzer on Pin 9
int ledSate= LOW; // LED State
bool SUGcheckG; // S(tart)U(p)G(round)checkG(reen)
bool SUGcheckR; // S(tart)U(p)G(round)checkR(ed)
unsigned long prevMillis = 0; // Save previousMillis in a Variable
void setup() {
Serial.begin(9600); // Serial Monitor on
pinMode(Green, OUTPUT); // GreenLED = Output
pinMode(Red, OUTPUT); // RedLED = Output
pinMode(LED_BUILTIN, OUTPUT); // Builtin LED on Board = Output
pinMode(GNDcheckGreen, INPUT_PULLUP); // Check for GND as Input_Pullup
pinMode(GNDcheckRed, INPUT_PULLUP);
pinMode(GNDcheckBzz, INPUT_PULLUP);
pinMode(VoltcheckGreen, INPUT); // Check if there's a connection from the Output to the LED
pinMode(VoltcheckRed, INPUT);
pinMode(Bzz, OUTPUT); // Buzzer as Output
Serial.println("--------------------");
Serial.println("Test Green Voltage connection:");
if (digitalRead(VoltcheckGreen == LOW)) {
Serial.println("Green LED receives Voltage");
}
else {
Serial.println("Green LED does not receive Voltage");
}
Serial.println("--------------------"); //
Serial.println("Test Green GND connection:");
if (SUGcheckG == 0) {
Serial.println("GND is not connected to the Green LED");
}
else {
Serial.println("GND is connected to the Green LED");
}
Serial.println("--------------------");
Serial.println("Test Red Voltage connection:");
if (digitalRead(VoltcheckRed) == LOW) {
Serial.println("Red LED receives Voltage");
}
else {
Serial.println("Green LED does not receive Voltage");
}
Serial.println("--------------------"); //
Serial.println("Test Red GND connection:");
if (SUGcheckR == 0) {
Serial.println("GND is not connected to the Red LED");
}
else {
Serial.println("GND is connected to the Red LED");
}
Serial.println("--------------------");
Serial.println("");
Serial.println("--------------------"); // Feedback in Serial Monitor when the Setup is done
Serial.println("Setup Done");
Serial.println("--------------------");
Serial.println("");
}
void loop() {
unsigned long currMillis = millis();
// Current LED State in Serial Monitor
if (digitalRead(GNDcheckGreen) == LOW) {
if (currMillis - prevMillis >= Time) {
// save the last time you blinked the LED
prevMillis = currMillis;
if (ledState == LOW) {
ledState = HIGH;
Serial.println("LED on");
Serial.println("");
}
else {
ledState = LOW;
Serial.println("LED off");
Serial.println("");
}
digitalWrite(Green, ledState);
}
}
if (digitalRead(GNDcheckGreen) == HIGH || digitalRead(GNDcheckRed) == HIGH) { // If either input detects a HIGH signal show errors
Serial.println("GND is not connected to the Breadboard or LEDs or the cable is severely damaged");
Serial.println("");
digitalWrite(Green, LOW);
while (digitalRead(GNDcheckGreen) == HIGH || digitalRead(GNDcheckRed) == HIGH) {
digitalWrite(Red, HIGH);
digitalWrite(LED_BUILTIN, HIGH);
tone(Bzz, 220);
digitalWrite(Green, HIGH);
delay(Time2);
digitalWrite(Red, LOW);
digitalWrite(LED_BUILTIN, LOW);
noTone(Bzz);
digitalWrite(Green, LOW);
delay(Time2);
}
}
}
