Christmas Tree Water Level via Cayenne and MKR1000




When you have a ‘real’ Christmas tree, it is important to keep it watered. This project monitors the water level and emails alerts.

resize-_56expL32Lx

Things used in this project

Hardware components

Arduino MKR1000
Arduino MKR1000
× 1
water level sensor
× 1
LED (generic)
LED (generic)
× 4
Resistor 220 ohm
Resistor 220 ohm
× 4
Jumper wires (generic)
Jumper wires (generic)
× 1
Breadboard (generic)
Breadboard (generic)
× 1
USB-A to Micro-USB Cable
USB-A to Micro-USB Cable
× 1

Software apps and online services

Arduino IDE
Arduino IDE
Arduino Web Editor
Arduino Web Editor
Cayenne
myDevices Cayenne

Story

Cayenne

I set up a very simple dashboard in Cayenne that indicates the level via a gauge that also changes color depending on the value. These colors and values are the same as the LEDs on the local display.

Schematics

Code

/*
Cayenne MKR1000 Example

This sketch connects to the Cayenne server using an Arduino/Genuino MKR1000 and runs the main communication loop.

The Cayenne 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 Arduino SAMD Boards from the Arduino Boards Manager if you have not done so already.
2. Install the WiFi101 library (https://github.com/arduino-libraries/WiFi101) from the Arduino Library Manager if you have not done so already.
3. Select the Arduino/Genuino MKR1000 board and the correct port in the Arduino IDE.
4. Set the token variable to match the Arduino token from the Dashboard.
5. Set the network name and password.
6. Compile and upload this sketch.

For Cayenne Dashboard widgets using digital or analog pins this sketch will automatically
send data on those pins to the Cayenne server. If the widgets use Virtual Pins, data
should be sent to those pins using virtualWrites. Examples for sending and receiving
Virtual Pin data are under the Basics folder.
*/

#define CAYENNE_DEBUG         // Uncomment to show debug messages
#define CAYENNE_PRINT Serial  // Comment this out to disable prints and save space
#include <CayenneMKR1000.h>

// Cayenne authentication token. This should be obtained from the Cayenne Dashboard.
char token[] = "put your token here";
// Your network name and password.
char ssid[] = "put your ssid here";
char password[] = "put your wifi password here";

int led1 = 2;
int led2 = 3;
int led3 = 4;
int led4 = 5;

void setup()
{
  // initialize the digital pins as an outputs.
  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
  pinMode(led3, OUTPUT);
  pinMode(led4, OUTPUT);
  
  Serial.begin(9600);
  Cayenne.begin(token, ssid, password);
}

void loop()
{
  Cayenne.run();

  // read the input on analog pin 0:
  int sensorValue = analogRead(A0);
  // print out the value you read:
  Serial.println(sensorValue);
  digitalWrite(led1, LOW);
  digitalWrite(led2, LOW);
  digitalWrite(led3, LOW);
  digitalWrite(led4, LOW);
  if (sensorValue > 10) {digitalWrite(led1, HIGH); }
  if (sensorValue > 250) {digitalWrite(led2, HIGH); }
  if (sensorValue > 350) {digitalWrite(led3, HIGH); }
  if (sensorValue > 390) {digitalWrite(led4, HIGH); }

  
  delay(250);        // delay in between reads for stability
}

// These functions are called when the Cayenne widget requests data for the Virtual Pin.
CAYENNE_OUT(V0)
{
  Cayenne.virtualWrite(V0, analogRead(A0));
}

create.arduino.cc code

Source : Christmas Tree Water Level via Cayenne and MKR1000

READ  WiFi Temperature Sensor featuring 4Duino-24

JLCPCB – Prototype 10 PCBs for $2 (For Any Color)
China’s Largest PCB Prototype Enterprise, 600,000+ Customers & 10,000+ Online Orders Daily
See Why JLCPCB Is So Popular: https://jlcpcb.com




Leave a Comment

*
= 3 + 8

(Spamcheck Enabled)

Read previous post:
Victoria Arduino opens showroom
Victoria Arduino opens showroom in London

Coffee machine manufacture Victoria Arduino is opening its new showroom in London on 28 March in collaboration with its local...

Close
Scroll to top