Hendra Kusumah
Published

Linkit One: Water Level Indicator

In this project we will learn on making water level indicator using linkit one. This project could help you save water more efficiently.

IntermediateShowcase (no instructions)1,917
Linkit One: Water Level Indicator

Things used in this project

Hardware components

LED (generic)
LED (generic)
×3
Resistor 330 ohm
Resistor 330 ohm
×3
Water Level Sensor
×1

Story

Read more

Code

Code snippet #1

Plain text
int red = 10;int yellow = 9;
int green = 8;void setup() {
   Serial.begin(9600);
   pinMode(red, OUTPUT);
   pinMode(yellow, OUTPUT);
   pinMode(green, OUTPUT);}void loop() {  int sensorValue = analogRead(A0);
  if (sensorValue <=480){
    digitalWrite(green, HIGH);
    digitalWrite(yellow, LOW);
    digitalWrite(red, LOW);
  }
  else if (sensorValue >=480 && sensorValue <=530){
    digitalWrite(red, LOW);
    digitalWrite(yellow, HIGH);
    digitalWrite(green, LOW);
  }
  else if (sensorValue >=530){
    digitalWrite(green, LOW);
    digitalWrite(yellow, LOW);
    digitalWrite(red, HIGH);
  }
  Serial.println(sensorValue);
  delay(1);}

ubidot linkit one

Arduino
//Put your variable key in "idvariable"

//and put your token key in "token" 
#include <LTask.h>
#include <LWiFi.h>
#include <LWiFiClient.h>
#define WIFI_AP "YourWiFiName"
#define WIFI_PASSWORD "WiFiPassword"
#define WIFI_AUTH LWIFI_WPA  // choose from LWIFI_OPEN, LWIFI_WPA, or LWIFI_WEP according to you WiFi AP configuration

LWiFiClient client;

String idvariable = "YourVariableKey";
String token = "YourTokenKey";

void setup() {
    // Open serial communications and wait for port to open:
     LWiFi.begin();
     Serial.begin(115200);
     
     Serial.println("connecting...");
     while (0 == LWiFi.connect(WIFI_AP, LWiFiLoginInfo(WIFI_AUTH, WIFI_PASSWORD)))
  {
    delay(1000);
  }
   }

void loop()
   {
     int value = analogRead(A0);
     save_value(String(value));
   }

void save_value(String value)
   {
     // if you get a connection, report back via serial:
     int num=0;
     String var = "{\"value\":"+ String(value) + "}";
     num = var.length();
     delay(10000);
     if(client.connect("things.ubidots.com", 80))
     {
       Serial.println("connected");    // New lines according to ubidots support:       
       client.println("POST /api/v1.6/variables/"+idvariable+"/values HTTP/1.1");
       Serial.println("POST /api/v1.6/variables/"+idvariable+"/values HTTP/1.1");
       client.println("Content-Type: application/json");
       Serial.println("Content-Type: application/json");
       client.println("Content-Length: "+String(num));
       Serial.println("Content-Length: "+String(num));
       client.println("X-Auth-Token: "+token);
       Serial.println("X-Auth-Token: "+token);
       client.println("Host: things.ubidots.com\n");
       Serial.println("Host: things.ubidots.com\n");
       client.print(var);
       Serial.print(var+"\n");
     }
     else
     {
       // if you didn't get a connection to the server:
       Serial.println("connection failed");
     }

   if (!client.connected())
     {
       Serial.println();
       Serial.println("disconnecting.");
       client.stop();
     }

    if (client.available())
     {
       char c = client.read();
       Serial.print(c);
     }
     client.flush();
     client.stop();

}

Credits

Hendra Kusumah

Hendra Kusumah

27 projects • 125 followers
Love hacking and making new things from IoT to robotics

Comments