Vernier sensors and the photon

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.

I have wired up everything as shown below.

Fixed Diagram

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.

2 Likes

Sorry… Messed up on those wires… Thanks for pointing it out… (Fixed…)

Will try the suggested changes to the code and see if that fixes it…

Thanks ScruffR…

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.

Does this sound right?

Are there any other thoughts?

@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.

1 Like

In principle yes, but we’d have to check your calibration constants :wink:
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

  char data[24];
  snprintf(data, sizeof(data), "C:%.0f,V:%.2f,S:%.2f", Count, Voltage, SensorReading);
  Particle.publish("Vernier", data, PRIVATE);

@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.

I agree, hence

And I can’t quite follow how this

doesn’t line up with what I said about “scaling away” the voltage divider :confused:

@ScruffR, cause I didn’t quite read you comments correctly? :flushed:

1 Like

@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.

Thanks to both of you for the help.