Hi all
I want to measuer the volts in an led lamp, this lamp is increasing in time the voltage whit PWM (analogwrite())
The mesure taken is not the correct one and always whiout decimal values.
its possible? any suggestion, or brillant idea?
int sensorValue = analogRead(sensorPin);
float sensorVoltage = map(sensorValue, 0, 1023, 0, 2.9); // Convert to Voltage (assuming analog reference is set to 2.9v)
Serial.print(sensorVoltage);
You didn't show all your code so I'm guessing your mistake is declaring sensorValue as 'int' and then trying to store a 'float' in it.
const int PinBlueLed=9;
const int PinWhiteLed=10;
const int PinFanLED= 6;
const int sensorPin = A0;
float sensorValue = 0; // variable to store the value coming from the sensor
You need to describe what you have connected to the Arduino, on which pins. You say that you are using PWM to light the LED, and then you say you are trying to read the voltage to the LED. You can't do both with the same LED.
Pin 9 is connected to potenciometer powering (PWM) the led
Pin A0 is connected in same pot monitoring
You mean this is not corret, I read values but erroneus, I think because the map.
You mean this is not corret, I read values but erroneus, I think because the map.
Personally, I am really confused. You said that there errors in, and misuse of, the map function were not the source of the problem, but now you think maybe they are.
Pin 9 is connected to potenciometer powering (PWM) the led
Potentiometers are variable resistors. They are not a source of power. If you have a potentiometer, where does PWM come into the picture?
You have described at best one third of the circuit.
Pin A0 is connected in same pot monitoring
Connected where?
We don't ask these questions to annoy you. We ask them because we can't see your hardware or your schematic.
Describe, or take a picture of, or draw a schematic that shows every wire connected to the Arduino.