This is a question about connecting vernier sensors to the photon. I originally had this working with an Arduino Yun but would like to see if it would work with the Photon. I used this guide to wire up the BTA connector into the voltage divider and this information with a couple of changes for the program.
In the program, I changed line 46 from
float Voltage = Count / 1023 * 5.0;// convert from count to raw voltage
to
float Voltage = Count / 4095 * 3.3;// convert from count to raw voltage.
All of the numbers I am getting are way off. Any thoughts on what my problem is?
That frizzing looks odd. Your red and black wire on the left short out on the top Vcc rail.
I’d use 4095.0 to ensure the division will be performed as floating point division irrespective of order of execution.
But from the mathematical side, I’d rewrite this so anyway float Voltage = (3.3 * Count) / 4095.0; to keep precission loss as small as possible.
Another thing to consider is that the ADCs on the Photon have no input driver (unlike Arduinos) hence the switched capacitor ADC’s input impedance will gain effect the higher the output impedance of your sensor gets.
Still getting very bizarre numbers from this, but I think I know why…
This is the current complete program.
// Constants for the linear calibration of the final value.
float Intercept = 6.825;
float Slope = 76.29375;
void setup()
{
}
void loop()
{
float Time;
float Count = analogRead(A4); //Reads the sensor
float Voltage = (3.3 * Count) / 4095.0;// convert from count to raw voltage
float SensorReading= Intercept + Voltage * Slope; //converts voltage to sensor reading
Particle.publish("Count:", String(Count), PRIVATE);
Particle.publish("Voltage:", String(Voltage), PRIVATE);
Particle.publish("Vernier:", String(SensorReading), PRIVATE); // Send to console
delay(10000);
}
When it calculates out the voltage in this line float Voltage = (3.3 * Count) / 4095.0;// convert from count to raw voltage, it is calculating out for 3.3 max voltage instead of 5 volts max voltage. When it goes to the next line, the calibration numbers are calibrated to a 5 volt max instead of 3.3 volts.
@istrait, note that doing 3 publishes in a row violates the 1-per-second publish limit. You may want to create a single string with your data and publish only once.
In principle yes, but we'd have to check your calibration constants
If these are in regards to 5V then they will probably be wrong tho'.
You could either scale them down to 3.3V or calculate the actual sensor output voltage via the voltage divider ratio and feed this up-scaled voltage into your original formula.
BTW, while it is better practice to wrap all your readings into one single publish, you cam get away with your three publishes in a row since the 10sec "cool down" ensures to keep your limit within the burst of 4 limit.
Still, I'd rather do this
@ScruffR, the sensor is powered by 5V and outputs a 0-5v voltage. Since this holds true here (5v power), the calibration for the sensor will stay the same. However, the output is scaled by the resistor divider. One concern is that the total resistance of the divider affects the output of sensor. The approx 9K ohm total resistance may be too low. A unity gain op-amp may be necessary to provide high input impedance with the divider positioned on the output of the op-amp and not the input.
@peekay123 Thanks for that piece of information. I just got my photon and have had it for a week and have missed some things, but am trying to learn fast.
@ScruffR I am changing my code to reflect the snprintf command. I had missed this as well.
Any chance I can get a diagram of how to do this? Am starting to do some reading on what you are trying to say as I am not great at the electronic side of this.