get WAN IP arduino
/in Arduino /by อ.เอ้ดvoid GetExternalIP()
{
WiFiClient client;
if (!client.connect(“api.ipify.org”, 80)) {
Serial.println(“Failed to connect with ‘api.ipify.org’ !”);
}
else {
int timeout = millis() + 5000;
client.print(“GET /?format=json HTTP/1.1\r\nHost: api.ipify.org\r\n\r\n”);
while (client.available() == 0) {
if (timeout – millis() < 0) {
Serial.println(“>>> Client Timeout !”);
client.stop();
return;
}
}
int size;
while ((size = client.available()) > 0) {
uint8_t* msg = (uint8_t*)malloc(size);
size = client.read(msg, size);
Serial.write(msg, size);
free(msg);
}
}
}
credit:martinayotte
source:https://www.esp8266.com/viewtopic.php?f=6&t=12782
Arduino Fix IP wifi
/in Arduino /by อ.เอ้ดใส่ code นี้ตอนกำหนด parameter
IPAddress staticIP(192, 168, xx, xx); //ESP static IP address
IPAddress gateway(192, 168, xx, 1); //IP Address of your WiFi Router (Gateway)
IPAddress subnet(255, 255, 255, 0); //Subnet mask
IPAddress primaryDNS(8, 8, 8, 8); //optional
IPAddress secondaryDNS(8, 8, 4, 4); //optionalDNS
แทรก code ถัดจาก void setup()
// Configures static IP address
if (!WiFi.config(staticIP, gateway, subnet, primaryDNS, secondaryDNS)) {
Serial.println(“STA Failed to configure”);
}
ESP32 wind Speed (Anemometer) thingspeak+fix IP wifi
/in Arduino /by อ.เอ้ด// create 04-dec-2019
#include<WiFi.h>
#include “ThingSpeak.h”
//—————- Fill in your credentails thingspeak 2019 ———————
char ssid[] = “XXXX”; // your network SSID (name)
char pass[] = “xxxxxx”; // your network password
unsigned long myChannelNumber = xxxxxx; // Replace the 0 with your channel number
const char * myWriteAPIKey = “xxxxxxxxxxxx”; // Paste your ThingSpeak Write API Key between the quotes
String myStatus = “”;
//——————————————————————
WiFiClient client;
int number = 0;
//Static IP address configuration
IPAddress staticIP(192, 168, xx,xx); //ESP static IP address
IPAddress gateway(192, 168, xx, 1); //IP Address of your WiFi Router (Gateway)
IPAddress subnet(255, 255, 255, 0); //Subnet mask
IPAddress primaryDNS(8, 8, 8, 8); //optional
IPAddress secondaryDNS(8, 8, 4, 4); //optionalDNS
//wind speed parameter
const int m_time = 5; //Measure time in Seconds
int wind_ct = 0;
float windkm = 0.0;
float windms = 0.0;
unsigned long ttime = 0;
void setup()
{
Serial.begin(115200);
// Configures static IP address
if (!WiFi.config(staticIP, gateway, subnet, primaryDNS, secondaryDNS)) {
Serial.println(“STA Failed to configure”);
}
// connect wifi
Connect_to_Wifi();
// time parameter
ttime = millis();
WiFi.mode(WIFI_STA);
ThingSpeak.begin(client); // Initialize ThingSpeak
}
void loop()
{
meassure();
Serial.print(“ความเร็วลม: “);
Serial.print(windkm); //Speed in Km/h
Serial.print(” km/h – “);
Serial.print(windms); //Speed in m/s
Serial.println(” m/s”);
// Write to ThingSpeak. There are up to 8 fields in a channel, allowing you to store up to 8 different
// pieces of information in a channel. Here, we write to field 1.
// set the fields with the values
ThingSpeak.setField(1, windkm);
ThingSpeak.setField(2, windms);
// set the status
ThingSpeak.setStatus(myStatus);
//int x = ThingSpeak.writeField(myChannelNumber, 1, windkm, myWriteAPIKey);
int x = ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);
// Check the return code
if(x == 200) {
Serial.println(“ThingSpeak Channel update successful.”);
}
else{
Serial.println(“Problem updating channel. HTTP error code ” + String(x));
}
number++;
if(number > 99){
number = 0;
}
delay(20000); // Wait 20 seconds before sending a new value
delay(20000);
}
void countWind() {
wind_ct ++;
}
void meassure() {
wind_ct = 0;
ttime = millis();
attachInterrupt(16, countWind, RISING);
delay(1000 * m_time);
detachInterrupt(1);
windkm = (float)wind_ct / (float)m_time * 2.4;
windms = windkm/3.6;
}
void Connect_to_Wifi()
{
// We start by connecting to a WiFi network
Serial.println(“Connecting to “);
Serial.println(ssid);
WiFi.begin(ssid, pass);
//Serial.println();
Serial.println();
Serial.print(“Wait for WiFi… “);
while (WiFi.status() != WL_CONNECTED) {
Serial.print(“.”);
delay(500);
}
Serial.println(“”);
Serial.println(“WiFi connected”);
Serial.print(“IP address: “);
Serial.println(WiFi.localIP());
}
source:https://github.com/mathworks/thingspeak-arduino
ที่วัดความเร็วลม Wind Speed (Anemometer) กับ ESP32
/in Arduino /by อ.เอ้ดใช้ Interrupt ที่ขา GPIO
attachInterrupt(GPIOPin, ISR, Mode);
โดยมีรูปแบบ การตรวจจับการ Interrupt 5 Mode
LOW : เกิดเมื่อสัญญาณขา Interrupt เป็น Low
HIGH : เกิดเมื่อสัญญาณขา Interrupt เป็น High
CHANGE : เกิดเมื่อสัญญาณขา Interrupt มีการเปลี่ยนแปลงค่าแรงดัน เช่น เปลี่ยนจาก 0 เป็น 3.3V หรือจาก 3.3 เป็น 0V
FALLING : เกิดเมื่อสัญญาณขา Interrupt เปลี่ยนจาก High เป็น Lowfrom HIGH to LOW.
RISING : เกิดเมื่อสัญญาณขา Interrupt เปลี่ยนจาก Low เป็น High
จากวงจรต่อ กับ ขา GPIO16
//bosblog.cz
const int m_time = 5; //Meassure time in Seconds
int wind_ct = 0;
float wind = 0.0;
unsigned long ttime = 0;
void setup()
{
Serial.begin(9600);
ttime = millis();
}
void loop()
{
meassure();
Serial.print(“ความเร็วลม: “);
Serial.print(wind); //Speed in Km/h
Serial.print(” km/h – “);
Serial.print(wind / 3.6); //Speed in m/s
Serial.println(” m/s”);
}
void countWind() {
wind_ct ++;
}
void meassure() {
wind_ct = 0;
ttime = millis();
attachInterrupt(16, countWind, RISING);
delay(1000 * m_time);
detachInterrupt(1);
wind = (float)wind_ct / (float)m_time * 2.4;
}
credit:http://www.bosblog.cz/93-2/
Fritzing 0.94
/in Arduino /by อ.เอ้ดfritzing 0.93b
https://fritzing.org/media/downloads/fritzing.0.9.3b.64.pc.zip
fritzing 0.94
https://fritzing.org/media/downloads/fritzing.0.9.4.64.pc.zip
esp32 esp8266 Arduino IDE
/in Arduino /by อ.เอ้ดArduino IDE
File> Preferences
เลือก Additional Board Manager URLs
https://dl.espressif.com/dl/package_esp32_index.json, http://arduino.esp8266.com/stable/package_esp8266com_index.json
Tools > Board > Boards Manager
Tools > Board > Boards Manager…
กดหา ESP32 เลือก
ESP32 by Espressif Systems
กด ติดตั้ง
ที่มา:https://randomnerdtutorials.com/installing-the-esp32-board-in-arduino-ide-windows-instructions/
Arduino Nano +DHT22
/in Arduino /by อ.เอ้ด#include “DHT.h”
#define DHTPIN 2 // what pin we’re connected to
#define DHTTYPE DHT22 // DHT 22 (AM2302)
DHT dht(DHTPIN, DHTTYPE, 6);
void setup() {
Serial.begin(9600);
Serial.println(“DHTxx test!”);
dht.begin();
}
void loop() {
// Wait a few seconds between measurements.
delay(2000);
// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds ‘old’ (its a very slow sensor)
float h = dht.readHumidity();
// Read temperature as Celsius
float t = dht.readTemperature();
// Read temperature as Fahrenheit
float f = dht.readTemperature(true);
// Check if any reads failed and exit early (to try again).
if (isnan(h) || isnan(t) || isnan(f)) {
Serial.println(“Failed to read from DHT sensor!”);
return;
}
// Compute heat index
// Must send in temp in Fahrenheit!
float hi = dht.computeHeatIndex(f, h);
Serial.print(“Humidity: “);
Serial.print(h);
Serial.print(” %\t”);
Serial.print(“Temperature: “);
Serial.print(t);
Serial.print(” *C “);
Serial.print(f);
Serial.print(” *F\t”);
Serial.print(“Heat index: “);
Serial.print(hi);
Serial.println(” *F”);
}
output
DHTxx test!
Humidity: 93.10 % Temperature: 29.90 *C 85.82 *F Heat index: 106.62 *F
Humidity: 93.20 % Temperature: 29.90 *C 85.82 *F Heat index: 106.68 *F
Humidity: 93.30 % Temperature: 29.90 *C 85.82 *F Heat index: 106.74 *F
Humidity: 93.30 % Temperature: 29.90 *C 85.82 *F Heat index: 106.74 *F
Humidity: 93.20 % Temperature: 29.90 *C 85.82 *F Heat index: 106.68 *F
remark ตัว DHT22 ที่ทดสอบ ไม่ค่อยดีนัก
credit:http://arduino-er.blogspot.com/2015/05/arduino-nano-dht11-temperature-humidity.html
nodmcu V3 (Lolin) DHT11 with DeepSleep
/in Arduino /by อ.เอ้ดการหลับ Deepsleep จะเป็นหน่วย microsecond
#include <ESP8266WiFi.h>
#include “DHT.h”
//deep sleep wire GPIO16 (D0) to RST Pin
#define DHTPIN D4 // ขา Out ของ Sensor ต่อเข้าขา D4 ของ Esp8266
#define DHTTYPE DHT11 // DHT 22 (AM2302), AM2321
DHT dht(DHTPIN, DHTTYPE);
void setup()
{
dht.begin();
Serial.begin(9600);
Serial.println(“Humidity and temperature\n\n”);
delay(700);
}
void loop()
{
float h = dht.readHumidity();
float t = dht.readTemperature();
Serial.print(“Current humidity = “);
Serial.print(h);
Serial.print(“% “);
Serial.print(“temperature = “);
Serial.print(t);
Serial.println(“C “);
//ESP.deepSleep(30e6); // Deep sleep mode for 30 seconds
//ESP.deepSleep(60e6); // Deep sleep mode for 60 seconds
ESP.deepSleep(300e6); // Deep sleep mode for (~5 min) 300 seconds
delay(800);
}
credit:https://roboindia.com/tutorials/DHT11-NodeMCU-arduino
nodmcu V3 (Lolin) DHT11 #1
/in Arduino /by อ.เอ้ด#include “DHT.h”
#define DHTPIN D4 // ขา Out ของ Sensor ต่อเข้าขา D4 ของ Esp8266
#define DHTTYPE DHT11 // DHT 22 (AM2302), AM2321
DHT dht(DHTPIN, DHTTYPE);
void setup()
{
dht.begin();
Serial.begin(9600);
Serial.println(“Humidity and temperature\n\n”);
delay(700);
}
void loop()
{
float h = dht.readHumidity();
float t = dht.readTemperature();
Serial.print(“Current humidity = “);
Serial.print(h);
Serial.print(“% “);
Serial.print(“temperature = “);
Serial.print(t);
Serial.println(“C “);
delay(800);
}
credit:https://roboindia.com/tutorials/DHT11-NodeMCU-arduino
Interesting links
Here are some interesting links for you! Enjoy your stay :)Categories
Archive
- January 2024
- September 2023
- August 2023
- June 2023
- May 2023
- January 2023
- December 2022
- September 2022
- July 2022
- June 2022
- May 2022
- April 2022
- March 2022
- February 2022
- January 2022
- December 2021
- November 2021
- October 2021
- August 2021
- July 2021
- June 2021
- May 2021
- March 2021
- February 2021
- January 2021
- December 2020
- November 2020
- October 2020
- September 2020
- August 2020
- July 2020
- June 2020
- May 2020
- April 2020
- March 2020
- January 2020
- December 2019
- November 2019
- October 2019
- September 2019
- July 2019
- June 2019
- September 2018
- August 2018
- March 2018
- February 2018
- January 2018
- December 2017
- November 2017
- September 2017
- August 2017
- July 2017
- May 2017
- April 2017
- March 2017
- February 2017
- January 2017
- November 2016
- October 2016
- September 2016
- August 2016
- July 2016
- June 2016
- March 2016
- October 2015
- September 2015
- August 2015
- March 2015
- March 2014
- October 2011