Arduino, a thermistor and four water baths
The Arduino returns a number from 0 to 1023. It has no unit.
Look at your own breadboard. How many things sit in row 20?
// raw reading on A0
void setup() {
Serial.begin(9600);
}
void loop() {
int raw = analogRead(A0);
Serial.println(raw);
delay(1000);
}The reading is stuck near 1023. Which side of the circuit is open?
Each bath at least 5 °C from the one before.
Announce T. Then read out the reference. Difference = T calculated − T reference, with its sign.
| Instrument | Resolution |
|---|---|
| Reference thermometer (digital) | 0.1 °C — its smallest displayed step |
| Millimetre ruler (analogue, for comparison) | 1 mm — its smallest printed division |
| Arduino, reading N on A0 | 1 count out of 1024 — its smallest possible step |
py -m pip install pyserial
import serial, statistics, time
PORT = "COM3" # change to your port
ser = serial.Serial(PORT, 9600, timeout=2)
time.sleep(2)
ser.reset_input_buffer()
readings = []
while len(readings) < 10:
line = ser.readline().decode().strip()
if line.isdigit():
readings.append(int(line))
print(readings)
print("mean =", statistics.mean(readings))
print("stdev =", statistics.stdev(readings))import serial, time
import matplotlib.pyplot as plt
ser = serial.Serial("COM3", 9600, timeout=2)
time.sleep(2)
xs, ys = [], []
plt.ion()
fig, ax = plt.subplots()
line, = ax.plot(xs, ys)
t0 = time.time()
while True:
raw = ser.readline().decode().strip()
if raw.isdigit():
xs.append(time.time() - t0)
ys.append(int(raw))
line.set_data(xs, ys)
ax.relim(); ax.autoscale_view()
plt.pause(0.05)