Arduino Voltmeter (NEED HELP!!!)

I'm making a voltmeter from this site:

But with a TFT screen so how should I go about coding this...

Thank you, Legoman39

give me the code!!! to help you
anyway that's a bad voltimeter, not sensitive!!
i recomended this one

Legoman39:
how should I go about coding this...

Download the arduino IDE. Start typing stuff in, until you have something that looks like it might work. If you get stuck, post what you have so far along with details of what is going wrong.

Thank Y'all! :smiley: :smiley:

KenF:
Download the arduino IDE. Start typing stuff in, until you have something that looks like it might work. If you get stuck, post what you have so far along with details of what is going wrong.

Here is the code I have so far it does seem as though it is displaying random numbers even though I have about .235V going to the A0 pin.
By the way I'm using a voltage divider.

// dc voltmeter
// for uno+TFT combo
#include<TFT.h>
#include<SPI.h>
#define cs 10
#define dc 9
#define rst 8

char dcv[4];
float R1=4700.0;
float R2=120.0;
int analogInput=0;

TFT TFTscreen = TFT(cs,dc,rst);

void setup(){
  
  TFTscreen.begin();
  TFTscreen.background(0,0,0);
  TFTscreen.stroke(255,255,255);
  TFTscreen.setTextSize(2);
}
void loop(){
  String dcvr = String((((analogRead(A0)*4.979)/1024.0)/(R2/(R1+R2))));
  dcvr.toCharArray(dcv,4);
  TFTscreen.text("DC Voltage:",0,0);
  TFTscreen.text(dcv,0,20);
  delay(250);
  TFTscreen.background(0,0,0);  
}

Random numbers problem fixed but its kind of (usually about 2 Volts too low or 1 too high, but it varies) inaccurate, how should I fix that? Here is the code.

// dc voltmeter

// for uno+TFT combo
#include<TFT.h>
#include<SPI.h>
#define cs 10
#define dc 9
#define rst 8

char dcv[4];
float R1=4700.0;
float R2=120.0;
int analogInput=0;

TFT TFTscreen = TFT(cs,dc,rst);

void setup(){
  
  TFTscreen.begin();
  TFTscreen.background(0,0,0);
  TFTscreen.stroke(255,255,255);
  TFTscreen.setTextSize(2);
}
void loop(){
  String dcvr = String(analogRead(A0)*(R2/(R1+R2)));
  dcvr.toCharArray(dcv,4);
  TFTscreen.text("DC Voltage:",0,0);
  TFTscreen.text(dcv,0,20);
  delay(1000);
  TFTscreen.background(0,0,0);  
}

Legoman39

Legoman39:
Random numbers problem fixed but its kind of (usually about 2 Volts too low or 1 too high, but it varies) inaccurate, how should I fix that? Here is the code.

// dc voltmeter

// for uno+TFT combo
#include<TFT.h>
#include<SPI.h>
#define cs 10
#define dc 9
#define rst 8

char dcv[4];
float R1=4700.0;
float R2=120.0;
int analogInput=0;

TFT TFTscreen = TFT(cs,dc,rst);

void setup(){
 
  TFTscreen.begin();
  TFTscreen.background(0,0,0);
  TFTscreen.stroke(255,255,255);
  TFTscreen.setTextSize(2);
}
void loop(){
  String dcvr = String(analogRead(A0)*(R2/(R1+R2)));
  dcvr.toCharArray(dcv,4);
  TFTscreen.text("DC Voltage:",0,0);
  TFTscreen.text(dcv,0,20);
  delay(1000);
  TFTscreen.background(0,0,0); 
}





Legoman39

How about this?

#include<TFT.h>
#include<SPI.h>
#define cs 10
#define dc 9
#define rst 8

char dcv[4];
int R1=4700;
int R2=120;
const int resistorFactor = 1023.0/(R2/(R1+R2));
const float referenceVolts = 5.0;
int analogInput=0;

TFT TFTscreen = TFT(cs,dc,rst);

void setup(){
  TFTscreen.begin();
  TFTscreen.background(0,0,0);
  TFTscreen.stroke(255,255,255);
  TFTscreen.setTextSize(2);
}

void loop(){
  String dcvr = String((analogRead(A0)/ resistorFactor) * referenceVolts);
  dcvr.toCharArray(dcv,4);
  TFTscreen.text("DC Voltage:",0,0);
  TFTscreen.text(dcv,0,20);
  delay(1000);
  TFTscreen.background(0,0,0);  
}

Referenced from Arduino cookbook.

I suggest you measure the real values of R1 and R2 using a meter, then correct the sketch.
The 5V line is rarely 5V and will depend on the USB / DC supply to the Arduino.
Measure it on the Arduino and alter ReferenceVolts.

If you are simply applying the external voltage across a potential divider you may well be altering the circuit voltage as your resistance values are quite low. This may be draining current and dropping the measured voltage.

Hey, heinlinanug2010 so I tryed out your code and it said -5V when I put my 9V on and even when my 9V wasn't attached. Ideas why??

Hi,

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png or pdf?

Thanks..Tom...... :slight_smile:

Try replacing R1 by 4k and R2 by 1k resistors and change the values of R1 and R2 in the sketch to 4000 and 1000 accordingly. You can measure up to 30V by this setup.
A picture of your circuit would also help.

Hi, have you got a 0.1uF cap from the analog input to ground?

Tom.... :slight_smile:

Hi guys I am really confused because now my board is working :relaxed: :relaxed: :relaxed: :cold_sweat: :cold_sweat: :cold_sweat: ... makes NO sense............