본문 바로가기

IOT(Arduino+Inventor)

Esp-01, ThingSpeak,Control Of LED

ESP-01s 릴레이 모듈입니다. 오직 릴레이 기능만 가능하지만 두가지 기능을 갖게 할 수 있습니다.

릴레이인 esp-01s  Gpio  0 포트입니다. 그리고 LED_BUILTIN는 Gpio 2 입니다.

LED 제어는 세계어디에서 제어가 가능합니다.

그러기 위해서는 ThingSpeak.com 계정을 이용합니다.

준비물 : ESP-01S 모듈, ThingSpeak.com 계정, 기타

 

 아래 아두이노 소스코드를 업로드 합니다.

그리고 스마트폰에 MIT Inventor를  APP 작성 합니다.

 

 

 

 

릴레이 동작 (GPIO 0)

GPIO 2 동작

GPIO 0, GPIO 2 동작

GPIO 0, GPIO 2 동작

 

GPIO 0  제어 데이터

GPIO 2 제어 데이터

code

#include <ThingSpeak.h>               // add librery
#include <ESP8266WiFi.h>


unsigned long channel = 2092100;                // Channel ID_MOTOR_ONOff field01
//const char * myCounterReadAPIKey = "8WTLAO59D6OTOAUJ";      // Read API Key
const int led1 = 1;                                 // The field you wish to read
const int led2 = 2;                                 // The field you wish to read
WiFiClient  client;
void setup()
{
  pinMode(0,OUTPUT);
   pinMode(2,OUTPUT);
 digitalWrite(0,1);
  digitalWrite(2,1);
  Serial.begin(115200);
  Serial.println();

  WiFi.begin("IOT999", "kbs48752");           // write wifi name & password           

  Serial.print("Connecting");
  while (WiFi.status() != WL_CONNECTED)
  {
    delay(500);
    Serial.print(".");
  }
  Serial.println();
  Serial.print("WiFi Connected, IP address: ");
    Serial.println("IP address:  ");
   
   //Serial.println();
  Serial.println(WiFi.localIP());
  Serial.print("Net Mask: ");
  Serial.println(WiFi.subnetMask());
   Serial.print("GateWay:  ");
    Serial.println(WiFi.gatewayIP());
  ThingSpeak.begin(client);
}

void loop() 
{
 int led_1 = ThingSpeak.readLongField(channel, led1);
 int led_2 = ThingSpeak.readLongField(channel, led2);
 if(led_1==1){
  digitalWrite(0,1);
  Serial.println("0 is Off");
 }
 else if(led_1==0){
  digitalWrite(0,0);
  Serial.println("0 is On");
 
 }
 if(led_2==1){
  digitalWrite(2,1);
  Serial.println("2 is Off");
 }
 else if(led_2==0){
  digitalWrite(2,0);
  Serial.println("2 is On");
 
 }
 
 //delay(5000);
}

'IOT(Arduino+Inventor)' 카테고리의 다른 글

3 Room Switch  (0) 2025.01.14
Room WiFi Switch  (0) 2025.01.09
온도 센서 ds18b20  (0) 2023.04.12
esp-01S Relay[5]  (0) 2023.04.12
ESP-01, DHT11, ThingSpeak [5]  (0) 2023.04.11