This repository will hold all the home-works/projects for the course New Human Factors in Computing - SUNY SBU Spring '17. Click on any of the assignmentsAssignment 2 - Part 2: Sensor reading - Problem Statement:
Construct a circuit with at least one sensor and at least one LED.
Use the datasheet for your sensor to understand its response characteristics.
If it's resistive (changes resistance) - see how many Ohms you get in different stages of operation.
You will benefit from picking a resistor value (or a series, parallel bunch of resistors) to help you span the entire range of the resistive sensor.
Linearize the response with a multimap if needed.
Output the sensor value also to the serial console: Convert raw values to meaningful readings (e.g. "lux", "degrees Celsius", etc.)
Use the sensor to also drive the LED
Use map according to the characteristics of the sensor and your linearization.
Use PWM to drive the LED from totally dark to ON, corresponding with the sensor read values.
Apply a filter to condition the signal:
a hardware RC filter, for which you'd need a capacitor - calculate the cutoff frequency.
a software filter: moving average, median, IIR (Butterworth), etc.
Document it with Fritzing (+ circuit diagram), as well as photographs, circuit diagram.
Write down the voltages, and operational ranges of your sensor
Plot the results from the sensor (after and before calibration, filtering): You can use Excel, Google Sheets, gnuplot, or anything else you are used to working with.
Answer:
We connected the Photo resistor in series to a 10kilo-ohm resistor and measured the voltage that is read on one leg of the photo resistor. The max voltage that is supplied is 5V, since it is connected to USB. 0-5V is mapped between 0-1023 in the analogRead api that is used. This is mapped to 0-255 before doing a digitalWrite. The output is written to the 13th pin. An LED is connected on that leg, through a resistor of 1 kilo-ohm. We invert the reading that is read in the analogWrite, so that if it is dark, the LED lights and when there is light, the LED turns off.
If 'x' is the input reading for AnalogRead, then the voltage drop across the resistor R is, (x/1023) * 5 Volts. Then the current flowing through the circuit at this time is V/R = ((x/1023) * 5)/ 10 * 10^4. Now, the voltage drop across the photo resistor is (1023 - x)/1023) * 5 V. Now, since the current is the same across both the resistors, the resistance of the photo resistor is V/I. Cancelling out terms, R = ((1023 - x) / x) * 10 ^ 4 ohms.
Fritzing Sketch:
Circuit Diagram:
Arduino Code: Running Average Filter (Smoothening)
Software Filter: Before Smoothening
Software Filter: After Smoothening (Running Average)
Resistance Graph
Sensor with LED