Advertisement
Guest User

arduino voltmeter

a guest
Jan 16th, 2013
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. // voltmeter sketch in Arduino
  2. // implemented on chipKIT UNO32 Microcontroller
  3. // by: Devin Cohen
  4. // date: 1/16/2013
  5. const int voltagePin = A0; // analog input
  6. const int maxDigital = 1024; // 10 bit ADC
  7. const int delayTime = 100; // milliseconds
  8. int adcValue;
  9. const float referenceVoltage = 3.30; // board voltage
  10. float voltage;
  11.  
  12. void setup() {
  13. pinMode(voltagePin, INPUT);
  14. Serial.begin(9600); // open up usb to serial connection
  15. // "COM4" on my computer, 9600 baud
  16. }
  17.  
  18. void loop(){
  19. delay(delayTime);
  20. adcValue = analogRead(voltagePin); // read from ADC
  21. voltage = referenceVoltage * adcValue / maxDigital; // converts digital data
  22. // to actual voltage
  23. Serial.print(voltage);
  24. Serial.print(" V\n"); // output to serial
  25. }
  26.  
  27. """ voltmeter.py
  28. by: Devin Cohen
  29. date: 1/16/2013
  30. uses the pyserial extention
  31. (http://pypi.python.org/pypi/pyserial)"""
  32.  
  33. import serial
  34. ser = serial.Serial("COM4",9600) """ open serial
  35. connection on COM4, 9600 baud """
  36. while 1:
  37. readin = ser.readline() """ read line
  38. from serial and print it """
  39. print readin
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement