I have been trying to read the voltage value of the analog pin and print it to my lcd but it just prints a bunch of weird characters. any help would be great. here is my sketch. I am new to programming so I wouldn't be surprised if I was dead wrong on what I have already done. BTW the lcd works when I tell it to write regular phrases.
#include <SoftwareSerial.h>
SoftwareSerial mySerial(3,2);
String string=String(analogRead(0), DEC);
void setup()
{
mySerial.begin(9600); // set up serial port for 9600 baud
delay(500); // wait for display to boot up
}
void loop()
{
mySerial.write(254); // move cursor to beginning of first line
mySerial.write(128);
mySerial.println(string);//prints the value of the initialized String (I hope)
delay(2000);
mySerial.write(" "); // clear display
mySerial.write(" ");
mySerial.write(254); // move cursor to beginning of first line
mySerial.write(128);
delay(2000);
}
I think one problem is that you're using "println" instead of "print". println sends a carriage return and a line feed that might be the last two strange characters you see. That doesn't explain why you don't see the results of the analog read.
I don't see why you position the cursor both before and after the printing of the data.
On the other hand, if you position the cursor before you print your spaces, that will erase the old data but you still need to look into the LCD addressing. From your code I'm guessing that you think you're erasing both lines on the LCD by sending out two lines of spaces. The LCD addresses for the two lines aren't consecutive.
ok thanks for replying. I changed the println command into a print command and it got rid of the strange characters but it prints nothing but zero no matter how much (safe) voltage I send through it. Am I forgetting to initialize something? any help would be awesome. I kept the spaces in just for the heck of it.
my revised code
#include <SoftwareSerial.h>
SoftwareSerial mySerial(3,2);
String string=String(analogRead(A0));
void setup()
{
mySerial.begin(9600); // set up serial port for 9600 baud
delay(500); // wait for display to boot up
}
void loop()
{
mySerial.write(254); // move cursor to beginning of first line
mySerial.write(128);
mySerial.print(string);
delay(1000);
mySerial.write(" "); // clear display
delay(1000);//also lowered the timing for quicker refresh times
}
you've been a great help. I put the read into the loop and now the voltage changes! and it prints it to the LCD but is there any way to convert that number which is from 300 to 1000 into a real voltage? and also the voltage changes erratically. is there a way to get an accurate reading of the voltage i am inputting? btw i'm trying to build an arduino ohm meter
#include <SoftwareSerial.h>
SoftwareSerial mySerial(3,2);
void setup()
{
mySerial.begin(9600); // set up serial port for 9600 baud
delay(500); // wait for display to boot up
}
void loop()
{
String string=String(analogRead(A0));
mySerial.write(254); // move cursor to beginning of first line
mySerial.write(128);
mySerial.print(string);
mySerial.print(" Volts");//I added this as a label
delay(1000);
mySerial.write(254); // move cursor to beginning of first line
mySerial.write(128);
mySerial.write(" "); // clear display
}
Iam going to use a resistor and hook it up to an analog pin then have probes going to the unknown resistance which goes into another analog pin. then I will split the voltage through the resistor and the unknown resistance. then its a simple equation to derive the resistance of the unknown resistance. the constantly fluctuating voltage will throw off my reading.
It is neater to remove the tracking garbage from the end of your quoted URLs.
It is even neater to just insert the hyperlinks into your description using the "Insert Hyperlink" button with the little world icon. You put an equals sign after the "url" before the "]" and paste the actual URL after that.
kklee97:
The constantly fluctuating voltage will throw off my reading.
You might want to use a capacitor on the Vref pin. Just how much does the voltage/ reading fluctuate?
It is neater to remove the tracking garbage from the end of your quoted URLs.
It is even neater smiley-grin to just insert the hyperlinks into your description using the "Insert Hyperlink" button with the little world icon. You put an equals sign after the "url" before the "]" and paste the actual URL after that.