Arduino weather station

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.
Components
- 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.
You can view a large pinout diagram here or download the PDF version.
Sparkfun TSL2561 luminosity sensor
The 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.
Pins
The breakout board has five pins:
INT
is 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.3.3V
in.GND
is ground.SCL
is the I2C clock line.SDA
is the I2C data line.
Datasheet
You should read the TSL2561
datasheet for more info.
TMP36 temperature sensor
The 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.
Pins
The sensor has three pins:
Vin
left, 2.7-5.5V in.GND
right, ground.Vout
middle is analog voltage out.
Datasheet
You should read the TMP36
datasheet for more info.
Note
AREF
pin, because by default the ADC in the Arduino uses an internal reference voltage of 5V.Connections
3.3V
pin from Arduino goes to the breadboard voltage rail.GND
pin from Arduino goes to the breadboard ground rail.A15
(ANALOG
) pin from Arduino goes to the middle pin of the TMP36 sensor via breadboard.AREF
pin from Arduino goes to the breadboard voltage rail (3.3V).SCL
pin from Arduino goes to the TSL2561’sSCL
pin.SDA
pin from Arduino goes to the TSL2561’sSDA
pin.- additionally, TSL2561 and TMP36 get wired to the breadboard
GND
and3.3V
rails.
Code
Note
Open the Arduino IDE, go to File
-> New
and paste the code below (or download the sketch in .ino format). Go to Tools
-> Board
and select Arduino Mega or Mega 2560
, also select the USB port the board is connected from Tools
-> Port
. Don’t forget to connect the Arduino board to power (be it an USB cable to your laptop/computer or a battery).
|
|
Press ⌘+R
(or CTRL+R
for Windows) and the sketch should compile. If everything is ok, press ⌘+U
(or 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!