User Manual
www.geolink.io
18 OpenTracker 2 User Manual (1.3)
Battery monitoring (AIN_S_INLEVEL)
OpenTracker hast got the possibility to monitor the input voltage. This is done via the power input (VIN) and
no additional cables have to be connected to the tracker.
Using Battery Monitoring
The following example shows how to measure the Supply voltage and print it to the debug port.
1. #define DEBUG 1 //enable debug msg, sent to serial port
2. #define debug_port SerialUSB
3.
4. #ifdef DEBUG
5. #define debug_print(x) debug_port.print(x)
6. #else
7. #define debug_print(x)
8. #endif
9.
10. // Variables will change:
11. int outputValue;
12. int sensorValue;
13.
14.
15. void setup() {
16. // put your setup code here, to run once:
17.
18. }
19.
20. void loop() {
21.
22. // Read VIN Value
23. // read the analog in value:
24. sensorValue = analogRead(AIN_S_INLEVEL);
25. // map it to the range of the analog out:
26. outputValue = sensorValue * (242.0f / 22.0f * ANALOG_VREF / 1024.0f);
27.
28. // print the results to the serial monitor:
29. debug_print(F("VIN = " ));
30. debug_print(outputValue);
31. debug_print(F("V ("));
32. debug_print(sensorValue);
33. debug_print(F(")"));
34. debug_port.println(" ");
35.
36. delay(1000);
37. }