I just got my spark core and have tried connecting an LM35 sensor to it, but am stumped with the results.
Tinker app gives me a reading of cca 492, and if I convert this to voltage, it should be 0,39 V, right?
If I measure with the voltmeter (measuring between A0 and GND), I get 0,29 V.
I also tried putting 3,3 V to another analog input, and I get 4095 which is fine.
I’ve also added an external LED with the resistor and connected the output of LED to another A input, which gives me 2331, which should be 1,87 V and which corresponds pretty well to voltmeter (1,89V).
What am I doing wrong here?
BTW - the temperature is around 24 Celzius, so maybe my temp sensor is quite off anyway (3 degrees).
I’ve now connected it an arduino clone and it’s weird - the voltmeter shows 0,25, arduino analogread the same.
I take temp sensor to spark core breadboard, voltmeter 0,29, spark core 0,39.
I also tried putting +v to temp sensor from VIN, which shows as 4,78 V at the moment, and got same results.
Stumped.
I can’t help with your Analog reading issue but just wanted to warn ya about the warm temp of the Spark Core will throw off your temp readings unless the Spark Core is placed above your temp sensor so all the heat it emits will rise up and not affect your temp readings.
clarity, there were issues with the A/D conversions that are now fixed but I am not sure they have been updated in the Web IDE. I will check and update this post.
UPDATE: Yup, the update has not been pushed to the web IDE yet but is available for users doing local compiling of the code.
@peekay123 is right about the ADC code in the webIDE (the “Build” button on the website) being a little bit behind the “master” branch that can try out if you compile your code on your local computer. The “master” branch will move to the webIDE when Spark has fully tested it.
Using the ADC code in the “master” branch, I was able to get analogRead() values that were +/- 1 count from what I calculated, which is all you can ask really.
A few other points worth mentioning:
You should use the filtered 3.3V output on the Spark core, which is labelled 3.3V* here
You might want to put a bypass capacitor right next to the LM35 from power to ground–they are notorious for picking up power supply noise. Something like 0.1uF to 0.01uF.
You 3.3V* might not be exactly 3.3V. It might 3.272 V or 3.354 V and that can throw off your calculations. If you measure it with your voltmeter, you can use that number in your calculations as the full scale (4095) value. It may change if you power the core differently, but to debug everything this is a key step.
bko, regarding the 3.3* pin, I also found that I had problems with some devices whose lower supply tolerance is
3.3v such as a DHT22 temperature/humidity sensor. I had to use a separate 3.3v supply.
@clarity, from the LM35 specs, I noticed that it operates from 4 to 30V so the 3.3v supply will not be adequate. You could use the Vin supply (the USB power) to power the LM35 but you should put a 0.1uf capacitor across the +Vs and GND pins AT the device to act as a noise filter, which is not uncommon from USB power supplies. You will also need to consider that the output of the LM35 may exceed the maximum 3.3v input voltage of the Spark A/D.
It sounds like your sensor is too close to your Photon device since when you turn on the LED, more current is needed from the Photon board and it heats up a bit more. Can you try extending the wiring so that the sensor is say 10cm or 4" away from everything else?
I have found that the digital sensors like the Dallas or Bosch ones work better for me.
Yes a 330 ohms, but I notice when a turn on the LED inmediately the temp changes to 2C more. I mean immediately the OUTPUT voltage of the sensor increase to 20mv.