LoginSignup
1
2

More than 3 years have passed since last update.

AmbientでESP-WROOM-02(esp8266)のアナログ入力を送信 遠隔制御

Posted at

前提

・ESP-WROOM-02がWi-Fiに接続されている→もしできてないならこちら(ESP-WROOM-02開発ボードでwi-fi接続からのWebサーバーにする)
・Ambientでアカウントを登録済み→もしできてないなら(AmbientのWebページ)

1:Ambientライブラリのインポート

こちらを参考にAmbientのライブラリをインポートしてきてください。

2:チャネルを作成して公開する

まず、チャネルを作るボタンを押してチャネルを作成してください。
1m2.PNG

次にチャネルの歯車マークを押してチャネルの設定を開いてください。
am3.PNG

公開チャネルにチェックをつけてチャネル属性を設定してください。
am4.PNG

3:データをAmbientに送信

Arduino IDEを開いてプログラムを書いていきます。
A0からの入力を送信するプログラムを書いていきたいと思います。

必要なもの

・作成したチャネルのチャネルID
・作成したチャネルのライトキー
・Wi-FiのSSID
・Wi-Fiのパスワード

プログラム

とりあえずこんな感じです。

#include <ESP8266WiFi.h>
#include <Wire.h>
#include "Ambient.h"

#ifndef STASSID
#define STASSID "ssid"
#define STAPSK  "password"
#endif

const char* ssid = STASSID;
const char* password = STAPSK;

unsigned int channelId = channelId;
const char* writeKey = "writekey";

WiFiClient client;
Ambient ambient;

int analog_value_zero = 0; 

const int led = 13;

//esp8266でアナログ入力するために必要
extern "C" {
#include "user_interface.h"
}



void setup() {
  // put your setup code here, to run once:

  pinMode(led, OUTPUT);
  digitalWrite(led, 0);
  Serial.begin(115200);
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);
  Serial.println("");

  // Wait for connection
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.print("Connected to ");
  Serial.println(ssid);
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());

  ambient.begin(channelId, writeKey, &client);

}

void loop() {
  // put your main code here, to run repeatedly:

 //system_abc_read()でアナログ入力を読み込む
  analog_value_zero = system_adc_read();
  float analog_value_zero_float = float(analog_value_zero);

  Serial.println(analog_value_zero_float);

 //値をセットして送信する
  ambient.set(1, analog_value_zero_float);
  ambient.send();

  delay(1000);
}

4:確認

作成したチャネルからグラフをみてちゃんとデータが送られているか確認しましょう。

参考

Arduino ESP8266で温度・湿度を測定し、Ambientに送ってグラフ化する

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2