วันพฤหัสบดีที่ 21 ธันวาคม พ.ศ. 2560

DHT11+LCD+Arduino UNO



Link for download LCD library https://www.dropbox.com/s/1aahz8f5pn5...




Code


#include "DHT.h"

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// Set the LCD address to 0x27 for a 16 chars and 2 line display
LiquidCrystal_I2C lcd(0x27, 16, 2);

DHT dht;

void setup()
{
  Serial.begin(9600);
  Serial.println();
  Serial.println("Status\tHumidity (%)\tTemperature (C)\t(F)");

  dht.setup(2); // data pin 2

  // initialize the LCD
  lcd.init();
  lcd.backlight();
  lcd.print("Sensor Family");
        lcd.setCursor(0, 1);
        lcd.print("A-Arduino Thailand");
}

void loop()
{
  delay(dht.getMinimumSamplingPeriod());

  float humidity = dht.getHumidity();
  float temperature = dht.getTemperature();

  Serial.print(dht.getStatusString());
  Serial.print("\t");
  Serial.print(humidity, 1);
  Serial.print("\t\t");
  Serial.print(temperature, 1);
  Serial.print("\t\t");
  Serial.println(dht.toFahrenheit(temperature), 1);

  delay(1000);


  // initialize the LCD
  lcd.init();
  lcd.backlight();
  lcd.setCursor(0,0);
  lcd.print("Humi");
  lcd.setCursor(8,0);
  lcd.print(humidity);

  lcd.setCursor(0,1);
  lcd.print("Temp");
  lcd.setCursor(8,1);
  lcd.print(temperature);
}

วันจันทร์ที่ 20 พฤศจิกายน พ.ศ. 2560

ESP8266 V2+Blynk on/off Switch everywhere in the world via Wifi


Please learn previous VDO










Load Blynk install to mobile phone 

http://www.blynk.cc/


Procedure

Use arduino UNO for upload program to ESP8266 only will disconnect after finish.

1. Hook up wiring 

Upload

ESP8266    to    Arduino UNO

RX             >>              Pin0 
TX             >>              Pin1
CH-PD      >>              3.3 V !!!
VCC          >>              3.3 V !!!
GPIO0       >>              GND
GND          >>              GND



2. Connect relay board and run

Open GPIO 0









3.Code



/*************************************************************
  Download latest Blynk library here:
    https://github.com/blynkkk/blynk-library/releases/latest

  Blynk is a platform with iOS and Android apps to control
  Arduino, Raspberry Pi and the likes over the Internet.
  You can easily build graphic interfaces for all your
  projects by simply dragging and dropping widgets.

    Downloads, docs, tutorials: http://www.blynk.cc
    Sketch generator:           http://examples.blynk.cc
    Blynk community:            http://community.blynk.cc
    Follow us:                  http://www.fb.com/blynkapp
                                http://twitter.com/blynk_app

  Blynk library is licensed under MIT license
  This example code is in public domain.

 *************************************************************
  This example runs directly on ESP8266 chip.

  Note: This requires ESP8266 support package:
    https://github.com/esp8266/Arduino

  Please be sure to select the right ESP8266 module
  in the Tools -> Board menu!

  Change WiFi ssid, pass, and Blynk auth token to run :)
  Feel free to apply it to any other example. It's simple!
 *************************************************************/

/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial


#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "YourAuthToken";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "YourNetworkName";
char pass[] = "YourPassword";

void setup()
{
  // Debug console
  Serial.begin(9600);

  Blynk.begin(auth, ssid, pass);
}

void loop()
{
  Blynk.run();

}











วันพุธที่ 15 พฤศจิกายน พ.ศ. 2560

ESP8266 V1 Web control on/off by IP address

Hardware


Arduino UNO what ever board you have


ESP8266 V1




and jumper wiring



Wiring



Procedure

Use arduino UNO for upload program to ESP8266 only will disconnect after finish.

1. Hook up wiring 

Upload

ESP8266    to    Arduino UNO

RX             >>              Pin0 
TX             >>              Pin1
CH-PD      >>              3.3 V !!!
VCC          >>              3.3 V !!!
GPIO0       >>              GND
GND          >>              GND

2.Use example file from IDE

File >> ESP8266wifi>> WifiWebserver
or copy here#

3. Run

RX             >>              Pin0 
TX             >>              Pin1
CH-PD      >>              3.3 V !!!
VCC          >>              3.3 V !!!
GPIO2       >>              + LED 
-LED         >>              GND
GND          >>              GND





/*
 *  This sketch demonstrates how to set up a simple HTTP-like server.
 *  The server will set a GPIO pin depending on the request
 *    http://server_ip/gpio/0 will set the GPIO2 low,
 *    http://server_ip/gpio/1 will set the GPIO2 high
 *  server_ip is the IP address of the ESP8266 module, will be 
 *  printed to Serial when the module is connected.
 */

#include <ESP8266WiFi.h>

const char* ssid = "your-ssid";
const char* password = "your-password";

// Create an instance of the server
// specify the port to listen on as an argument
WiFiServer server(80);

void setup() {
  Serial.begin(115200);
  delay(10);

  // prepare GPIO2
  pinMode(2, OUTPUT);
  digitalWrite(2, 0);
  
  // Connect to WiFi network
  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);
  
  WiFi.begin(ssid, password);
  
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");
  
  // Start the server
  server.begin();
  Serial.println("Server started");

  // Print the IP address
  Serial.println(WiFi.localIP());
}

void loop() {
  // Check if a client has connected
  WiFiClient client = server.available();
  if (!client) {
    return;
  }
  
  // Wait until the client sends some data
  Serial.println("new client");
  while(!client.available()){
    delay(1);
  }
  
  // Read the first line of the request
  String req = client.readStringUntil('\r');
  Serial.println(req);
  client.flush();
  
  // Match the request
  int val;
  if (req.indexOf("/gpio/0") != -1)
    val = 0;
  else if (req.indexOf("/gpio/1") != -1)
    val = 1;
  else {
    Serial.println("invalid request");
    client.stop();
    return;
  }

  // Set GPIO2 according to the request
  digitalWrite(2, val);
  
  client.flush();

  // Prepare the response
  String s = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n<!DOCTYPE HTML>\r\n<html>\r\nGPIO is now ";
  s += (val)?"high":"low";
  s += "</html>\n";

  // Send the response to the client
  client.print(s);
  delay(1);
  Serial.println("Client disonnected");

  // The client will actually be disconnected 
  // when the function returns and 'client' object is detroyed
}





















วันอาทิตย์ที่ 15 ตุลาคม พ.ศ. 2560

Robot TANK + ESP8266 mission record humidity and temp




L298 Motor drive bord.

Code for control motor.



#include<SoftwareSerial.h>

char receivedChar;

int ENA=2;
int IN1=3;
int IN2=4;
int IN3=5;
int IN4=6;
int ENB=7;

int ENA1=A0;
int IN11=A1;
int IN12=A2;
int IN13=A3;
int IN14=A4;
int ENB1=A5;


SoftwareSerial mySerial(10, 11); // RX, TX



//RX on Bluetooth to TCX on Arduino through a voltage divider 50ohm from arduino and 100ohm to ground. This is so we can drop the the voltage down to 3.3v (roughly)

// Use blueterm on android to get messages



void setup()



 pinMode(ENA,OUTPUT);//output
 pinMode(ENB,OUTPUT);
 pinMode(IN1,OUTPUT);
 pinMode(IN2,OUTPUT);
 pinMode(IN3,OUTPUT);
 pinMode(IN4,OUTPUT);

 pinMode(ENA1,OUTPUT);//output
 pinMode(ENB1,OUTPUT);
 pinMode(IN11,OUTPUT);
 pinMode(IN12,OUTPUT);
 pinMode(IN13,OUTPUT);
 pinMode(IN14,OUTPUT);
  
  mySerial.begin(9600); 
}



void loop() // run over and over



