Skip to content

Instantly share code, notes, and snippets.

@elktros
Created July 14, 2018 08:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elktros/b63002a8d084aef75ff8e959c8397578 to your computer and use it in GitHub Desktop.
Save elktros/b63002a8d084aef75ff8e959c8397578 to your computer and use it in GitHub Desktop.
Code for interfacing Voltage Sensor with Arduino for measuring voltages less than or equal to 25V.
#include "LiquidCrystal.h"
const int voltageSensor = A0;
float vOUT = 0.0;
float vIN = 0.0;
float R1 = 30000.0;
float R2 = 7500.0;
int value = 0;
LiquidCrystal lcd(7, 6, 5, 4, 3, 2); // RS, E, D4, D5, D6, D7
void setup()
{
//Serial.begin(9600);
lcd.begin(16,2);
lcd.print(" Measure > 25V ");
delay(2000);
}
void loop()
{
value = analogRead(voltageSensor);
vOUT = (value * 5.0) / 1024.0;
vIN = vOUT / (R2/(R1+R2));
//Serial.print("Input = ");
//Serial.println(vIN);
lcd.setCursor(0,0);
lcd.print("Input = ");
lcd.setCursor(9,0);
lcd.print(vIN);
delay(500);
}
@memo0238
Copy link

Hi, very good information. Before this, i did a conection with a burning ground wire results. Per your diagram, i think my mistake was the + male terminal conection to the +5 Vcc of the Arduino uno R3, when It should be NC.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment