This post is the first part in a series that will walk you through connecting several sensors to an Arduino microcontroller board. Of course you could buy a weather shield that has all the sensors included, but where is the fun in doing that? In addition to that, I already had some components laying around just taking up space so why not put them to good use.
- 1x Arduino Mega 2560.
- 1x Sparkfun TSL2561 luminosity sensor breakout board.
- 1x TMP36 temperature sensor.
- 1x Breadboard
- ~10x jumper wires, M/M and F/F (if the M/M ones are too short).
- 1x USB cable A-male to B-male for powering up the Arduino and connecting to it.
Arduino Mega 2560
The Arduino Mega 2560 is a microcontroller board based on Atmel’s ATmega2560
. It has 54 digital input/output pins (of which 15 can be used as
PWM outputs), 16 analog inputs, 4 UARTs (hardware serial ports), a 16 MHz crystal oscillator, a USB connection, a power jack, an ICSP header, and a reset button. It contains everything needed to support the microcontroller; simply connect it to a computer with a USB cable or power it with a AC-to-DC adapter or battery to get started.
Sparkfun TSL2561 luminosity sensor
TSL2561 is an inexpensive, yet sophisticated, light sensor. Unlike simpler sensors, like photoresistors and photodiodes, the TSL2561 incorporates both infrared and visible light sensors to better approximate the response of the human eye. Because the TSL2561 is an integrating sensor (it soaks up light for a predetermined amount of time), it is capable of measuring both very small and very large amounts of light.
The breakout board has five pins:
INTis an optional interrupt signal which the TSL2561 can use to “interrupt” your microcontroller. You can set up the TSL2561 to automatically send an interrupt when it completes a measurement, or if a measurement goes above or below a certain level for a certain amount of time.
SCLis the I2C clock line.
SDAis the I2C data line.
You should read the
for more info.
TMP36 temperature sensor
TMP36 is an analogue sensor, that needs to be read using the Arduino’s analogue input. The sensor outputs a voltage that is proportional to the temperature and is packaged in a transistor like
TO92 format. The sensor can operate at either 5 volts or 3 volts, but will produce greater accuracy when operated at 3 volts.
The sensor has three pins:
Vinleft, 2.7-5.5V in.
Voutmiddle is analog voltage out.
You should read the
for more info.
AREFpin, because by default the ADC in the Arduino uses an internal reference voltage of 5V.
3.3Vpin from Arduino goes to the breadboard voltage rail.
GNDpin from Arduino goes to the breadboard ground rail.
ANALOG) pin from Arduino goes to the middle pin of the TMP36 sensor via breadboard.
AREFpin from Arduino goes to the breadboard voltage rail (3.3V).
SCLpin from Arduino goes to the TSL2561’s
SDApin from Arduino goes to the TSL2561’s
- additionally, TSL2561 and TMP36 get wired to the breadboard
Open the Arduino IDE, go to
New and paste the code below (or download the sketch
in .ino format). Go to
Board and select
Arduino Mega or Mega 2560, also select the USB port the board is connected from
Port. Don’t forget to connect the Arduino board to power (be it an USB cable to your laptop/computer or a battery).
CTRL+R for Windows) and the sketch should compile. If everything is ok, press
CTRL+U for Windows) to upload the compiled sketch into the Arduino Mega. Open the
Serial Monitor from the
Tools menu and you should see output from the sensors.
light sensor setting timing light sensor powering up light sensor RAW DATA: data0=32, data1=9, lux=10.19, valid=yes temp sensor RAW DATA: reading=792.00, voltage=0.77V, temp=27.34°C, temp=81.22°F light sensor RAW DATA: data0=3, data1=1, lux=0.82, valid=yes temp sensor RAW DATA: reading=755.70, voltage=0.74V, temp=23.80°C, temp=74.84°F
For the next part we’ll be adding some more sensors and data processing. Stay tuned!