Hardware Reference
In-Depth Information
pinMode (RLED, OUTPUT); //Set Red LED as Output
}
void loop()
{
val = analogRead(TEMP);
if (val < LOWER_BOUND)
{
digitalWrite(RLED, LOW);
digitalWrite(GLED, LOW);
digitalWrite(BLED, HIGH);
}
else if (val > UPPER_BOUND)
{
digitalWrite(RLED, HIGH);
digitalWrite(GLED, LOW);
digitalWrite(BLED, LOW);
}
else
{
digitalWrite(RLED, LOW);
digitalWrite(GLED, HIGH);
digitalWrite(BLED, LOW);
}
}
This code listing doesn't introduce any new concepts; rather, it combines what
you have learned so far to make a system that uses both inputs and outputs
to interact with the environment. To try it out, squeeze the temperature sensor
with your fingers or exhale on it to heat it up. Blow on it to cool it down.
UsingVariableResistorstoMakeYourOwnAnalog
Sensors
Thanks to physics, tons of devices change resistance as a result of physical action.
For example, some conductive inks change resistance when squished or flexed
(force sensors and flex sensors), some semiconductors change resistance when
struck by light (photoresistors), and some polymers change resistance when
heated or cooled (thermistors). These are just a few examples of components
that you can take advantage of to build your own analog sensors. Because these
sensors are changing resistance and not voltage, you need to create a voltage
divider circuit so that you can measure their resistance change.
 
Search WWH ::




Custom Search