# Temperature Sensor - Circuit Set-up


`````{tab-set}
:sync-group: micro
````{tab-item} Pico Wiring Diagram
:sync: pico
```{image} images/Tempsensor_wiring_pico.png
:class: bg-primary mb-1
:width: 700px
:align: center
```

````
````{tab-item} Arduino Wiring Diagram
:sync: ard

```{image} images/Tempsensor_wiring_ard.png
:class: bg-primary mb-1
:width: 700px
:align: center
```
````
`````

`````{tab-set}
:sync-group: micro
````{tab-item} Pico Circuit Diagram
:sync: pico
```{image} images/Tempsensor_circuit_pico.png
:class: bg-primary mb-1
:width: 400px
:align: center
```
For connecting the temperature sensor to the Pico (the blue wire), you must use one of the analog pins **ADC** pins labelled **ADC0**, **ADC1** and **ADC2**.
````
````{tab-item} Arduino Circuit Diagram
:sync: ard
```{image} images/Tempsensor_circuit_ard.png
:class: bg-primary mb-1
:width: 400px
:align: center
```

For connecting the temperature sensor to the Arduino (the blue wire), you must use one of the analog pins labelled **ADC0 - ADC4**.
````
`````




``````{Warning}
`````{grid}
````{grid-item}
```{image} images/LM35Pins.png
:width: 180px
:align: center
```
````
````{grid-item}
Make sure to double check that you have connected your microprocessor to the correct pins of your LM35.


If you accidentally swap the Power-in and GND pins, high resistance can cause current to build up massively, making the sensor very hot.
````
``````

## Analog to Digital signals

While other microcontrollers may be able to read analog inputs, the microprocesser can only read digital and so requires an **Analog to Digital Converter (ADC)**. 

As you could guess, this is a small device built into the microprocesser's microcontroller that can convert analog input signals into digital signals. The microprocesser's ADC has _12 bit resolution_ meaning it converts the 0 - 3.3V input from the analog component into a value between 0 and 4095. 

```{image} images/ADC.gif
:width: 500px
:align: center
```

(LM35label)=
## LM35 Temperature sensor

The temperature sensor we are using is an LM35 Temperature sensor - it is compact and very widely used for its low cost and high accuracy. it also exists in various versions.

The sensor works by taking in current at a certain voltage and outputting a different voltage depending on the ambient temperature. This variable outputted voltage is the analog input signal that is converted to digital and read by the microprocesser.

```{image} images/LM35circuit.png
:width: 400px
:align: center
```
<br>

The LM35 is calibrated so that it will output 0 V at 0 $^{\circ}C$. From there, a 10 mV increase in the voltage corresponds to a 1 $^{\circ}C$ increase in the temperature. For example, at 25 $^{\circ}C$ the output voltage should be approximately 250 mV or 0.25 V (which the microprocesser's ADC would convert to 310). The LM35 ideally works with a supply from 4 - 20 V and so the 3.3 V from the Pico might not be enough. If that is the case it can be powered with the 5 V from the Pico's Vsys connection.

<br>

Our set-up can measure temperatures ranging from roughly 2 $^{\circ}C$ to 150 $^{\circ}C$. The component itself has a typical accuracy of $\pm$0.25 $^{\circ}C$ at standard room temperatures, which climbs up to roughly $\pm$ 0.75 $^{\circ}C$ at higher temperatures. However, we have additional innacuracies since the power input from the microprocesser often deviates slightly from 3.3 V.

```{admonition} More specs
:class: seealso
Check [here](https://www.ti.com/lit/ds/symlink/lm35.pdf) for more information from the official LM35 datasheet.
```

```{warning}
:class: warning
There is a family of LM35 sensors, such as the LM335. The output of this is slightly different in that it is referenced to absolute zero (that is 0 K). There the conversion needs to have 273.15 taken off it to go from Kelvin to Celsius.

