Professional Documents
Culture Documents
• Use
Easiest way to determine temperature in a room.
Delivers an analog output that has a linear relationship
to the temperature it is sensing.
• Code
void setup() {
Serial.begin(9600);
}
void loop() {
int sensorValue = analogRead(A0);
Serial.println(sensorValue);
}
float voltage = sensor * 5 / 1024; //converts the 0-1023 reading into a voltage
float tempC = (voltage – 0.5)*100;
• Wiring
Note the wiring diagram has the flat surface of the sensor facing you when the 5V is on the left
and the ground is on the right.
• Use
Easy to tell you if temperature is moving up or down or changing,
but very hard to get a reading of what the actual temperature is.
• Code
void setup() {
Serial.begin(9600);
}
void loop() {
int sensorValue = analogRead(A0);
Serial.println(sensorValue);
}
• Wiring
the thermistor goes in a voltage divider circuit
• Use
Comes in waterproof versions. Can use multiple with one digital pin. Sends the actual
temperature using digital, not analog, data. Needs a library.
• Code
You need 2 libraries. Search “DS18B20” in the library manager. Install “Dallas Temperature
Control” and the “OneWire” Library.
For instructions on how to use the library manager see the “installing libraries” section.
• Wiring
Note you need a resistor connecting the data pin to 5V
• Use
Best for high heat (fire, cooking, etc.) and bad environments. Needs a separate circuit to go along
with the sensor. A thermocouple amplifier such as MAX31855, (Adafruit product number 269)
• Code
You need a library. Search “max31855” in the library manager. Install “Adafruit max31855
Library”. Open an example code to see which pins go to which wires, and to print out the
temperature.
For instructions on how to use the library manager see the “installing libraries” section.
• Wiring
The example codes will indicate which pins receive which wires
• Use
Easy to use and gives temperature and humidity
• Code
You need a library. Search “DHT22” in the library manager. Install
“SimpleDHT”. Open the example “DHT22default”.
For instructions on how to use the library manager see the “installing libraries” section.
• Wiring
Note the data pin must also have a resistor to 5V on it.
• Use
To detect ultraviolet rays. Great for projects related to detecting sunlight and too much
harmful UV radiation.
• Code
void setup() {
Serial.begin(9600);
}
void loop() {
int sensorValue = analogRead(A0);
Serial.println(sensorValue);
}
• Wiring
Vcc/5V → 5V
Gnd → ground
A0/OUT/SIG → A0
• Use
Used to measure moisutre content of soil, or similar substrates (eg – sponge)
• Code
void setup() {
Serial.begin(9600);
}
void loop() {
int sensorValue = analogRead(A0);
Serial.println(sensorValue);
}
• Wiring
For the 3 wire version that doesn’t come with a separate board, the wiring is:
Vcc → 5V
Gnd → ground
Out/A0→ anlaog pin A0
For the 4 wire versions that come with a breakout board, the wiring is the same for the 5V, gnd,
and A0 pins. The 4th wire can go to any digital pin. Using the
potentiometer on the breakdout to set a threshold value, the
digital output pin will be set to HIGH whenever moisture level
climb above the set threshold value. Set the potentiomter
through tiral and error.
• Use
Used to measure a variety of gasses, depending on which model you have:
o MQ-2 - Methane, Butane, LPG, smoke o MQ135 - Air Quality (CO, Ammonia, Benzene,
o MQ-3 - Alcohol, Ethanol, smoke Alcohol, smoke)
o MQ-4 - Methane, CNG Gas o MQ136 - Hydrogen Sulfide gas
o MQ-5 - Natural gas, LPG o MQ137 - Ammonia
o MQ-6 - LPG, butane gas o MQ138 - Benzene, Toluene, Alcohol, Acetone,
o MQ-7 - Carbon Monoxide Propane, Formaldehyde gas, Hydrogen
o MQ-8 - Hydrogen Gas o MQ214 - Methane, Natural gas
o MQ-9 - Carbon Monoxide, flammable gasses o MQ216 - Natural gas, Coal gas
o MQ131 - Ozone
• Code
void setup() {
Serial.begin(9600); Note: The sensor must be
} warmed up before it can give
void loop() { an accurate reading
int sensorValue = analogRead(A0);
Serial.println(sensorValue);
}
• Wiring
The sensor can either come:
1) loose with 6 pins exposed 2) on a breakout board with 3 pins
Vcc/5V → 5V
Gnd → ground
A0/OUT → A0
3) or on a breakout board with 4 pins
If it is a four pin breakdout board, then
the last pin should be labebled with a D
for digital pin
D0 → a digital pin (optional)
• Use
To sense light. Can also be used as an object sensor to sense if an object is placed over it.
• Code
void setup() {
Serial.begin(9600);
}
void loop() {
int sensorValue = analogRead(A0);
Serial.println(sensorValue);
}
• Wiring
Sensor is placed in a voltage divider circuit
• Use
For detecting heat. Usually large amounts, like a flame
• Code (for the 4 wire version)
void setup() {
Serial.begin(9600);
}
void loop() {
int sensorValue = analogRead(A0);
Serial.println(sensorValue);
}
• Wiring
For the individual sensors, there is a 3-wire and a 4-wire version.
For the 3 wire version, the wiring is:
Vcc → 5V
Gnd → ground
Out/D0 → Digital Arduino pin
Use the potentiometer on the breakdout to set
a threshold value. The digital output pin will be
set to HIGH whenever heat levels climb above
the set threshold value. Set the potentiomter
through trial and error.
For the 4 wire version, the 4th wire goes to an
analog pin. This can be used to detect the level
of heat, as opposed to just yes or no with the
digital pin and potentiometer.
• Use
Easy to measure distances using ultrasound. Ideal from 1 – 5 feet. Ultrasound travels in a conic
and echoing pattern, leading to potential interference and poor precision
• Code
void setup()
{
Serial.begin(9600);
pinMode(12, OUTPUT);
pinMode(11, INPUT);
}
void loop()
{
long duration, inches;
digitalWrite(12, LOW);
delayMicroseconds(2);
digitalWrite(12, HIGH);
delayMicroseconds(5);
digitalWrite(12, LOW);
duration = pulseIn(11, HIGH);
inches = duration / 74 / 2;
Serial.println(inches);
delay(200);
}
• Wiring
Note: the wiring depends on
which pins you referred to in
your code
• Use
More accurate at close range than the ultrasonic distance sensors, with less uses cause by
“coning” sound waves. Very easy to hookup and use. Very poor at long distance (> 2 feet). Ideal
for seeing what is right in front of you.
• Code
void setup() {
Serial.begin(9600);
}
void loop() {
int sensorValue = analogRead(A0);
Serial.println(sensorValue);
}
• Wiring
• Use
By using laser instead of sound to measure distance, the reading are much more accurate and
the “View window” is only directly in front of the sensor. This eliminates static caused by the
“coning” nature of ultrasound and infrared. They are expensive. IMPORTANT: you much select
a sensor designed for the ranges you want to measure. Can be anywhere from I inch to 1000’s
of feet.
• Code
Each sensor is unique.
• Wiring
Each sensor is unique
• Use
Can be used to easily detect the volume of noise. Great for discerning a loud clap or shout.
• Code
void setup() {
Serial.begin(9600);
}
void loop() {
int sensorValue = analogRead(A0);
Serial.println(sensorValue);
}
• Wiring
Note: when there is a potentiometer on the sensor there is also a digital output pin. The
potentiometer sets the threshold volume, for which when the sound rises above it the digital pin
becomes HIGH. The Analog output pin is constantly fluctuating with the sound and is not affected
by the potentiometer.
• Use
Cheap and easy when need to sense if something is moving. This will tell you how much the item
is vibrating.
• Code
void setup() {
Serial.begin(9600);
}
void loop() {
int sensorValue = analogRead(A0);
Serial.println(sensorValue);
}
• Wiring
Note: you need the large resistor across the two polls.
For the two wire version that just contains the sensor, use the diagram on the left. For a sensor
that comes with a breakout board and 3 pinouts, use the key on the right.
For individual sensor with no breakout: For breakout
board with 3 pinouts:
Vcc/5V → 5V
Gnd → ground
A0/OUT/SIG → A0
• Use
Easy to tell you when something has vibrated more than the allotted threshold. It will not tell
you how much it has vibrated. When the threshold set by the potentiometer is crossed, the
output pin becomes HIGH.
• Code
void setup()
{
Serial.begin(9600);
pinMode(2, INPUT);
digitalWrite(2, HIGH);
}
void loop()
{
Serial.println(digitalRead(2));
if (digitalRead(2) == HIGH)
{
//do something here
}
}
• Wiring
• Use
Are all analog output accelerometers. Great for detecting tilt, orientation, and a sudden impact.
Very easy to use and hookup. You can tell if it is an analog output accelerometer because there
will be a pins marked X, Y and Z. They are not good if you want to measure the actual
acceleration. Because gravity is always pulling down towards the center of the Earth, the axis
facing the Earth will appear to have a larger read value. As you turn the sensor, that number will
drop and a different axis will begin to see a larger value. You can then select threshold numbers
to determine if you’ve tilted too far.
Use the 377 for high g levels, such as a ball being hit by a bat.
• Code
void setup() {
Serial.begin(9600);
}
void loop() {
int x = analogRead(A0);
int y = analogRead(A1);
int z = analogRead(A2);
Serial.print(x);
Serial.print("\t");
Serial.print(y);
Serial.print("\t");
Serial.println(z);
}
• wiring
Note: some require 3V and some 5V
• Use
To measure pulse. Must be stuck to a finger, or sometimes an ear.
• Code
• Wiring
• Use
Place ECG pads on a muscle and the sensor can tell if you
are flexing the muscle by sensing the electrical activity in
the muscle.
• Code
void setup() {
Serial.begin(9600);
}
void loop() {
int sensorValue =
analogRead(A0);
Serial.println(sensorValue);
}
• Wiring
Only pins 1, 2 and 3 are needed. Pin 1 and 2 go to power and ground, and pin 3 goes to analog
pin A0.
• Use
Can either be used to detect contact on the surface from a small
object, or flexing of the sensors when attached to a bending
object. Only the sensitive portion on the end can detect pressure,
and the object being detected must be entirely in contact with the
sensing area, and not also resting on the table. The wire leads are
extremely fragile and soldering is not recommended.
• Code
void setup() {
Serial.begin(9600);
}
void loop() {
int sensorValue = analogRead(A0);
Serial.println(sensorValue);
}
• Wiring
Note: do not solder to ends of the pressure sensors
To attach the ends of the wires you can use female jumper cables and either
hot glue or crimp them in place. You can also buy specific connectors for these
sensors: https://www.sparkfun.com/products/14195
The sensor should be placed in a voltage divider circuit. A Resistor in range of the sensor should
be used. Approximate 10k-20k range.
• Use
Buttons and switches are the most common types of Input. Variations include:
o Latching (stays shut like a switch) vs monetary (opens when you let go like a button)
o Illuminated – buttons with a light in the center. They have two separate leads for the
LED and are controlled like a regular LED that was in a breadboard. The light has no
connection to the button other than it being physically inside of it.
o Mount – is it mounted flush on a surface, like an arcade button, or protrudes out, like
a button in a breadboard.
• Code
void setup(){ Note: In this case we are wiring
Serial.begin(9600); our buttons to connect a digital
pinMode(2, INPUT); pin to ground, so when the button
digitalWrite(2, HIGH);
} is pressed the pin becomes LOW
void loop(){
Serial.println(digitalRead(2));
if (digitalRead(2) == LOW)
{
//do something here
}
}
• Wiring
• Reed Switch
Works like a regular button but is activated by a magnet instead of a physical touch. When
a magnet is placed near the switch it closes, i.e. – is pressed. Coding and wiring are the
same as a mechanical tactile button. Sometimes a magnet is provided and other times
not.
• Capacitive button
Works like a regular button but there are no moving parts. Similar to a touch screen, the
switch can only be activated by certain materials touching the button, such as human skin.
Wiring involves three wires, one to 5V, one to ground, and one to a digital pin. Coding is
the same as the previous page, but switch usually sends out a HIGH signal when activated.
• Use
Can detect the amount of current in a circuit. Useful for determining when a battery charger is
done charging, or how much power you are getting from a solar panel.
These all require you to cut the wire you want to measure the current in. There are larger more
expensive ones that don’t. Those would also be required for larger measurements, such as the
current flowing through an appliance (e.g. – air conditioner).
• Code
void setup() {
Serial.begin(9600);
}
void loop() {
int sensorValue = analogRead(A0);
Serial.println(sensorValue);
}
• Wiring
In general, there are 5 connections:
Cut the wire you want to measure the current inside of, and connect those two ends to the largest
terminals on the board, usually labeled with a + and -.
Vcc to Arduino 5V
Gnd to Arduino ground
Vo/Vout/Out to Arduino analog pin A0
Notes:
o Protocols
o I2C is probably easiest to get multiple sensors on
o SSI/SPI also will work but trickier usually
o UART: if 9600 baud is OK then can use Software Serial, higher baud rates
on a case-by-case basis
o Vcc voltage, 3V? 5V? 12V?