How measure Any DC Voltage with Arduino ARDVC-01
How measure Any DC Voltage with Arduino ARDVC-01
Using this code and proper hardware you will be able to measure any DC Voltage using Arduoino. You simply need 2 resistors to use them as voltage divider which has been explained in the video. To protect Arduino agains excess of voltage at Analog pin, you need a 5.1V Zener diode. but if you are sure that the voltage never goes above your limit, you don't need zener diode.
Resources for this sketch and video
- How to measure Current using Arduino and ACS712
- How to use Breadboard(video)
- Leran Arduino in 30 Minuetes (video)
- My Arduino Course on Udemy
- Get Early Acess to my videos via Patreon
/*
* Using this Arduino Code and proper resistor values
* any DC voltage can be measured. Watch the video for details.
* Written by Ahmad Shamshiri for Robojax Robojax.com
* on April 24, 2020 at 16:55 in Ajax, Ontario, Canada
*
Watch the video instruction for this sketch:https://youtu.be/t8xwrVj2aFs
You can get the wiring diagram and full explanition of this code from my Arduino Course at Udemy.com
Learn Arduino step by step with all library, codes, wiring diagram all in one place
visit my course now http://robojax.com/L/?id=62
Use the following resistors:
R1 5100 ohm 1% any power 1/4W or 1/8W
12V R2 7200
for the rest watch the video
If you found this tutorial helpful, please support me so I can continue creating
content like this. You can be my Patron and have early access to my videos here http://robojax.com/L/?id=63
or make donation using PayPal http://robojax.com/L/?id=64
*
* Code is available at http://robojax.com/learn/arduino
* This code is "AS IS" without warranty or liability. Free to be used as long as you keep this note intact.*
* This code has been download from Robojax.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
const float arduinoVCC = 5.01;//Your Arduino voltage
unsigned long ValueR1 = 5070;
unsigned long ValueR2 = 7500;
double Voltage_Source = 12;
const int alanogPin = A0;//the pin connecting the voltage.
const int inputResolution =1023;//works with most Arduino boards
const float average_of = 500;//Average of 500 readings
float voltage;
void setup() {
Serial.begin(9600);
Serial.println("Robojax: Reading Any voltage with Arduino");
delay(500);
}
void loop() {
//Robojax.com ARDVC-01 Measure any voltage with Arduino
readVoltage();
Serial.print("Vin: ");
//Serial.print(voltage);
//Serial.print("V Avg: ");
Serial.print(getVoltageAverage());
Serial.println("V");
//delay(100);
//Robojax.com ARDVC-01 Measure any voltage with Arduino
}//loop end
/*
* @brief calculates the input voltage and updates the variable "voltage"
* @param none
* @return does not return anything
* Written by Ahmad Shamshiri
* www.Robojax.com code Ap1il 24 2020 at 17:49 in Ajax, Ontario, Canada
*/
void readVoltage(){
//Robojax.com ARDVC-01 Measure any voltage with Arduino
//This code is explained at my Arduino Course at udemy.com http://robojax.com/L/?id=62
int A0Value = analogRead(alanogPin);
float voltage_sensed = A0Value * (arduinoVCC / (float)inputResolution);
// Serial.print("voltage_sensed:");
// Serial.print(voltage_sensed);
voltage = voltage_sensed * ( 1 + ( (float) ValueR2 / (float) ValueR1) );
//Robojax.com ARDVC-01 Measure any voltage with Arduino
}//readVoltage()
/*
* @brief calculates the average of input voltage and updates the variable "voltage"
* @param none
* @return retuns average of "average_of" iteration of voltage
* Written by Ahmad Shamshiri
* www.Robojax.com code Ap1il 25 2020 at 13:43 in Ajax, Ontario, Canada
*/
float getVoltageAverage(){
//Robojax.com ARDVC-01 Measure any voltage with Arduino
//This code is explained at my Arduino Course at udemy.com http://robojax.com/L/?id=62
float voltage_temp_average=0;
for(int i=0; i < average_of; i++)
{
readVoltage();
voltage_temp_average +=voltage;
}
return voltage_temp_average / average_of;
//Robojax.com ARDVC-01 Measure any voltage with Arduino
}//getVoltageAverage