{

  


  while (!mySerial.available());   // stay here so long as COM port is empty

  receivedChar = mySerial.read();

  if (receivedChar == 'A') {

    Serial.print(receivedChar);

            //digitalWrite(ENA,LOW);
            // digitalWrite(ENB,LOW);// High is start driving car
              
             digitalWrite(ENA,HIGH);
             digitalWrite(ENB,HIGH);// High is start driving car
  
             digitalWrite(IN1,HIGH); 
             digitalWrite(IN2,LOW);//setting motorA's directon
             digitalWrite(IN3,LOW);
             digitalWrite(IN4,HIGH);//setting motorB's directon
  }
              
  if (receivedChar == 'B') {

             // digitalWrite(ENA,LOW); Backward
             // digitalWrite(ENB,LOW);// High is start driving car
              
              
                    
             digitalWrite(ENA,HIGH);
             digitalWrite(ENB,HIGH);// High is start driving car
  
             digitalWrite(IN1,LOW); 
             digitalWrite(IN2,HIGH);//setting motorA's directon
             digitalWrite(IN3,HIGH);
             digitalWrite(IN4,LOW);//setting motorB's directon

                         
  }      
  if (receivedChar == 'C') 
  
              {

             // digitalWrite(ENA,LOW);Left
             // digitalWrite(ENB,LOW);// High is start driving car
  
             digitalWrite(ENA,HIGH);
             digitalWrite(ENB,HIGH);// High is start driving car
  
             digitalWrite(IN1,HIGH); 
             digitalWrite(IN2,LOW);//setting motorA's directon
             digitalWrite(IN3,HIGH);
             digitalWrite(IN4,LOW);//setting motorB's directon

             

  } // if it is a 3 flash the LED

  if (receivedChar == 'D') {
  
              //digitalWrite(ENA,LOW);
              //digitalWrite(ENB,LOW);// High is start driving car
              
                          
             digitalWrite(ENA,HIGH);
             digitalWrite(ENB,HIGH);// High is start driving car
  
             digitalWrite(IN1,LOW); 
             digitalWrite(IN2,HIGH);//setting motorA's directon
             digitalWrite(IN3,LOW);
             digitalWrite(IN4,HIGH);//setting motorB's directon


  } // if it is a 4 print out lots of sensor data


  if (receivedChar == 'E') {
  
             digitalWrite(ENA,HIGH);
             digitalWrite(ENB,HIGH);// High is start driving car
  
             digitalWrite(IN1,LOW); 
             digitalWrite(IN2,LOW);//setting motorA's directon
             digitalWrite(IN3,LOW);
             digitalWrite(IN4,LOW);//setting motorB's directon
  
  }
  
}


How to make mobile app control 





ESP 8266 To Think speak





     Code

//ตัวนี้ใช้ได้ดีมาก
#include <SoftwareSerial.h>
#include <stdlib.h>
#include "DHT.h"

DHT dht;


int sensor1State=0;
int sensor2State=0;
//int sensor3State=0;
//int sensor4State=0;


// replace with your channel's thingspeak API key
String apiKey = "Your API from web ";

// connect 10 to TX of ESP8266
// connect 11 to RX of ESP8266
SoftwareSerial ser(10, 11); // RX, TX

int i=1;



void setup() {  

// DHT

dht.setup(2); // data pin 2

                  
  
  Serial.begin(9600); 
  
  ser.begin(9600);
  
  // reset ESP8266
  ser.println("AT+RST");
}


