วันอาทิตย์ที่ 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);  
}