Open Source Electronics for Laboratory Physics Chapter 3
Open Source Electronics for Laboratory Physics Chapter 3: Sensors Dr. John Liu Saint Cloud State University, MN, USA zliu@stcloudstate. edu AAPT workshop W 03 July 26, 2014
CH 3: Sensors �Resistive sensors (thermistors, photo resistors etc. ) �Analog sensors (PASCO or Vernier analog sensors etc. output voltage represents measurement) �Digital on-off sensors (photo-gates, Hall-effect switches etc. ) �Digital pulse width sensors (sonic rangers) �Digital sensors with serial output (some sonic rangers) �Digital sensors with I 2 C bus (accelerometers, magnetic sensors, gyroscopes etc. ) �Digital sensors with SPI, One-Wire, SDI-12 interfaces
Resistive sensors (10 -bit) �Thermistor: doped semiconductor that decreases resistance with increasing temperature. �Light dependent resistor (LDR): doped semiconductor that decreases resistance with increasing light intensity. Also called photo resistors. Wikipedia. org
Sensing resistance Vsen Rfix The easiest way to sense resistance is to form a voltage divider using a fixed resistor and the variable resistor. R For best accuracy, the value of the fixed resistor should be equal to that of the variable resistor when it is in the middle of its range. Analog input GND OSPL has on-board 10 Kohm pull-up resistors on channels A 1, A 3, and A 5 so there is no need to add a resistor to the circuit. This makes prototyping and cabling a lot easier.
Breadboard �All 5 holes in a row are connected and they act as junctions you see on a schematic. �All holes along a red bus are connected but different red buses are separate. Same goes with blue buses.
Breadboard vs. schematic
Photo resistor Integers calculation will truncate accuracy of the result. Make sure to use floating point numbers when necessary to maintain accuracy. Use channel 0 (leftmost) Wiring: One end – White Other end – Black
Thermistor: Integers calculation will truncate accuracy of the result. Make sure to use floating point numbers when necessary to maintain accuracy. Use channel 0 (leftmost) Wiring: One end – White Other end – Black
Analog sensors (10 -bit) �Vernier direct temperature probe (DCT-DIN) �Slope 55. 55 Deg. C/V or 100 Deg. F/V �Intercept -17. 7 Deg. C or 0 Deg. F 1. Analog voltage 2. Slope 3. Intercept 1 2 3 Vernier dual range force gauge (DFS-DIN) Slope -4. 9 N/V (± 10 N) or -24. 5 N/V(± 50 N) Intercept 12. 25 N (± 10 N) or 61. 25 N (± 50 N)
Reading Vernier analog sensors Send measurement to PC, 4 lines of code reading=analog. Read(channel); result=a*reading+b; Serial. println(result); delay(200); Line 1: acquire data: Line 2: scale data for output: Line 3: output result: Line 4: pause momentarily for user: Display measurement on the LCD, 5 lines of code reading=analog. Read(channel); result=a*reading+b; lcd. clear(); lcd. print(result); delay(200); Line 1: acquire data: Line 2: scale data for output: Line 3: clear LCD: Line 4: output result: Line 5: pause momentarily for user:
Optional: Reflective sensor Integers calculation will truncate accuracy of the result. Make sure to use floating point numbers when necessary to maintain accuracy. Use channel 0 (leftmost) Diode side Wiring: Left pin – 150 ohm resistor – Red Transistor side wiring: Left pin – White Right pin – Black
ADXL 335 Accelerometer 1 2 3
Digital on-off sensors �PASCO photogates �No obstruction-digital HIGH �Obstruction-digital LOW �Predefined blocker distance (1 cm) for speed calculation � 10 spokes on pulley for angular speed calculation 1. To While signal is HIGH, wait for LOW. � calculate speed: 2. 3. 4. 5. 6. When it becomes LOW, store time stamp and wait for HIGH again. When it becomes HIGH again, wait for LOW. When it becomes LOW, subtract stored time stamp from current time stamp. Divide predefined blocker distance by the time elapse to find speed. Best way to sense a photogate is to use an object implementing state machine
Pulse-width sensor �Sonic ranger �Start ranging by pulling the trigger pin to HIGH for 10 us or longer then return it to LOW �Ranger will emit ultrasonic pulses and detect its echo �Ranger pulls the echo pin HIGH for the amount of time it takes sound to travel the distance round trip �Detect this pulse width with pulse. In() and calculate distance with speed of sound. �Accuracy depends on timing accuracy of the receiver.
Sonic ranger code and wiring Use channel 0 (leftmost) Wiring: VCC – RED Trig – Brown Echo – White GND – Black 1 1. Initialize pins A 0 as output and A 1 as input. 2. Initialize the serial port to 9600 baud rate. 3. Define a variable to store result. 4. Toggle the INIT pin to start ranging. 5. Get result with a function pulse. In(). 6. Convert the result into distance in mm and print it to serial monitor. 2 3 4 5 6
Serial interface sensor �Maxbotix sonic rangers (car reverse parking sensors) �Free running at around 10 Hz �Prints “R 1234n” where 1234 is the range in mm. �Requires some C-string to integer conversion if range value is to be used programmatically �Can be directly connected to a PC �Measurements are done on board and suffers NO loss of accuracy during transmission.
2 IC sensors �Inter-Integrated Circuit bus connects to many sensors. �Two wires for a large number (127) of different sensors �Each sensor module has a different address �Measurements are done on board and suffers NO loss of accuracy during transmission. �Requires the Wire library to communicate with and some understanding of the commands on data sheets.
ADXL 345 Accelerometer
ADXL 345 3 -axis accelerometer �ADXL 345 has maximal range of 18 g in all 3 dimensions �First set up the device (range, power up) �Then read the device data register for X, Y, and Z acceleration.
Stores persistent values of offset for each axis Controls data range and accuracy Stores x, y, and z acceleration measurements, low and high bytes
How to set offset registers How to set data format registers
10 DOF sensor board wiring 1. 2. 3. 4. VCC_IN – Red GND – Black SCL – Write SDA – Brown Note the diagram is a mirror image of the actual sensor board. The code is so long I can only fit a small portion on this slide.
- Slides: 22