Good day everyone, forgive me for the shabby drawing I am just panicking, why my float switches are suddenly undetected by my Arduino mega. I've tested all the float switches one by one to confirm if everything is working just before installing it..
i have 18 sets of float switches, 5 pumps being controlled by the relay, my main PSU is 12V 20A. The yellow rectangle stands for the float switch, the purple line is connected to digital pins from between and 10k ohm resistor and the switch. the green line is a common ground connection from the 5.2V buck (psu for devices that need 5 to 5.5v) to the Arduino mega's gnd.
here's my code, and its not the project code, just a simple test sketch because my float switches are suddenly acting weird:
#include <OneWire.h>
#include "OneButton.h"
#include <DallasTemperature.h>
#include "GravityTDS.h"
#include <EEPROM.h>
#include "Wire.h" // Include the I2C Wire Library
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,20,4);
#define bp1 (uint8_t) 10 /*Button 1*/
#define bp2 (uint8_t) 11 /*Button 2*/
#define bp3 (uint8_t) 12 /*Button 3*/
OneButton btn1 = OneButton(bp1,false,false); uint8_t bx1 = 0;
OneButton btn2 = OneButton(bp2,false,false); uint8_t bx2 = 0;
OneButton btn3 = OneButton(bp3,false,false); uint8_t bx3 = 0;
//Float Switches...........
/*Collector Float Switch*/
#define CT_Fs2 (uint8_t) 9
/*Sieve & Cloth*/
#define SC_Fs1 (uint8_t) 8
/*Primary Test Tank*/
#define PT_Fs1 (uint8_t) 7
#define PT_Fs2 (uint8_t) 6
/*Grease Trap*/
#define GT_Fs1 (uint8_t) 5
/*First Filtration*/
#define FFP_Fs1 (uint8_t) 4
#define FFP_Fs2 (uint8_t) 3
/*Sediment Filter*/
#define SD_Fs1 (uint8_t) 2
/*Second Filtration Passed*/
#define SP_Fs1 (uint8_t) 24
#define SP_Fs2 (uint8_t) 25
/*Final Test Tank*/
#define FT_Fs1 (uint8_t) A7
#define FT_Fs2 (uint8_t) A8
/*Tank A*/
#define TA_Fs1 (uint8_t) 45
#define TA_Fs2 (uint8_t) 47
/*Tank B*/
#define TB_Fs1 (uint8_t) 42
#define TB_Fs2 (uint8_t) 43
/*Tank C*/
#define TC_Fs1 (uint8_t) 40
#define TC_Fs2 (uint8_t) 41
void setup()
{
Serial.begin(9600); /* Show Serial Monitor */
lcd.begin(); /* LCD Screen Set Up */
//---------------------------------------------------------------------dont forget to set up the pins
//ALL DIGITAL PINS ARE INPUT AS DEFAULT, DECLARE ONLY IF MODE IS OUTPUT:
pinMode(FT_Fs1,INPUT);
pinMode(FT_Fs2,INPUT);
//----------------------------------------------------------------------One Button Single Click event attachment
btn1.attachClick(handleClick1);
btn2.attachClick(handleClick2);
btn3.attachClick(handleClick3);
}
//simple show txt on LCD Screen
void lcd_print(String txt ,uint8_t a, uint8_t b)
{ lcd.setCursor(a,b); lcd.print(txt);}
void loop()
{
FSTester();
}
void FSTester() // to check FLOAT SWITCH
{
if (digitalRead(CT_Fs2) == 1)
{
lcd.clear();
lcd_print("CT_Fs2 Detected",0,1);
delay(5000);
}
else if (digitalRead(SC_Fs1) == 1)
{
lcd.clear();
lcd_print("SC_Fs1 Detected",0,1);
delay(5000);
}
else if (digitalRead(PT_Fs1) == 1)
{
lcd.clear();
lcd_print("PT_Fs1 Detected",0,1);
delay(5000);
}
else if (digitalRead(PT_Fs2) == 1)
{
lcd.clear();
lcd_print("PT_Fs2 Detected",0,1);
delay(5000);
}
else if (digitalRead(GT_Fs1) == 1)
{
lcd.clear();
lcd_print("GT_Fs1 Detected",0,1);
delay(5000);
}
else if (digitalRead(FFP_Fs1) == 1)
{
lcd.clear();
lcd_print("FFP_Fs1 Detected",0,1);
delay(5000);
}
else if (digitalRead(FFP_Fs2) == 1)
{
lcd.clear();
lcd_print("FFP_Fs2 Detected",0,1);
delay(5000);
}
else if (digitalRead(SD_Fs1) == 1)
{
lcd.clear();
lcd_print("SD_Fs1 Detected",0,1);
delay(5000);
}
else if (digitalRead(SP_Fs1) == 1)
{
lcd.clear();
lcd_print("SP_Fs1 Detected",0,1);
delay(5000);
}
else if (digitalRead(SP_Fs2) == 1)
{
lcd.clear();
lcd_print("SP_Fs2 Detected",0,1);
delay(5000);
}
else if (digitalRead(FT_Fs1) == 1)
{
lcd.clear();
lcd_print("FT_Fs1 Detected",0,1);
delay(5000);
}
else if (digitalRead(FT_Fs2) == 1)
{
lcd.clear();
lcd_print("FT_Fs2 Detected",0,1);
delay(5000);
}
else if (digitalRead(TA_Fs1) == 1)
{
lcd.clear();
lcd_print("TA_Fs1 Detected",0,1);
delay(5000);
}
else if (digitalRead(TA_Fs2) == 1)
{
lcd.clear();
lcd_print("TA_Fs2 Detected",0,1);
delay(5000);
}
else if (digitalRead(TB_Fs1) == 1)
{
lcd.clear();
lcd_print("TB_Fs1 Detected",0,1);
delay(5000);
}
else if (digitalRead(TB_Fs2) == 1)
{
lcd.clear();
lcd_print("TB_Fs2 Detected",0,1);
delay(5000);
}
else if (digitalRead(TC_Fs1) == 1)
{
lcd.clear();
lcd_print("TC_Fs1 Detected",0,1);
delay(5000);
}
else if (digitalRead(TC_Fs2) == 1)
{
lcd.clear();
lcd_print("TC_Fs2 Detected",0,1);
delay(5000);
}
else
{
lcd.clear();
lcd_print("NOTHING",0,1);
}
}
I've checked for continuity and everything is fine. why is it weird?
somebody please correct my mistakes