Automatic Battery Voltage monitor and Selector CloudX

  • img
Project Details

This is a project that automatically selects between two batteries, it triggers the relay to switch to the second battery if the first battery voltage is less than 10V, if the second battery is less than 10V too then the two relays disconnects from supplying outputs. This project allows people to use more than one battery system to power up a device and it can also be used in many applications. You can watch YouTube Video.

 

CLOUDX M633 (PIC16F877A) Pinouts

 

Circuit Diagram

 

Code

/* 
* File: switcher.c
* Author: BYTEHUB
*
* Created on 28 March 2019, 15:35
*/

#define _XTAL_FREQ 20000000
// PIC16F877A Configuration Bit Settings

// 'C' source line config statements

#include <CloudX\PIC16F877A.h>

// CONFIG
#pragma config FOSC = HS
#pragma config WDTE = OFF
#pragma config PWRTE = ON
#pragma config BOREN = OFF
#pragma config LVP = OFF
#pragma config CPD = OFF
#pragma config WRT = OFF
#pragma config CP = OFF

#include <CloudX\LCD.h>
#include <CloudX\ADC.h>
#include <CloudX\conversion.h>
#include <CloudX\string.h>

const char degreeSign[] = {0x0E, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F};

float readB1,readB2;
char *str;

#define RLY1 11
#define RLY2 12

#define LED1 9
#define LED2 10

void BattTwo(){

if(readB2 < 10.0) {
LCD_writeTextCP("NONE");
digitalWrite(RLY1, 0);
digitalWrite(RLY2, 0);
digitalWrite(LED1, 0);
digitalWrite(LED2, 0);
}
else {
LCD_writeTextCP("2 ");
digitalWrite(RLY1, 0);
digitalWrite(RLY2, 1);
digitalWrite(LED1, 0);
digitalWrite(LED2, 1);
}

}

void BattOne(){
LCD_writeTextCP("1 ");
digitalWrite(RLY1, 1);
digitalWrite(RLY2, 0);
digitalWrite(LED1, 1);
digitalWrite(LED2, 0);
}
setup(){
LCD_setting(8,7,6,5,4,3);
Analog_setting();
LCD_cmd(clear);
LCD_cmd(cursorOff);
LCD_writeText(1,5,"CloudX");
LCD_writeText(2,1,"Battery Switcher");
delay(2000);
LCD_cmd(clear);
pinMode(RLY1,OUTPUT);
pinMode(RLY2,OUTPUT);
pinMode(LED1,OUTPUT);
pinMode(LED2,OUTPUT);

loop(){
LCD_writeText(1,1,"Active: ");
// LCD_writeText(2,1,"B1: ");
readB1 = Analog_read(A0);
readB2 = Analog_read(A1);
readB1 *= ((float)5/1023) * 10.985;
readB2 *= ((float)5/1023) * 10.985;
readB1 < 10.0 ? BattTwo() : BattOne();
str = floatTostr(readB1);
str[4] = 0;
//LCD_writeText(2,1,": ");
LCD_writeCustomChar(0, 2, 1, degreeSign);
LCD_writeCP(' ');
LCD_writeTextCP(str);
str = floatTostr(readB2);
str[4] = 0;

LCD_writeCustomChar(0, 2, 10, degreeSign);
LCD_writeCP(' ');
LCD_writeTextCP(str);
delay(100);
}
}

 

Bootloading the PIC16F877A

You can load your code directly into the PIC microcontroller using the PICKIT programmer from Microchip or buy the Bootloaded PIC16F877A chip from the cloudx store so that you can program directly into the chip using the softcard programmer. If you want to bootload the chip directly yourself then you can download the bootloader here.

 

 

Wiring your Project

 

 

 

Testing project

Share this with friends