1. #include <LiquidCrystal.h>
  2. LiquidCrystal lcd(12, 11, 10, 9, 8, 7);
  3. const float referenceVolts = 5; // the default reference on a 5-volt board
  4. //const float referenceVolts = 3.3; // use this for a 3.3-volt board
  5. const float R1 = 10000; // value for a maximum voltage of 10 volts
  6. const float R2 = 10000;
  7. // determine by voltage divider resistors, see text
  8. const float resistorFactor = 1023.0 / (R2/(R1 + R2));
  9. const int batteryPin = 0; // +V from battery is connected to analog pin 0
  10. int sensorPin3 = A3; // select the input pin for the potentiometer
  11. int sensorValue0 = 0; // variable to store the value coming from the sensor
  12. int sensorValue3 = 0; // variable to store the value coming from the sensor
  13. void setup() {
  14. // initialize serial communication at 9600 bits per second:
  15. Serial.begin(9600);
  16. lcd.begin(20,4); // columns, rows. use 16,2 for a 16x2 LCD, etc.
  17. lcd.clear(); // start with a blank screen
  18. }
  19. void loop() {
  20. int val = analogRead(batteryPin); // read the value from the sensor
  21. float volts = (val / resistorFactor) * referenceVolts ; // calculate the ratio
  22. Serial.print("Volts :");
  23. Serial.println(volts); // print the value in volts
  24. float average = 0;
  25. for(int i = 0; i < 1000; i++) {
  26. average = average + (.0264 * analogRead(A3) -13.51) / 1000;
  27. delay(1);
  28. }
  29. Serial.print("Amps :");
  30. Serial.println(average);
  31. lcd.setCursor(0,0); // set cursor to column 0, row 0 (the first row)
  32. lcd.print("Volts:"); // change this text to whatever you like. keep it clean.
  33. lcd.setCursor(0,1); // set cursor to column 0, row 1
  34. lcd.print(volts);
  35. // if you have a 4 row LCD, uncomment these lines to write to the bottom rows
  36. // and change the lcd.begin() statement above.
  37. lcd.setCursor(0,2); // set cursor to column 0, row 2
  38. lcd.print("Amps");
  39. lcd.setCursor(0,3); // set cursor to column 0, row 3
  40. lcd.print(average);
  41. }