// the loop 
void loop() {


  delay(dht.getMinimumSamplingPeriod());

float humidity = dht.getHumidity(); // ดึงค่าความชื้น
float temperature = dht.getTemperature(); // ดึงค่าอุณหภูมิ

Serial.print(dht.getStatusString());
Serial.print("\t");
Serial.print(humidity, 1);
Serial.print("\t\t");
Serial.print(temperature, 1);
Serial.print("\t\t");
Serial.println(dht.toFahrenheit(temperature), 1);

  sensor1State = humidity ;//digitalRead(sensor1);
  sensor2State = temperature; //digitalRead(sensor2);


  String state1=String(sensor1State);
  
  
  String state2=String(sensor2State);
  
  

  // server connect
  String cmd = "AT+CIPSTART=\"TCP\",\"";
  cmd += "184.106.153.149"; // api.thingspeak.com
  cmd += "\",80";
  ser.println(cmd);
  Serial.println(cmd);
   
 if(ser.find("Error")){
Serial.println("AT+CIPSTART error");
return;
  }
  
  // prepare GET string
  String getStr = "GET /update?api_key=";
  getStr += apiKey; 
  getStr +="&field1=";
  getStr += String(state1);
  getStr +="&field2=";
  getStr += String(state2);

  getStr += "\r\n\r\n";

  // send data length
  cmd = "AT+CIPSEND=";
  cmd += String(getStr.length());
  ser.println(cmd);
  Serial.println(cmd);

  if(ser.find(">")){
    ser.print(getStr);
    Serial.print(getStr);
  }
  else{
    ser.println("AT+CIPCLOSE");
    // alert user
    Serial.println("AT+CIPCLOSE");
  }
    
  // thingspeak needs 15 sec delay between updates
  delay(16000);  
}

วันเสาร์ที่ 7 ตุลาคม พ.ศ. 2560

HOW to Check ESP8266 connected with Arduino





1.Specification


Specification

  • Module power 3.3V, regular current consumption at 70ma, peak current at 240mA (300mA must be able to provided)
  • +20Dbm power, 100M max transmitting distance on ideal circumstance.
  • It is common and correct to see some random error data when module is power up, and end up with "ready" (Turn baud rate to 115200 can see this actual debug data, this is used for firmware updating)

IC Features

  • 802.11 b / g / n
  • WIFI @ 2.4 GHz, supports WPA / WPA2 security mode
  • Ultra-small size module 11.5mm * 11.5mm
  • Built-in 10 bit precision ADC
  • Built-in TCP / IP protocol stack
  • Built-in TR switch, balun, LNA, power amplifier and matching network
  • Built-in PLL, voltage regulator and power management components
  • 802.11b mode + 19.5dBm output power
  • Supports antenna diversity
  • Off leakage current is less than 10uA
  • Built-in low-power 32-bit CPU: can double as an application processor
  • SDIO 2.0, SPI, UART
  • STBC, 1x1 MIMO, 2x1 MIMO
  • The guard interval A-MPDU, the polymerization of the A-MSDU and 0.4 s of
  • Within 2ms of the wake, connect and transfer data packets
  • Standby power consumption is less than 1.0mW (DTIM3)
  • Operating temperature range -40 ~ 125 ℃

2. Connection 




3. Connect

ESP8266    to   Arduino

TX             to   PIN1
RX             to   PIN0
CH_PD      to   3.3 Vcc
Vcc            to   3.3 vcc
GND          to   GND







VDO 













4.  Test  Arduino  Board

load simple blinking led pin 13 make sure board connected



code

void setup() {

  // initialize digital pin 13 as an output.

  pinMode(13, OUTPUT);

}

// the loop function runs over and over again forever

void loop() {

  digitalWrite(13, HIGH);   // turn the LED on (HIGH is the voltage level)

  delay(1000);              // wait for a second

  digitalWrite(13, LOW);    // turn the LED off by making the voltage LOW

  delay(1000);              // wait for a second



}


5. serial monitor check AT Command

load AT Command Here : 

https://www.dropbox.com/s/iyuybn7bg9nw0vg/4a-esp8266_at_instruction_set_en_%281%29.pdf?dl=0


5.1  AT

Should get OK

5.2 AT+GMR

version


5.3 AT+CWMODE?

Mode will show 1,2 or 3

5.4 AT+CWLAP

Will show Access point around


5.5 AT+CWJAP="User","Password"

connect Access point

5.6 AT+CIFSR

Get IP

All OK mean connected.






วันพฤหัสบดีที่ 5 ตุลาคม พ.ศ. 2560

IOT ESP8266 send Temperature and Humidity to web server Thingspeak. โชว์ค่าการวัดจากเซนเซอร์แสดงค่าปัจจุบันดูได้ทุกที่














