Using voltage sensor switching relay if voltage drops less than 7V

Hey all,
I was using voltage sensor and 2 relays to control my battery output, The batteries are rated as 11.1V but if that battery drops less than 5V the arduino should low (off) that battery and switch to other battery that is been charged. Once the other battery is switched on the delay must be high enough for main battery to charge. This should be a continuous cycle.
I am stuck when voltage sensor is used to give value to relay and finding difficulties with coding as well.

Show us a good schematic of your proposed circuit.
Show us a good image of your ‘actual’ wiring.
Give links to components.

Hey,
I have used an
1.Arduino Uno
2. 2 * 11.1V batteries orange Li-ion
3. 2 Channel 5V Relay * 2 (for if one battery goes below 5V it shuts off and second relay turns on)
4. 2 Voltage sensor (<25V) for voltage sensing.

Arduino should declare low if <5V on relay whose voltage is less than 5V
I have the component and working on actual wiring, can you suggest your way of doing it.

Please show us a schematic, you can draw it on paper and upload a picture of it for us to see.


Take a picture of your wiring and show it to us.


What sensor are you using ?

This is the code written serial pins error, solving it

// Voltage Input to Arduino
const int analogInPin5 = A4;
const int analogInPin6 = A5;

// Assigning the Ouputs to the Relays
const int R1 = 0;         // Relay 1 
const int R2 = 1;         // Relay 2

// Initial States of Inputs/Outputs & Establishing the SetPoint
int sensorValue4 = 0;         // Value Read From Input A3
int sensorValue5 = 0;         // Value Read From Input A4

int setPoint = 300;           // Initial value of setPoint

int R1State = 0;              // Store State of Relay 1
int R2State = 0;              // Store State of Relay 2

int voltage = 0;

void setup() {
  // configure hardware
  pinMode(R1, OUTPUT);      // Set Relay 1 as an Output
  pinMode(R2, OUTPUT);      // Set Relay 2 as an Output

    // read the analog in value
  sensorValue6 = analogRead(analogInPin4);
  sensorValue5 = analogRead(analogInPin5); 
  voltage = sensorValue5 * 5.0/1023;
}

void loop() {

  if(sensorValue4 > setPoint)
    R1State = 1;   
  else
    R1State = 0;
  // Check Voltage Level For Relays 1 & 2

  if (sensorValue5 > setPoint)
  R2State = 1;
  else
  R2State = 0;

  // wait 10 mins before the next loop
  delay(600000);                     
}void setup() {
  // put your setup code here, to run once:

}

void loop() {
  // put your main code here, to run repeatedly:

}

Voltage Detection Sensor Module 25V

const int R1 = 0; // Relay 1
const int R2 = 1; // Relay 2

Pins 0 and 1 are RX and TX.

Use 2 and 3.


sensorValue6 :thinking:



    // read the analog in value
  sensorValue6 = analogRead(analogInPin4);
  sensorValue5 = analogRead(analogInPin5); 
  voltage = sensorValue5 * 5.0/1023;

This should be in loop( )


Only one setup( ) and loop( ) per sketch :wink:


Please show us a schematic, you can draw it on paper and upload a picture of it for us to see.


Edit:
When you connect the sensor to your 11v battery, what is the sensor output read with a DMM , and what volt does the DMM read on the same battery ?

I tried making this diagram where sensor value influences LOW and HIGH on relay and loop until both battery go below 5v or 7v.

// Voltage Input to Arduino  
const int analogInPin1 = A0;   
const int analogInPin2 = A2;

// Assigning the Ouputs to the Relays  
const int R1 = 2;         // Relay 1   
const int R2 = 4;         // Relay 2  

// Initial States of Inputs/Outputs & Establishing the SetPoint  
int sensorValue1 = 0;         // Value Read From Input A0  
int sensorValue2 = 0;         // Value Read From Input A2

int setPoint = 300;           // Initial value of setPoint  

int R1State = 0;              // Store State of Relay 1  
int R2State = 0;              // Store State of Relay 2  

int voltage = 0;


void setup() {  
  // configure hardware  
  pinMode(R1, OUTPUT);      // Set Relay 1 as an Output  
  pinMode(R2, OUTPUT);      // Set Relay 2 as an Output  
}  
void loop() {  
  // read the analog in value  
  sensorValue1 = analogRead(analogInPin1);  
  voltage = sensorValue1 * 5.0/1023;    
    
  // Check Voltage Level For Relays 1 & 2  
  if (sensorValue1 > setPoint)  
R1State = 1;     
  else  
R1State = 0;  
    
  if (sensorValue1 > setPoint)  
  R2State = 1;  
  else  
  R2State = 0;  
  // wait 500 milliseconds before the next loop  
  delay(500);                       
}

I updated code and got compiled though i had concerns about will it work

What relays are you using ?

2 channel 5V relay for arduino input.

Do you have a Digital Volt Meter ?


