0

my set up

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

5
  • 2
    "suddenly acting weird" doesn't give us much to go on. I'd suggest trying a small fragment of your code that only uses one float switch and get that working. Then add in the rest of them (with any modifications you might have had to make for the first one). Is it possible that the switches work in the opposite sense from which your testing them? You're testing for HIGH - are they in fact switching to LOW? Otherwise, we'll need to know what you expected your code to do, and what it is doing instead. And it will still be helpful to reduce it to just one relay - i.e. the simplest case that fails.
    – JRobert
    May 1, 2021 at 12:30
  • What is the yellow component in your drawing and what are the green/purple connection?
    – Sim Son
    May 1, 2021 at 12:47
  • 1
    What is the reason, that you are using an additional buck power supply for - what I assume from your drawing - are just simple switches? Why not just directly using the Arduinos 5V pin for that?
    – chrisl
    May 1, 2021 at 13:24
  • 1
    Your diagram is almost impossible to follow. Can you sketch out the actual wiring without using coloured boxes, etc? In particular the part about the switch. We assume you are supplying power to the various devices, you don't need to show that. Possibly the inputs to your switch are "floating" (that is, indeterminate) in either the open or closed position.
    – Nick Gammon
    May 2, 2021 at 7:40
  • See my page about switches and if that helps I can make an answer along those lines (if there isn't one already which there probably is).
    – Nick Gammon
    May 2, 2021 at 7:42

1 Answer 1

1

It is difficult to determine from the diagram if the green wire is at the same voltage as the black wire supplying power to the Arduino board. Even if they are connected, it is difficult to say if the current is nominal. As there is a power supply of unknown design involved for both the Arduino and the float switch.

This could cause unexpected results and may even permanently damage sensitive parts. Consider using a design with only one power supply thereby mitigating the risk of unexpected results.

2
  • The assumption is that your code, sensors and pump all worked together at one point ("on the test bench"). So the code probably works. And only after you installed it and ran it for a while did you notice that it fails. Is that correct?
    – st2000
    May 1, 2021 at 12:56
  • You're new @princessbubbles15. If the above answers your question select it as the correct answer. If you want to wait and try it fist to see if it works that's ok too. Or write a comment/question here if something is not clear and I'll edit the answer. Feel free to edit your question too if you find you forgot to ask something in particular.
    – st2000
    May 2, 2021 at 18:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.