Hello, I just started with Arduino and very basic knowledge about it.
In project 3 - Love O meter:
One of the equation "temperature = (voltage - 0.5) * 100" How does that come from? I understand because the sensor can detect below 0, so we need to offset the number to below 0. But I don't know how that equation is created?
In project 4 - Color mixing lamp:
I did some research and understand how PWM works. However, can analog (A0, A1...) can also do the same thing? Just use analogWrite(A0, xxx) to works the same as PWM? Or those analog (A0,A1..) can only be input?
I tried to look at the spec sheet of Arduino Uno but I don't see where it states ADC (A0, A1...) are 10-bit and digital (2, 3, 4...., 13) are 8-bit. Can someone help me to understand how to read the spec?
Phototransistor spec sheet shows the diagram is 5V -> phototransistor -> resistor -> ground. When I first connect the circuit without reading the spec, I had 5V -> resistor -> phototransistor -> ground. And there is no value reading. Do resistor always has to be connected after the device? or only some devices are like that?
4.1 Analog pins (A0-A5) are internally connected to an Analog to Digital Converter (ADC). They can be used to converted an analog input voltage into a digital value (0-1023). These pins can also be used as digital pins. PWM pins are essentially the opposite... they take a digital value and convert to a PWM signal - this can then be used to vary the brightness of an LED, or speed of a motor for example. PWM pins are not the same as Analog pins... see below.
4.2 You might be getting confused here. The 10 bit analog pins refers to the resolution of the digital signal that gets determined. 10 bits equals a range of 0 - 1023. Digital pins are either HIGH (1) or LOW (0). The 8 bit thing might be referring to the fact that these are often arranged in ports - each port has 8 bits, but that refers to 8 pins.
4.3 You should always be measuring between the resistor and the LDR. The value you get will depend on the light level, the LDR, and the resistor values. Can you confirm exactly what values you are using.
temperature = (voltage - 0.5) * 100 in Project 3 comes from the TMP36 data sheet. Figure 6 curve b shows the temperature vs output voltage. Note that it crosses 0 C at 0.5 Volts.
analogWrite works on the PWM pins. The PWM pins for various Arduino boards are listed here
The ADC on the Arduino Uno produces a result with 10 significant bits. At the usual Arduino abstraction layer "digitalRead" and "digitalWrite" the pins are handled as a single bit. At the hardware register level they're in groups of 8, but that's not something one needs to know unless one is doing register level I/O manipulation.
The light sensor in the project is a "photoresistor" or "light dependent resister" (LDR), not a "phototransistor". It works in a voltage divider whether it is on the ground side of the divider or the voltage side.
I think I got it now. I thought A0 to A5 can work as OUTPUT with analogWrite, but analogWrite only works with 6 PWM channels. Those channels, from the analogWrite shows the parameter is 0-255.