Go Down

Topic: Units of displayed readings (Read 182 times) previous topic - next topic

Suaad

Hi,


I'm new in arduino world
I wrote this sketch to read the light intensity as voltage and display readings in serial moniteor
Code: [Select]


int SensorPin = A0;
int SensorReading;


void setup(void)
  // serial.begin command to connect with PC
 { Serial.begin(9600); }


void loop(void)
{
       
 
  // the main code that will repeated
  SensorReading = analogRead(SensorPin);
  Serial.print("Voltage = ");
  float voltage= SensorPin * (5.0 / 1023.0);
  /*float command to take decimals
  into account more prices than integer*/
  Serial.print(SensorReading);
  Serial.println(SensorPin, DEC);
  //show decimals in serial monitor
      delay(60L*1000L);
 
  }



and these are the readings
V=7314
V= 014
V=014
V=1014
V=914
V= 014
V= 014
V=614
V=6814
V= 2314


actually that's not make sense for me! what's the unit of these readings? is it miiliVolt?


wildbill

This:
Code: [Select]
  Serial.println(SensorPin, DEC);


is giving you a suffix of 14 on all your 'readings'. Get rid of it.

Then you'll be printing the direct output of the ADC. Better if you print your voltage variable instead.

igendel

...and, of course, correct the formula for voltage so that it uses the right variables  ;)
My Adventures in the Making:
http://www.idogendel.com/en

Suaad

This:
Code: [Select]
  Serial.println(SensorPin, DEC);


is giving you a suffix of 14 on all your 'readings'. Get rid of it.

Then you'll be printing the direct output of the ADC. Better if you print your voltage variable instead.
i need print the voltage vairable, but I'm confused how to do this in unit (volt)?

i neglect  Serial.println(SensorPin, DEC);

then!!


Suaad

...and, of course, correct the formula for voltage so that it uses the right variables  ;)
pardon me, can you explain more?
I don't know what's the correct formula.

cattledog

Quote
I don't know what's the correct formula.
You need to think this through. As you learn programming you will need to train yourself to think logically.

What is SensorPin? Will it ever change?

What is the SensorReading? Where to do you get its value from? How do you get the value? What do you expect it to be? What do you think Serial.print (SensorReading) will give you.

You have declared a float type variable named voltage but you never use it. Why not?  Why did you use that formula to become voltage?

What should go in the brackets of Serial.print() to print out the voltage?

Suaad

I think that's it  :)

Code: [Select]
SensorReading = analogRead(SensorPin);
  Serial.print("Voltage = ");
  float Voltage = float(SensorReading) * (5.0 / 1023.0);
 
  Serial.print(Voltage);
  Serial.println("V");
 
      delay(3000L);


the outputs values must be in (Volt) now, right?

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy