Advertisement
learnelectronics

Arduino LipoChecker

Jun 30th, 2017
4,792
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.94 KB | None | 0 0
  1. /*
  2.  * Arduino LiPo Checker
  3.  *
  4.  * learnelectronics
  5.  * 30 JUN 2017
  6.  *
  7.  * www.youtube.com/c/learnelectronics
  8.  *
  9.  *
  10.  *
  11.  * NOTE: My 18650 gave these readings, yours may differ. If it does simply change the values in the if statements:
  12.  *
  13.  * 4.2V   975
  14.  * 3.7V   882
  15.  * 2.7V   650
  16.  */
  17.  
  18. #define red   6
  19. #define yellow 4
  20. #define green 3
  21. #define lipo  A0
  22.  
  23. float lipoV = 0;
  24.  
  25.  
  26.  
  27.  
  28.  
  29. void setup() {
  30.  
  31. pinMode(red,OUTPUT);
  32. pinMode(yellow,OUTPUT);
  33. pinMode(green,OUTPUT);
  34. pinMode(lipo,INPUT);
  35. Serial.begin(9600);
  36. }
  37.  
  38. void loop() {
  39.  
  40. lipoV = analogRead(lipo);
  41.  
  42.  
  43. Serial.println(lipoV);
  44.  
  45. if(lipoV<650){
  46.   digitalWrite(red,HIGH);
  47.   digitalWrite(yellow,LOW);
  48.   digitalWrite(green,LOW);
  49. }
  50. if(lipoV>800 && lipoV<950){
  51.   digitalWrite(red,LOW);
  52.   digitalWrite(yellow,HIGH);
  53.   digitalWrite(green,LOW);
  54. }
  55. if(lipoV>950){
  56.   digitalWrite(red,LOW);
  57.   digitalWrite(yellow,LOW);
  58.   digitalWrite(green,HIGH);
  59. }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement