Electric door and a Water heater controlled from Internet
Posted: Tue Nov 10, 2015 2:27 pm
[youtube]https://www.youtube.com/watch?v=B7YCGIZ6iuY[/youtube]
-->
Open Community Forum for ESP8266, Come share Arduino and IoT (Internet of Things)
https://www.esp8266.com/
#include <SPI.h>
#include <ESP8266WiFi.h>
#include <ThingerWifi.h>
#define USERNAME "username"
#define DEVICE_ID "deviceid"
#define DEVICE_CREDENTIAL "devicecredentials"
#define SSID "networkName"
#define SSID_PASSWORD "networkPassword"
ThingerWifi thing(USERNAME, DEVICE_ID, DEVICE_CREDENTIAL);
void setup() {
pinMode(0, OUTPUT);
pinMode(1, OUTPUT);
thing.add_wifi(SSID, SSID_PASSWORD);
// resource input example (i.e. turning on/off a light, a relay, configuring a parameter, etc)
thing["bojler"] << [](pson& in){ digitalWrite(0, in ? HIGH : LOW); };
// resource input example (i.e. turning on/off a light, a relay, configuring a parameter, etc)
thing["vrata"] << [](pson& in){ digitalWrite(2, in ? HIGH : LOW); };
}
void loop() {
thing.handle();
}
int bojler = 2;
int vrata = 3;
int sostojba = 0;
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
pinMode(bojler, OUTPUT);
pinMode(vrata, OUTPUT);
}
// the loop routine runs over and over again forever:
void loop() {
digitalWrite(vrata, LOW);
int pom1 = analogRead(A0);
int pom2 = analogRead(A1);
float bojlerV = pom1 * (5.0 / 1023.0);
float vrataV = pom2 * (5.0 / 1023.0);
if (bojlerV<2)
{
digitalWrite(bojler, HIGH);
}
else if (bojlerV>3)
{
digitalWrite(bojler, LOW);
}
if (vrataV<2)
{
sostojba = 0;
}
else if (vrataV>3)
{
sostojba++;
}
if (sostojba==10)
{
sostojba = 2;
}
if (sostojba==1)
{
digitalWrite(vrata, HIGH);
delay(2000);
digitalWrite(vrata, LOW);
}
delay(250);
Serial.print("Bojler napon: ");
Serial.println(bojlerV);
Serial.print("Vrata napon: ");
Serial.println(vrataV);
Serial.print("Sostojba: ");
Serial.println(sostojba);
}