initial commit
initial commit

--- /dev/null
+++ b/LipoStorage/LipoStorage.ino
@@ -1,1 +1,79 @@
+/**
+* Arduino lipo battery discharger to storage minimumVoltage=3.85v
+* For this you need :
+* - arduino board. I used arduino micro
+* - voltage sensor - http://www.aliexpress.com/store/product/10pcs-New-Voltage-Sensor-Module-For-Robot-Arduino/341125_1352801407.html
+* - relay shield - http://www.aliexpress.com/item/2-Channel-2-channel-2-way-5V-Relay-Shield-Module-for-ARM-PIC-AVR-DSP/1971554348.html
+*/
 
+#include <Wire.h>
+
+int debug = 1;
+
+int analogValue;
+float voltage;
+float minimumVoltage = 3.85;
+int timesUnderMinimumVoltage = 0;
+int maxUnderMinimumVoltage = 5;
+bool relayActivated = false;
+
+void setup() 
+{
+  if ( debug ) {
+    Serial.begin(9600);
+  }
+  if ( debug >= 3 ) {
+    Serial.println("Voltage: x.xx V");
+  }
+}
+
+void loop() 
+{
+  analogValue=analogRead(1);
+  if ( debug >= 3 ) {
+    Serial.print("analogValue : ");
+    Serial.println(analogValue);
+  }
+  
+  voltage=analogValue/4.092/10;  
+  if ( debug >= 1 ) {
+    Serial.print("Voltage : ");
+    Serial.print(voltage);
+    Serial.println(" V");
+  }
+  
+  if ( relayActivated == false ) {
+    if ( voltage <= minimumVoltage ) {
+      timesUnderMinimumVoltage++;
+      if ( debug >= 2) {
+        Serial.print("timesUnderMinimumVoltage : ");
+        Serial.println(timesUnderMinimumVoltage);
+      }
+    }
+    if ( timesUnderMinimumVoltage >= maxUnderMinimumVoltage ) {
+      relayActivated = true;
+      if ( debug >= 1 ) {
+        Serial.println("Send signal to relay to disconnect battery");
+        // to do relay part
+      }
+    }    
+  } else {
+    if ( voltage > minimumVoltage && timesUnderMinimumVoltage > 0 ) {
+      timesUnderMinimumVoltage--;
+      if ( debug >= 2) {
+        Serial.print("timesUnderMinimumVoltage : ");
+        Serial.println(timesUnderMinimumVoltage);
+      }
+    }
+    if ( timesUnderMinimumVoltage == 0 ) {
+      relayActivated = false;
+      if ( debug >= 1 ) {
+        Serial.println("Send signal to relay to reconnect battery");
+        // to do relay part        
+      }      
+    }
+  }
+  
+  delay(500);
+}

+

comments