mirror of
https://github.com/home-assistant/home-assistant.io.git
synced 2025-07-29 12:17:01 +00:00
Add examples
This commit is contained in:
parent
9faf94b30e
commit
6f553ed23c
@ -57,4 +57,35 @@ sensor:
|
|||||||
```
|
```
|
||||||
{% endraw %}
|
{% endraw %}
|
||||||
|
|
||||||
|
## {% linkable_title Examples %}
|
||||||
|
|
||||||
|
### {% linkable_title Arduino %}
|
||||||
|
|
||||||
|
For controllers of the Arduino family a possible sketch to read the temperature and the humidity could look like the sample below.
|
||||||
|
|
||||||
|
```
|
||||||
|
#include <ArduinoJson.h>
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
Serial.begin(115200);
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
StaticJsonBuffer<100> jsonBuffer;
|
||||||
|
JsonObject& json = prepareResponse(jsonBuffer);
|
||||||
|
json.printTo(Serial);
|
||||||
|
Serial.println();
|
||||||
|
delay(2000);
|
||||||
|
}
|
||||||
|
|
||||||
|
JsonObject& prepareResponse(JsonBuffer& jsonBuffer) {
|
||||||
|
JsonObject& root = jsonBuffer.createObject();
|
||||||
|
root["temperature"] = analogRead(A0);
|
||||||
|
root["humidity"] = analogRead(A1);
|
||||||
|
return root;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### {% linkable_title Digispark USB Development Board %}
|
||||||
|
|
||||||
|
This [blog post](/blog/2017/10/23/simple-analog-sensor/) describes the setup with a Digispark USB Development Board.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user