Monday 29 June 2015

Measure the temperature and light enviroment

Hi! how you doing?, in this post i want to show one of the most interesting uses in electronics, the sensors. With arduino and sensors you can measure any physic event, like light, temperature, distance, noise, anything  you can imagine.

Here i measured the temperature and the light of the corridor of my home. The sensors are very cheap and very easy to use in an arduino, you can think, why i want  an arduino if i have pins in my raspberry pi?, and this is a good observation. But you have to consider that the raspberry only has digital pins and the arduino has digital and analog pins.
Most of the sensors requires analog pins to read the value, so you can't use a raspberry for this.

We split the post in two sections:
  1. how do we build the arduino and sensors
  2. how we communicate the raspberry pi (openhab server) with the arduino

Build the arduino with light and temperature sensor

Requirements
  1. An Arduino uno
  2. arduino ethernet shield
    http://www.aliexpress.com/item/UNO-Shield-Ethernet-Shield-W5100-R3-UNO-Mega-2560-1280-328-UNR-R3-only-W5100-Development/1620285783.html?spm=2114.32010308.4.2.4CoIdI
  3. DHT22 sensor
    http://www.aliexpress.com/item/1pcs-DHT22-digital-temperature-and-humidity-sensor-Temperature-and-humidity-module-AM2302-replace-SHT11-SHT15-Free/1059369726.html}
  4. Light sensor
    http://www.amazon.com/gp/product/B00AF278A8?psc=1&redirect=true&ref_=oh_aui_detailpage_o01_s01
  5. Arduino case (optional)
    http://www.amazon.com/gp/product/B00N52HR5Q?psc=1&redirect=true&ref_=oh_aui_detailpage_o02_s00
  6. Mini protoboard
  7. Wires

The light sensor is more easy than the temperature sensor, because you only have to read the pin to know the value. As every analog sensor you can read a value between 0-1024, this is connected to a digital pin but remember is a PWM pin, their behavior is like a analog pin.
With the temperature sensor is a little more difficult, but don't think is rocket engineering.
You have to download the dhtlib and use the library, there are other libraries you can try, follow this link if you want to learn more.

The Arduino expose the measurements as a HTTP server, this the reason of the ethernet shield. Could be also a wifi shield and you don´t have to plug the arduino to the router but remember the ethernet shield is extremely more cheaper.
So you have to use the ethernet library to expose the values, for convenience and more interoperability the values are formatted as xml.

Communication between the raspberry pi and the arduino

The raspberry see the arduino as a normal web page. You get the values inside a xml, so you have to do an HTTP request and transform the values.
I defined three numbers items, the temperature, the humidity and the light, in the binding you can refresh the values every 30 seconds for example.
I don`t do it, but you can for example make a rule for activate the air conditioner if the temperature have a determined value or switch on the light if is getting dark.

1 comment:

  1. The Lucky Nugget Hotel and Casino - Mapyro
    The 화성 출장안마 Lucky Nugget Hotel 대전광역 출장안마 and Casino. 6,000 feet off The Strip, this Las Vegas resort features 광양 출장안마 a 충청남도 출장마사지 shopping center, a seasonal outdoor pool, and 서울특별 출장안마 a full-service

    ReplyDelete