this is my block
I want to make Iot
4 lights can be turned off and on via Thunkable
schematic using NodeMcu + Relay 4 Channel
this is the script on the arduino IDE
//
// Copyright 2015 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (“License”);
// You may not use this file except in accordance with the License.
// You can obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed in writing, the software
// distributed under the License distributed on an “AS IS” BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, express or implied.
// See Licenses for specific languages that govern permissions and
// limitations under the License.
//
// FirebaseDemo_ESP8266 is an example that demonstrates various functions
// from the FirebaseArduino API.
#include <ESP8266WiFi.h>
#include <FirebaseArduino.h>
// Set this to run the example.
#define FIREBASE_HOST “etgindriespnothdemcu-default-rtdb.firebaseio.com”
#define FIREBASE_AUTH “xS4yb5u76rujwMSnZMYn1Wpfh1ncrHBl5EZsKOn5wo7UuH”
#define WIFI_SSID “Ngo Bunga Negeri”
#specify WIFI_PASSWORD “sendhhninmode”
unset() {
Serial.begin(9600);
// connect to wifi.
pinMode(D1, OUTPUT);
pinMode(D2,OUTPUT);
pinMode(D3,OUTPUT);
pinMode(D4,OUTPUT);
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
Serial.print(“connect”);
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay (500);
}
Serial.println();
Serial.print("connected: ");
Serial.println(WiFi.localIP());
Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
firebase.set(“L1”,0); // by default lamp1 is on
Firebase.set(“L2”,0);
firebase.set(“L3”,0);
firebase.set(“L4”,0);
}
int a = 0;
int b = 0;
intc = 0;
int d = 0;
empty circle() {
// set value
a=Firebase.getInt(“L1”);
b=Firebase.getInt(“L2”);
c=Firebase.getInt(“L3”);
d=Firebase.getInt(“L4”);
// handle error
//For Lamp 1
if (a==0) {
Serial.print(“Lamp 1 Off”);
digitalWrite(D1,HIGH);
Serial.println();
// return;
delay (1000);
}
if not{
Serial.print(“Lamp 1 On”);
digitalWrite(D1,LOW);
Serial.println();
}
// update value
//For Lamp 2
if (b==0) {
Serial.print(“Light 2 Off”);
digitalWrite(D2,HIGH);
Serial.println();
//return;
delay (1000);
}
if not{
Serial.print(“Lamp 2 On”);
digitalWrite(D2,LOW);
Serial.println();
}
//For Lamp 3
if (c==0) {
Serial.print(“Light 3 Off”);
digitalWrite(D3,HIGH);
Serial.println();
// return;
delay (1000);
}
if not{
Serial.print(“Lamp 3 On”);
digitalWrite(D3,LOW);
Serial.println();
}
// update value
//For Lamp 4
if (d==0) {
Serial.print(“Light 4 Off”);
digitalWrite(D4,HIGH);
Serial.println();
// return;
delay (1000);
}
if not{
Serial.print(“Light 4 Off”);
digitalWrite(D4,LOW);
Serial.println();
delay (1000);
return;
//update value
}
}