Hello folks!
I’ve used the esp-01 and Arduino Nano to control an Electric door and a Water heater from internet, using the Thinger platform. The Android application is used to turn ON/OFF the Water heater and to hold open the Electric door for 2 seconds.
This can be done with esp-01 itself and 2 transistors, without Arduino, but I’m planing to upgrade the project and add 2 more devices on it using RF 433mhz modules to communicate to the other room.
https://www.youtube.com/watch?v=B7YCGIZ6iuY
Components used
- Arduino Nano
- esp8266 wifi module
- 2 channel relay
- 1 channel relay
- 400 point breadboard
- breadboard power supply
esp8266 code
First I’ve created a device called “wifi” on Thinger and then uploaded the code to the esp-01:
bojler = water heater
vrata = electric door
#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(); }
Arduino code
then uploaded the code to the Arduino:
> 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);
> }
And the wiring looks like this:
Problem
Everything works fine, but there is a little problem.
When I open the Android app the values of the two GPIO reset to LOW, if my heater is turned ON and someone opens the Android app, the heater will turn OFF. I think it is because this part of the code:
// 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); };
Now I need some suggestions, how to make to keep the old value i.e. when I open the app the current state to be shown, not to reset to LOW.