/* Create a voltmeter! No need for a multimeter! To use... (1) have a common ground (connect GND of Arduino to GND of what you're measuring). (2) plug any voltage LESS THAN 5 V into A0 pin to have it displayed on Serial Monitor! In reality, the Arduino's voltage is a BIT less than 5 V, so the reading will be high because it assumes that 5 V is the Arduino's voltage. You'll see all kinds of stuff if A0 is open! */ // you don't have to initialize analog pins int const pin = 0; // A0 // Arduino's voltage float const voltage = 5.0; // Use built-in LED instead of Serial Monitor? bool const useLED = false; // Set true if there is not a computer nearby. // Set true to measure the voltage of pins 0 and 1 // when Serial.begin() has NOT been called // (both pins set at 5 V regardless of Serial.begin). // Note that other RX and TX pins of Arduino Mega // have no voltage set, unless you do Serial#.begin() // which only sets TX to 5 V (RX still not set). // However, when communicating with 3.3 V, // I'm not worried about the pins always // being set to 5 V because it changes the moment I // apply another voltage (such as 3.3 V) to it, // so I think there's just huge resistors in the // Arduino somewhere. void setup() { if (useLED) { pinMode(13, OUTPUT); } else { Serial.begin(9600); } } void loop() { delay(100); if (useLED) { // Don't use linear brightness increase // because the eye perceives brightness exponentially //analogWrite(13,int(analogRead(pin)/4)); // linear analogWrite(13, int(min(pow(2.,analogRead(pin)*8.0/1023),255))); } else { Serial.println(analogRead(pin)*voltage / 1023); } }