Introduction: Arduino Voltage Sensor 0-25V

The reason I'm making this is because I couldn't find any really helpful information on how to fix the code for my voltage sensor. Arduinos have built in voltage sensors. Unfortunately, they only support voltages of 0-5V. This module allows you to measure voltages of 0-25V by presenting a lower voltage to the arduino for measuring. After you have this value you simply feed it through some math and you get your actual voltage. Don't ask me how this math works. I don't know. If you do know however, please share. I'm really just editing the example code from the seller so that it will display decimal values instead far less useful int values.

To start you need to wire it up. It's extremely easy as it only needs 3 wires.

Plug + into 5V, - ground and S into an analogue pin. I have removed all but the relevant pins in a pinout of the arduino nano. If you're using another model then you'll have to figure them out on your own. Any analogue pin will do. As far as I am aware at least. Once you have done this you're ready to move on to the software.

Step 1: Fixing the Code

The example code I got from the seller would only output a very limited integer value for the voltage. When you're trying to tell the actual voltage of what you're measuring though it isn't all that helpful. Because of this I fixed the code a bit so that it would give me a float value. In the photos you can see the edits I have made. I will also list the edits below. Keep in mind that the analogue pin will need to be changed depending on which pin you attach the S pin to.

This is the original code.

#include <Wire.h>
int val11;

int val2;

void setup()

{

Serial.begin(9600);

Serial.println("Emartee.Com");

Serial.println("Voltage: ");

Serial.print("V");

} void loop()

{

float temp;

val11=analogRead(1);

temp=val11/4.092;

val11=(int)temp;

val2=((val11%100)/10);

Serial.println(val2);

delay(1000);

}

This is the edited code.



#include

int val11;

float val2;

void setup()

{

Serial.begin(9600);

Serial.println("Emartee.Com");

Serial.println("Voltage: ");

Serial.print("V");

}

void loop()

{

float temp;

val11=analogRead(1);

temp=val11/4.092;

val2=(temp/10);

Serial.println(val2);

delay(1000);

}



I have also included the finished code in case anyone wants it.