Specification

  • Module power 3.3V, regular current consumption at 70ma, peak current at 240mA (300mA must be able to provided)
  • +20Dbm power, 100M max transmitting distance on ideal circumstance.
  • It is common and correct to see some random error data when module is power up, and end up with "ready" (Turn baud rate to 115200 can see this actual debug data, this is used for firmware updating)

IC Features

  • 802.11 b / g / n
  • WIFI @ 2.4 GHz, supports WPA / WPA2 security mode
  • Ultra-small size module 11.5mm * 11.5mm
  • Built-in 10 bit precision ADC
  • Built-in TCP / IP protocol stack
  • Built-in TR switch, balun, LNA, power amplifier and matching network
  • Built-in PLL, voltage regulator and power management components
  • 802.11b mode + 19.5dBm output power
  • Supports antenna diversity
  • Off leakage current is less than 10uA
  • Built-in low-power 32-bit CPU: can double as an application processor
  • SDIO 2.0, SPI, UART
  • STBC, 1x1 MIMO, 2x1 MIMO
  • The guard interval A-MPDU, the polymerization of the A-MSDU and 0.4 s of
  • Within 2ms of the wake, connect and transfer data packets
  • Standby power consumption is less than 1.0mW (DTIM3)
  • Operating temperature range -40 ~ 125 ℃

Wiring






ESP8266 >>> Arduino
TX>>> Pin10
RX>>> Pin11
Vcc>>> 3.3 Vcc
GND >>> GND
CH_PD>>> 3.3Vcc





VDO









Library

DHT11 :



AT Command for ESP8266




Code


//ตัวนี้ใช้ได้ดีมาก
#include <SoftwareSerial.h>
#include <stdlib.h>
#include "DHT.h"

DHT dht;


int sensor1State=0;
int sensor2State=0;
//int sensor3State=0;
//int sensor4State=0;


// replace with your channel's thingspeak API key
String apiKey = "LE3COBJ28VTF50KL";

// connect 10 to TX of ESP8266
// connect 11 to RX of ESP8266
SoftwareSerial ser(10, 11); // RX, TX

int i=1;



void setup() {  

// DHT

dht.setup(2); // data pin 2

                  
  
  Serial.begin(9600); 
  
  ser.begin(9600);
  
  // reset ESP8266
  ser.println("AT+RST");
}


// the loop 
void loop() {


  delay(dht.getMinimumSamplingPeriod());

float humidity = dht.getHumidity(); // ดึงค่าความชื้น
float temperature = dht.getTemperature(); // ดึงค่าอุณหภูมิ

Serial.print(dht.getStatusString());
Serial.print("\t");
Serial.print(humidity, 1);
Serial.print("\t\t");
Serial.print(temperature, 1);
Serial.print("\t\t");
Serial.println(dht.toFahrenheit(temperature), 1);

  sensor1State = humidity ;//digitalRead(sensor1);
  sensor2State = temperature; //digitalRead(sensor2);


  String state1=String(sensor1State);
  
  
  String state2=String(sensor2State);
  
  

  // server connect
  String cmd = "AT+CIPSTART=\"TCP\",\"";
  cmd += "184.106.153.149"; // api.thingspeak.com
  cmd += "\",80";
  ser.println(cmd);
  Serial.println(cmd);
   
  if(ser.find("Error")){
    Serial.println("AT+CIPSTART error");
    return;
  }
  
  // prepare GET string
  String getStr = "GET /update?api_key=";
  getStr += apiKey;

  getStr +="&field1=";
  getStr += String(state1);
  getStr +="&field2=";
  getStr += String(state2);

  getStr += "\r\n\r\n";

  // send data length
  cmd = "AT+CIPSEND=";
  cmd += String(getStr.length());
  ser.println(cmd);
  Serial.println(cmd);

  if(ser.find(">")){
    ser.print(getStr);
    Serial.print(getStr);
  }
  else{
    ser.println("AT+CIPCLOSE");
    // alert user
    Serial.println("AT+CIPCLOSE");
  }
    
  // thingspeak needs 15 sec delay between updates
  delay(16000);  
}