Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- float vout = 0.0;
- float vin = 0.0;
- float R1 = 20000.0;
- float R2 = 3300.0;
- int value = 0;
- void setup()
- {
- pinMode(A2, INPUT);
- Serial.begin(115200); //I use 115200 because it's fast ;) but you can use 9600 if you want. You'd have to change the baud rate in the c# program to 9600 if you do as serial ports' baud rates need to be the same
- }
- void loop()
- {
- value = analogRead(A2); //read the analogue voltage
- vout = (value * 5.0) / 1024.0; //math
- vin = (vout / (R2 / (R1+R2))); //more math, this also uses the resistor values too.
- String msg = String(vin + 1) + "v"; //creates a string with the end voltage (e.g, 11 + 1 as it's a bit inaccurate) and adds "v" for volts
- Serial.println(msg); //sends it
- delay(250);
- //this delay is used to avoid flooding the serial port. if you want faster updates, it'd change this to a minimum of 25. Put at 100 for updates every 1/10th of a second, or every 0.1 seconds
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement