Sample program
//////////////////////////////////////////////////////////
float temp; // create a floating-point type variable temp as storage space for storing data
void setup()
{
Serial.begin(9600);
}
void loop()
{
int V1 = analogRead(A0);
// Read the voltage data from A0 port and store it in the newly created integer variables V1;
measurement range of voltage from analog port is 0 to 5V; return value of 0-1023.
float vol = V1*(5.0 / 1024.0);
// We convert V1 value into actual voltage value and store it into floating-point variable vol
if (vol == temp)
// The judgment here is used to filter repeated data; only voltage value that is differ than the last
one will be output.
{
temp = vol; // After comparison is completed, store the value in variable temp
}
else
{
Serial.print(vol);
// Serial port outputs voltage value, in the same line
keyestudio
// use 9600 baud rate to have serial communication
www.keyestudio.cc
96
Need help?
Do you have a question about the ARDUINO maker learning kit and is the answer not in the manual?