What are the numbers written on the 2 black resistors circled in yellow ?


t

7501, 3002.

If a 3S LiPo drops below 5volt, then it's probably toast.
2.7volt *3 = 8.1volt is the absolute minimum for survival.
Leo..

Always start with a schematic.


Below is a first try of what should be in that schematic.

Do you understand how this circuit might give you what you need ?

Hey Leo,
Instead of using direct output from LiPo, instead was going to boost it to 12V and, try to keep drainage voltage until 7v or 5v until the time it cuts itself off using relay. My main objective is using arduino code try to control the relay with accordance to voltage sensor.
I have posted my updated code;
Please suggest if its gonna work this way or i should change something.

// Voltage Input to Arduino  
const int analogInPin1 = A0;   
const int analogInPin2 = A2;

// Assigning the Ouputs to the Relays  
const int R1 = 2;         // Relay 1   
const int R2 = 4;         // Relay 2  

// Initial States of Inputs/Outputs & Establishing the SetPoint  
int sensorValue1 = 0;         // Value Read From Input A0  
int sensorValue2 = 0;         // Value Read From Input A2

int setPoint = 300;           // Initial value of setPoint  

int R1State = 0;              // Store State of Relay 1  
int R2State = 0;              // Store State of Relay 2  

int voltage = 0;              //Initial Value of voltage 


void setup() {  
  // configure hardware  
  pinMode(R1, OUTPUT);      // Set Relay 1 as an Output  
  pinMode(R2, OUTPUT);      // Set Relay 2 as an Output  
}  
void loop() {  
  // read the analog in value  
  sensorValue1 = analogRead(analogInPin1);  
  voltage = sensorValue1 * 5.0/1023;    
    
  // Check Voltage Level For Relays 1 & 2  
  if (sensorValue1 > setPoint)  
R1State = 1;     
  else  
R1State = 0;  
    
  if (sensorValue2 > setPoint)  
  R2State = 1;  
  else  
  R2State = 0;  
  
  // wait 10 mins before the next loop  
  delay(600000);                       
}

Shiv

Bed time here, will let Australia take over.

:sleeping:
:bed:

If you do this, then the relay will probably chatter during bootup.
Better to do this:

pinMode(R1, INPUT_PULLUP); // first enable internal pull up
pinMode(R2, INPUT_PULLUP);
pinMode(R1, OUTPUT); // then set pin to output
pinMode(R2, OUTPUT);
  sensorValue1 = analogRead(analogInPin1);  
  voltage = sensorValue1 * 5.0/1023; 

You forgot to include the voltage divider on the analogue input, so 'voltage' will be wrong.
But you don't need this block anyway. This should be enough.

if (analogRead(analogInPin1) > setPoint) {
  // some code
}
else {
  // other code
}

delay(600000);
Study the BlinkWithoutDelay example, and try to use millis() for timing.
Leo..

Which read as 750x10^1, 300x10^2

So 7k5 and 30k, ie 1:4 ratio, the output voltage is 0.2 times the input voltage. So 11.1V will read as 2.22V, 7V as 1.4V

// Voltage Input to Arduino  
const int analogInPin1 = A0;   
const int analogInPin2 = A2;

// Assigning the Ouputs to the Relays  
const int R1 = 2;         // Relay 1   
const int R2 = 4;         // Relay 2  

// Initial States of Inputs/Outputs & Establishing the SetPoint  
int sensorValue1 = 0;         // Value Read From Input A0  
int sensorValue2 = 0;         // Value Read From Input A2

int setPoint = 300;           // Initial value of setPoint  

int R1State = 0;              // Store State of Relay 1  
int R2State = 0;              // Store State of Relay 2  

int voltage = 0;              //Initial Value of voltage 


void setup() {  
  // configure hardware  
  pinMode(R1, INPUT_PULLUP); // first enable internal pull up
  pinMode(R2, INPUT_PULLUP);
  pinMode(R1, OUTPUT); // then set pin to output
  pinMode(R2, OUTPUT);  
}  
void loop() {  
  // read the analog in value
  
  sensorValue1 = analogRead(analogInPin1);  
  float voltage = sensorValue1 * (5.0/1023);
  
  if (analogRead(analogInPin1) > setPoint) {
  R1State = 1;
}
  else {
  R1State = 0; 
}  
  if (analogRead(analogInPin2) > setPoint) {
  R2State = 1;
}
  else {
  R2State = 0; 
} 

  // wait 10 mins before the next loop  
  delay(600000);           


``
t

R1 and R2 and Output pins. Why do you need to declare those as INPUT_PULLUP at first?
However, here is a tutorial that you may find helpful. This is about interfacing two relay modules with Arduino UNO. As same as the output part of your project.

Not helpful at all,
because the article is using a different relay module, that might not need this 'trick'.

Enabling internal pull up before setting the pin to output is only used for the more common relay modules with opto couplers. The only ones that chatter (turn on briefly) during startup.
Leo..