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:
- how do we build the arduino and sensors
- how we communicate the raspberry pi (openhab server) with the arduino
Build the arduino with light and temperature sensor
Requirements- An Arduino uno
- 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 - 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} - Light sensor
http://www.amazon.com/gp/product/B00AF278A8?psc=1&redirect=true&ref_=oh_aui_detailpage_o01_s01 - Arduino case (optional)
http://www.amazon.com/gp/product/B00N52HR5Q?psc=1&redirect=true&ref_=oh_aui_detailpage_o02_s00 - Mini protoboard
- 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.