Advertisement
Guest User

Untitled

a guest
Dec 4th, 2016
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. int LipoType = 0;
  2. float LowVoltage = 0;
  3. int analogInput = 0;
  4. float vout = 0.0;
  5. float vin = 0.0;
  6. float R1 = 100000.0; // resistance of R1 (100K) -see text!
  7. float R2 = 10000.0; // resistance of R2 (10K) - see text!
  8. int value = 0;
  9.  
  10. void setup(){
  11. pinMode(analogInput, INPUT);
  12. Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
  13. Serial.print("Arduino Digital Voltmeter for ZEO OSD");
  14. Serial.println();
  15. value = analogRead(analogInput);
  16. vout = (value * 5.0) / 1024.0; // see text
  17. vin = vout / (R2/(R1+R2));
  18. if (vin<0.09) {
  19. vin=0.0;//statement to quash undesired reading !
  20. }
  21. if (vin >13)
  22. {
  23. LipoType = 4;
  24. }
  25. else if (vin >10)
  26. {
  27. LipoType = 3;
  28. }
  29. else if (vin >6)
  30. {
  31. LipoType = 2;
  32. }
  33. else if (vin >2)
  34. {
  35. LipoType =1;
  36. }
  37. }
  38.  
  39. void loop(){
  40. // read the value at analog input
  41. value = analogRead(analogInput);
  42. vout = (value * 5.0) / 1024.0; // see text
  43. vin = vout / (R2/(R1+R2));
  44. if (vin<0.09) {
  45. vin=0.0;//statement to quash undesired reading !
  46. }
  47. if (LipoType = 4)
  48. {
  49. LowVoltage= vin/4;
  50. }
  51. else if (LipoType = 3)
  52. {
  53. LowVoltage= vin/3;
  54. }
  55. else if (LipoType = 2)
  56. {
  57. LowVoltage= vin/2;
  58. }
  59. else if (LipoType= 1)
  60. {
  61. LowVoltage= vin;
  62. }
  63. Serial.print("INPUT V= ");
  64. Serial.print(vin);
  65. Serial.println();
  66. Serial.print(LipoType);
  67. Serial.print("S");
  68. Serial.println();
  69. Serial.print(LowVoltage);
  70. if (LowVoltage <= 3.6) Serial.print("LOW BATTERY:");
  71. Serial.println();
  72. delay(100);
  73.  
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement