Sunday 12 February 2017

pwm - 12V - How to activate an electric item if battery is full


I have a solar system 12V connected to a PWM controller 20A and a lead-acid battery 80Ah deep cycle.


What kind of setup should I make to activate a pump (12V) if the battery is full ( >13.8V ) ?




Answer



So here is what I did :


1 - I connected an Arduino to collect analog outputs from a voltage sensor PCB. (connected on 5v pin, ground and Analog 0 or A0)


2 - The analog data is sent through the usb cable to my raspberry pi. (You have to install on the raspberry pi : sudo apt-get install arduino arduino-mk)


ON RASPBERRY :


1 - Create a file named "Makefile" in the project's folder.


ARDUINO_DIR = /usr/share/arduino
ARDUINO_PORT = /dev/ttyACM*

USER_LIB_PATH = /home/pi/ARDUINO/librairies

BOARD_TAG = uno

include /usr/share/arduino/Arduino.mk

2 - Create the arduino code


void setup(){
Serial.begin(9600);
}

void loop(){

/* Voltage sensor on A0 */
int volt = analogRead(A0);
double voltage_a0 = map(volt, 0, 1023, 0, 2500);
voltage_a0 /= 100;
Serial.println(voltage_a0,1);
delay(10000);
}

3 - Run the code on the arduino and check Serial output


make upload monitor clean


3 - Leave the monitoring system with CTRL + A and then CTRL + D


4 - Close all screen with screen -X quit (otherwise it will not be available)


5 - You can now read the arduino Serial manually with cat /dev/ttyACM0 but I created a script for reading it every 45 seconds, and write it in a file in a "logs" folder with the date as filename (keep running in the background with screen) :


#!/bin/bash
while [ 1 ]; do
TODAY=$(date +%Y_%m_%d)
read DUMP < /dev/ttyACM0 #DUMP
sleep 2
read ARDUINO_LINE < /dev/ttyACM0 #(arduino every 10s) Example : 14.7

TIME=$(date +%R)
if [[ "$TIME" != "$OLD_TIME" ]]; then
echo "${TIME}=${ARDUINO_LINE}"
echo "${TIME}=${ARDUINO_LINE}" >> "logs/$TODAY"
fi
OLD_TIME=$TIME
sleep 45
done

6 - Now i have every day a file in logs called for example 2019_07_30 and it contains 1440 lines like this one : 14:40=14.2. I can use this file to create a graph with for example libre office.



7 - NOT DONE YET. I just need to add some relays that will be controlled by the raspberry pi. (I will edit this post as soon as it's done.)


No comments:

Post a Comment

arduino - Can I use TI&#39;s cc2541 BLE as micro controller to perform operations/ processing instead of ATmega328P AU to save cost?

I am using arduino pro mini (which contains Atmega328p AU ) along with cc2541(HM-10) to process and transfer data over BLE to smartphone. I...