Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Cayenne DS18B20 Example
- This sketch shows how to send DS18B20 Sensor data to the Cayenne Dashboard.
- The CayenneMQTT Library is required to run this sketch. If you have not already done so you can install it from the Arduino IDE Library Manager.
- Steps:
- 1. Install the OneWire library (http://www.pjrc.com/teensy/td_libs_OneWire.html) from the Arduino Library Manager.
- 2. Install the DallasTemperature library (http://milesburton.com/Main_Page?title=Dallas_Temperature_Control_Library#Code.2FLibrary) from the Arduino Library Manager.
- 3. Attach a DS18B20 to a digital pin on your Arduino.
- Schematic:
- [Ground] -- [DS18B20] -- [4.7k resistor] -- [5V]
- |______________|
- |
- Digital Pin
- 4. Set the SENSOR_PIN value below to the pin number you used when connecting the sensor.
- 5. Set the VIRTUAL_CHANNEL value below to a free virtual channel (or the virtual channel of a DS18B20 Sensor widget you have added) in the Dashboard.
- 6. Set the Cayenne authentication info to match the authentication info from the Dashboard.
- 7. Compile and upload this sketch.
- 8. Once the Arduino connects to the Dashboard it should automatically create a temporary display widget (or update the DS18B20 Sensor widget you have added) with data.
- To make a temporary widget permanent click the plus sign on the widget.
- */
- #define CAYENNE_PRINT Serial // Comment this out to disable prints and save space
- #include <OneWire.h>
- #include <DallasTemperature.h>
- #include <CayenneMQTTEthernet.h>
- // Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
- char username[] = "";
- char password[] = "";
- char clientID[] = "";
- #define VIRTUAL_CHANNEL1 1
- #define VIRTUAL_CHANNEL2 2
- #define VIRTUAL_CHANNEL3 3
- #define VIRTUAL_CHANNEL4 4
- #define VIRTUAL_CHANNEL5 5
- #define VIRTUAL_CHANNEL6 6
- #define VIRTUAL_CHANNEL7 7
- #define VIRTUAL_CHANNEL8 8
- // #define VIRTUAL_CHANNEL9 9
- // #define VIRTUAL_CHANNEL10 10
- #define ACTUATOR_PIN1 40
- #define ACTUATOR_PIN2 41
- #define ACTUATOR_PIN3 42
- #define ACTUATOR_PIN4 43
- #define ACTUATOR_PIN5 44
- #define ACTUATOR_PIN6 45
- #define ACTUATOR_PIN7 46
- #define ACTUATOR_PIN8 47
- //#define ACTUATOR_PIN9 48
- #define SENSOR_PIN22 22
- #define SENSOR_PIN23 23
- #define SENSOR_PIN24 24
- #define SENSOR_PIN25 25
- #define SENSOR_PIN26 26
- #define SENSOR_PIN27 27
- #define SENSOR_PIN28 28
- // #define SENSOR_PIN29 29
- // #define SENSOR_PIN30 30
- // #define SENSOR_PIN31 31
- // #define SENSOR_PIN32 32
- // #define SENSOR_PIN33 33
- // #define SENSOR_PIN34 34
- // #define SENSOR_PIN35 35
- // #define SENSOR_PIN36 36
- // #define SENSOR_PIN37 37
- #define VIRTUAL_CHANNEL22 22
- #define VIRTUAL_CHANNEL23 23
- #define VIRTUAL_CHANNEL24 24
- #define VIRTUAL_CHANNEL25 25
- #define VIRTUAL_CHANNEL26 26
- #define VIRTUAL_CHANNEL27 27
- #define VIRTUAL_CHANNEL28 28
- // #define VIRTUAL_CHANNEL29 29
- // #define VIRTUAL_CHANNEL30 30
- // #define VIRTUAL_CHANNEL31 31
- // #define VIRTUAL_CHANNEL32 32
- // #define VIRTUAL_CHANNEL33 33
- // #define VIRTUAL_CHANNEL34 34
- // #define VIRTUAL_CHANNEL35 35
- // #define VIRTUAL_CHANNEL36 36
- // #define VIRTUAL_CHANNEL37 37
- OneWire oneWire22(SENSOR_PIN22);
- OneWire oneWire23(SENSOR_PIN23);
- OneWire oneWire24(SENSOR_PIN24);
- OneWire oneWire25(SENSOR_PIN25);
- OneWire oneWire26(SENSOR_PIN26);
- OneWire oneWire27(SENSOR_PIN27);
- OneWire oneWire28(SENSOR_PIN28);
- // OneWire oneWire29(SENSOR_PIN29);
- // OneWire oneWire30(SENSOR_PIN30);
- // OneWire oneWire31(SENSOR_PIN31);
- // OneWire oneWire32(SENSOR_PIN32);
- // OneWire oneWire33(SENSOR_PIN33);
- // OneWire oneWire34(SENSOR_PIN34);
- // OneWire oneWire35(SENSOR_PIN35);
- // OneWire oneWire36(SENSOR_PIN36);
- // OneWire oneWire37(SENSOR_PIN37);
- DallasTemperature sensors22(&oneWire22);
- DallasTemperature sensors23(&oneWire23);
- DallasTemperature sensors24(&oneWire24);
- DallasTemperature sensors25(&oneWire25);
- DallasTemperature sensors26(&oneWire26);
- DallasTemperature sensors27(&oneWire27);
- DallasTemperature sensors28(&oneWire28);
- // DallasTemperature sensors29(&oneWire29);
- // DallasTemperature sensors30(&oneWire30);
- // DallasTemperature sensors31(&oneWire31);
- // DallasTemperature sensors32(&oneWire32);
- // DallasTemperature sensors33(&oneWire33);
- // DallasTemperature sensors34(&oneWire34);
- // DallasTemperature sensors35(&oneWire35);
- // DallasTemperature sensors36(&oneWire36);
- // DallasTemperature sensors37(&oneWire37);
- void setup()
- {
- Serial.begin(9600);
- pinMode(ACTUATOR_PIN1, OUTPUT);
- pinMode(ACTUATOR_PIN2, OUTPUT);
- pinMode(ACTUATOR_PIN3, OUTPUT);
- pinMode(ACTUATOR_PIN4, OUTPUT);
- pinMode(ACTUATOR_PIN5, OUTPUT);
- pinMode(ACTUATOR_PIN6, OUTPUT);
- pinMode(ACTUATOR_PIN7, OUTPUT);
- pinMode(ACTUATOR_PIN8, OUTPUT);
- // pinMode(ACTUATOR_PIN9, OUTPUT);
- // pinMode(ACTUATOR_PIN10, OUTPUT);
- Cayenne.begin(username, password, clientID);
- sensors22.begin();
- sensors23.begin();
- sensors24.begin();
- sensors25.begin();
- sensors26.begin();
- sensors27.begin();
- sensors28.begin();
- // sensors29.begin();
- // sensors30.begin();
- // sensors31.begin();
- // sensors32.begin();
- // sensors33.begin();
- // sensors34.begin();
- // sensors35.begin();
- // sensors36.begin();
- // sensors37.begin();
- }
- void loop()
- {
- Cayenne.loop();
- }
- CAYENNE_IN(VIRTUAL_CHANNEL1)
- {
- // Write value to turn the relay switch on or off. This code assumes you wire your relay as normally open.
- if (getValue.asInt() == 0) {
- digitalWrite(ACTUATOR_PIN1, HIGH);
- }
- else {
- digitalWrite(ACTUATOR_PIN1, LOW);
- }
- }
- CAYENNE_IN(VIRTUAL_CHANNEL2)
- {
- // Write value to turn the relay switch on or off. This code assumes you wire your relay as normally open.
- if (getValue.asInt() == 0) {
- digitalWrite(ACTUATOR_PIN2, HIGH);
- }
- else {
- digitalWrite(ACTUATOR_PIN2, LOW);
- }
- }
- CAYENNE_IN(VIRTUAL_CHANNEL3)
- {
- // Write value to turn the relay switch on or off. This code assumes you wire your relay as normally open.
- if (getValue.asInt() == 0) {
- digitalWrite(ACTUATOR_PIN3, HIGH);
- }
- else {
- digitalWrite(ACTUATOR_PIN3, LOW);
- }
- }
- CAYENNE_IN(VIRTUAL_CHANNEL4)
- {
- // Write value to turn the relay switch on or off. This code assumes you wire your relay as normally open.
- if (getValue.asInt() == 0) {
- digitalWrite(ACTUATOR_PIN4, HIGH);
- }
- else {
- digitalWrite(ACTUATOR_PIN4, LOW);
- }
- }
- CAYENNE_IN(VIRTUAL_CHANNEL5)
- {
- // Write value to turn the relay switch on or off. This code assumes you wire your relay as normally open.
- if (getValue.asInt() == 0) {
- digitalWrite(ACTUATOR_PIN5, HIGH);
- }
- else {
- digitalWrite(ACTUATOR_PIN5, LOW);
- }
- }
- CAYENNE_IN(VIRTUAL_CHANNEL6)
- {
- // Write value to turn the relay switch on or off. This code assumes you wire your relay as normally open.
- if (getValue.asInt() == 0) {
- digitalWrite(ACTUATOR_PIN6, HIGH);
- }
- else {
- digitalWrite(ACTUATOR_PIN6, LOW);
- }
- }
- CAYENNE_IN(VIRTUAL_CHANNEL7)
- {
- // Write value to turn the relay switch on or off. This code assumes you wire your relay as normally open.
- if (getValue.asInt() == 0) {
- digitalWrite(ACTUATOR_PIN7, HIGH);
- }
- else {
- digitalWrite(ACTUATOR_PIN7, LOW);
- }
- }
- CAYENNE_IN(VIRTUAL_CHANNEL8)
- {
- // Write value to turn the relay switch on or off. This code assumes you wire your relay as normally open.
- if (getValue.asInt() == 0) {
- digitalWrite(ACTUATOR_PIN8, HIGH);
- }
- else {
- digitalWrite(ACTUATOR_PIN8, LOW);
- }
- }
- /* CAYENNE_IN(VIRTUAL_CHANNEL9)
- {
- // Write value to turn the relay switch on or off. This code assumes you wire your relay as normally open.
- if (getValue.asInt() == 0) {
- digitalWrite(ACTUATOR_PIN9, HIGH);
- }
- else {
- digitalWrite(ACTUATOR_PIN9, LOW);
- }
- }
- CAYENNE_IN(VIRTUAL_CHANNEL10)
- {
- // Write value to turn the relay switch on or off. This code assumes you wire your relay as normally open.
- if (getValue.asInt() == 0) {
- digitalWrite(ACTUATOR_PIN10, HIGH);
- }
- else {
- digitalWrite(ACTUATOR_PIN10, LOW);
- }
- }*/
- // This function is called at intervals to send sensor data to Cayenne.
- CAYENNE_OUT(VIRTUAL_CHANNEL22)
- {
- sensors22.requestTemperatures();
- Cayenne.celsiusWrite(VIRTUAL_CHANNEL22, sensors22.getTempCByIndex(0));
- }
- CAYENNE_OUT(VIRTUAL_CHANNEL23)
- {
- sensors23.requestTemperatures();
- Cayenne.celsiusWrite(VIRTUAL_CHANNEL23, sensors23.getTempCByIndex(0));
- }
- CAYENNE_OUT(VIRTUAL_CHANNEL24)
- {
- sensors24.requestTemperatures();
- Cayenne.celsiusWrite(VIRTUAL_CHANNEL24, sensors24.getTempCByIndex(0));
- }
- CAYENNE_OUT(VIRTUAL_CHANNEL25)
- {
- sensors25.requestTemperatures();
- Cayenne.celsiusWrite(VIRTUAL_CHANNEL25, sensors25.getTempCByIndex(0));
- }
- CAYENNE_OUT(VIRTUAL_CHANNEL26)
- {
- // Send the command to get temperatures.
- sensors26.requestTemperatures();
- // This command writes the temperature in Celsius to the Virtual Channel.
- Cayenne.celsiusWrite(VIRTUAL_CHANNEL26, sensors26.getTempCByIndex(0));
- }
- CAYENNE_OUT(VIRTUAL_CHANNEL27)
- {
- // Send the command to get temperatures.
- sensors27.requestTemperatures();
- // This command writes the temperature in Celsius to the Virtual Channel.
- Cayenne.celsiusWrite(VIRTUAL_CHANNEL27, sensors27.getTempCByIndex(0));
- }
- CAYENNE_OUT(VIRTUAL_CHANNEL28)
- {
- // Send the command to get temperatures.
- sensors28.requestTemperatures();
- // This command writes the temperature in Celsius to the Virtual Channel.
- Cayenne.celsiusWrite(VIRTUAL_CHANNEL28, sensors28.getTempCByIndex(0));
- }
- /* CAYENNE_OUT(VIRTUAL_CHANNEL29)
- {
- // Send the command to get temperatures.
- sensors29.requestTemperatures();
- // This command writes the temperature in Celsius to the Virtual Channel.
- Cayenne.celsiusWrite(VIRTUAL_CHANNEL29, sensors29.getTempCByIndex(0));
- }
- CAYENNE_OUT(VIRTUAL_CHANNEL30)
- {
- // Send the command to get temperatures.
- sensors30.requestTemperatures();
- // This command writes the temperature in Celsius to the Virtual Channel.
- Cayenne.celsiusWrite(VIRTUAL_CHANNEL30, sensors30.getTempCByIndex(0));
- }
- CAYENNE_OUT(VIRTUAL_CHANNEL31)
- {
- // Send the command to get temperatures.
- sensors31.requestTemperatures();
- // This command writes the temperature in Celsius to the Virtual Channel.
- Cayenne.celsiusWrite(VIRTUAL_CHANNEL31, sensors31.getTempCByIndex(0));
- }
- CAYENNE_OUT(VIRTUAL_CHANNEL32)
- {
- // Send the command to get temperatures.
- sensors32.requestTemperatures();
- // This command writes the temperature in Celsius to the Virtual Channel.
- Cayenne.celsiusWrite(VIRTUAL_CHANNEL32, sensors32.getTempCByIndex(0));
- }
- CAYENNE_OUT(VIRTUAL_CHANNEL33)
- {
- // Send the command to get temperatures.
- sensors33.requestTemperatures();
- // This command writes the temperature in Celsius to the Virtual Channel.
- Cayenne.celsiusWrite(VIRTUAL_CHANNEL33, sensors33.getTempCByIndex(0));
- }
- CAYENNE_OUT(VIRTUAL_CHANNEL34)
- {
- // Send the command to get temperatures.
- sensors34.requestTemperatures();
- // This command writes the temperature in Celsius to the Virtual Channel.
- Cayenne.celsiusWrite(VIRTUAL_CHANNEL34, sensors34.getTempCByIndex(0));
- }
- CAYENNE_OUT(VIRTUAL_CHANNEL35)
- {
- // Send the command to get temperatures.
- sensors35.requestTemperatures();
- // This command writes the temperature in Celsius to the Virtual Channel.
- Cayenne.celsiusWrite(VIRTUAL_CHANNEL35, sensors35.getTempCByIndex(0));
- }
- CAYENNE_OUT(VIRTUAL_CHANNEL36)
- {
- // Send the command to get temperatures.
- sensors36.requestTemperatures();
- // This command writes the temperature in Celsius to the Virtual Channel.
- Cayenne.celsiusWrite(VIRTUAL_CHANNEL36, sensors36.getTempCByIndex(0));
- }
- CAYENNE_OUT(VIRTUAL_CHANNEL37)
- {
- // Send the command to get temperatures.
- sensors37.requestTemperatures();
- // This command writes the temperature in Celsius to the Virtual Channel.
- Cayenne.celsiusWrite(VIRTUAL_CHANNEL37, sensors37.getTempCByIndex(0));
- } */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement