IOT control temp and PM 2.5 using ESP8266 Node MCU + water spray system

 

This project add soil sensor for measure wet in soil then program control solenoid feed water valve through nozzle splash foggy water to plant and cool ambien temperature down and same time water misc with reduce PM 2.5 dust in the same time.

 

Add  Blynk application follow this

 

 

 

Add Relay and Soi sensor

Sensor

เครื่องวัดความหนาแน่นของความชื้นความชื้นความชื้น เซนเซอร์ สำหรับ Arduino

https://sea.banggood.com/custlink/GmGvctPJ9N

โมดูลรีเลย์ 12V 2 ช่องพร้อมการสนับสนุน Optocoupler การเรียกระดับต่ำสำหรับ Arduino

https://sea.banggood.com/custlink/3K3mWP5cFy

 

Soi connect to  D2

Relay IN1 >>> D0
IN2>>>  D1

 

 

VDO How to make

 

CODE

#include <Adafruit_Sensor.h>

/*************************************************************
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


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

*************************************************************
qwert7yip0[p=]\
This example shows how value can be pushed from Arduino to
the Blynk App.

WARNING :
For this example you'll need Adafruit DHT sensor libraries:
https://github.com/adafruit/Adafruit_Sensor
https://github.com/adafruit/DHT-sensor-library

App project setup:
Value Display widget attached to V5
Value Display widget attached to V6
*************************************************************/

// www.a-arduino.com

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


#include <SPI.h>

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

#include <DHT.h>


//////////oled display

#include <Wire.h> // Only needed for Arduino 1.6.5 and earlier
#include "SSD1306.h" // alias for `#include "SSD1306Wire.h"`

//////////////


// TimeClient settings


/*Dust sensor

*/
int measurePin = A0;
int ledPower = D6;

const int soi = D2;
const int waterfeed = D0;
const int foggy = D1;

int soiState = 0;

unsigned int samplingTime = 280;
unsigned int deltaTime = 40;
unsigned int sleepTime = 9680;

float voMeasured = 0;
float calcVoltage = 0;
float dustDensity = 0;

SSD1306 display(0x3c, D3, D4);

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

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

#define DHTPIN D5 // What digital pin we're connected to GPIO14

// Uncomment whatever type you're using!
#define DHTTYPE DHT11 // DHT 11
//#define DHTTYPE DHT22 // DHT 22, AM2302, AM2321
//#define DHTTYPE DHT21 // DHT 21, AM2301

DHT dht(DHTPIN, DHTTYPE);
BlynkTimer timer;

// This function sends Arduino's up time every second to Virtual Pin (5).
// In the app, Widget's reading frequency should be set to PUSH. This means
// that you define how often to send data to Blynk App.
void sendSensor()
{
float h = dht.readHumidity();
float t = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit

if (isnan(h) || isnan(t)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
// You can send any value at any time.
// Please don't send more that 10 values per second.
Blynk.virtualWrite(V5, h);
Blynk.virtualWrite(V6, t);

/******************
* Dust
*****************/
digitalWrite(ledPower,LOW);
delayMicroseconds(samplingTime);

voMeasured = analogRead(measurePin);

delayMicroseconds(deltaTime);
digitalWrite(ledPower,HIGH);
delayMicroseconds(sleepTime);

calcVoltage = voMeasured*(3.0/1024);
dustDensity = 0.17*calcVoltage-0.1;

if ( dustDensity < 0)
{
dustDensity = 0.00;
}


Serial.println("temp:");
Serial.println(t);

Serial.println("Humi:");
Serial.println(h);

Serial.println("Raw Signal Value (0-1023):");
Serial.println(voMeasured);

Serial.println("Voltage:");
Serial.println(calcVoltage);

dustDensity = dustDensity*1000 ;

Serial.println("Dust Density micro gram/m^3:");
Serial.println(dustDensity);


Blynk.virtualWrite(V7,dustDensity);

///////////////////////////////

display.clear();
display.drawString(0, 16, String(t)+"C\t" + String(h) + "%\t"); 

display.drawString(0, 32, "Dust: " + String(dustDensity) + "ug/m^3"); 
delay(1000);
soiState = digitalRead(soi);
Serial.print(soiState);

if (soiState == HIGH) //D2
{
digitalWrite(waterfeed,LOW); // D0

WidgetLED led1(V10);
led1.on();
display.clear();
//display.drawString(0, 16, String(t)+"C\t" + String(h) + "%\t"); 
//display.drawString(0, 32, "Dust: " + String(dustDensity) + "ug/m^3"); 
display.drawString(0, 32, "FEED WATER"); 

delay(1000);

}
else{
digitalWrite(waterfeed,HIGH); // D0
WidgetLED led1(V10);
led1.off();
}

if ( t >= 36 )
{
digitalWrite(foggy,LOW); //D1

delay(2000);

digitalWrite(foggy,HIGH); //D1

}
else if( t<36 )
{
digitalWrite(foggy,HIGH); //D1
}

}

BLYNK_WRITE(V8)

{

int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
// You can also use:
// String i = param.asStr();
// double d = param.asDouble();

Serial.println(pinValue);
if(pinValue == 1)
{
digitalWrite(waterfeed,LOW);

}
else
{ 
digitalWrite(waterfeed,HIGH);
}

}


BLYNK_WRITE(V9)

{

int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
// You can also use:
// String i = param.asStr();
// double d = param.asDouble();
Serial.print("Forward value is: ");
Serial.println(pinValue);
if(pinValue == 1)
{
digitalWrite(foggy,LOW);

}
else
{ 
digitalWrite(foggy,HIGH);
}

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

Blynk.begin(auth, ssid, pass);
// You can also specify server:
//Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 8442);
//Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8442);

dht.begin();

// Setup a function to be called every second
timer.setInterval(1000L, sendSensor);


pinMode(ledPower,OUTPUT);

pinMode(soi,INPUT);
pinMode(waterfeed,OUTPUT);
pinMode(foggy,OUTPUT);

digitalWrite(waterfeed,HIGH);
digitalWrite(foggy,HIGH);
///////////////

display.init();

display.flipScreenVertically();
display.setFont(ArialMT_Plain_16);
display.setTextAlignment(TEXT_ALIGN_LEFT);
dht.begin(); // initialize dht
}

void loop()
{
Blynk.run();
timer.run();
display.display();
}


NRF24L01 Wireless make flight controller

 

https://www.banggood.com/custlink/vKG3CE240H

1100 Meter Long Distance NRF24L01+PA+LNA Wireless Module With Antenna

Features:

NRF24L01P + PA + LNA Division for the ultra-long-distance data transmission, specially developed high-power and high sensitivity wireless module 2.4G ISM band NRF24L01P + PA + LNA wireless module to work in the license-free that can be point-to-point applications or be composed of a star network.
Digital transmission chip NRF24L01+ with the Division of Professional Design professional full two-way RF power amplifier high power PA and LNA chip, RF switches and band pass filters, makes effective communication distance greatly expand.
RF part, it has been done a lot of optimization matching debugging. The emission efficiency to achieve the highest harmonic minimum and make NRF24L01P + PA + LNA wireless module of RF interference to the external equipment reaches minimum, while not susceptible to interference from other devices.

NRF24L01P + PA + LNA wireless module integration is extremely high, the size is 41mm x 15.5mm to make conveniently embedded.

Description:
Voltage: 3-3.6V
Max output power: +20 dBm
Working current in transmit mode: 115mA
Working current in receiver mode: 45mA
Current in    mode: 4.2uA
Operating temperature: -20-70 degree
Receiver sensitivity: -92dBm in 2Mbps mode, -95dBm in 1Mbps mode, -104dBm in 250kbps mode
PA growth: 20dB
LAN growth: 10dB
LAN noise figure: 2.6dB
Antenna growth: 2dBI
2M rate: 520m

 

1100 Meter Long Distance NRF24L01+PA+LNA Wireless Module With Antenna

,

 

NRF24L01 -> Arduino

  • Vcc -> 3.3V   (5 V will kill immediately !!!)
  • Gnd -> Gnd
  • CSN -> 10
  • CE -> 8
  • MOSI -> 11
  • SCK -> 13
  • MISO -> 12

 

Plane receive all wiring

Part receive schematic

 

 

Motor drive

Q1,Q2, Transistor use NPN BD139  can take 3 amp but as I mention the surface mounting type would be better

 

Remote control side

 

 

CODE

Library need for this project

RHReliableDatagram : https://goo.gl/UJbziK

Remote  TX

 

// Include RadioHead ReliableDatagram & NRF24 Libraries
#include <RHReliableDatagram.h>
#include <RH_NRF24.h>

// Include dependant SPI Library 
#include <SPI.h>

// Define Joystick Connections
#define joyVert A0 
#define joyHorz A2

// Define Joystick Values - Start at 512 (middle position)
int joyposVert = 512;
int joyposHorz = 512;

// Define addresses for radio channels
#define CLIENT_ADDRESS 1 
#define SERVER_ADDRESS 2

// Create an instance of the radio driver
RH_NRF24 RadioDriver;

// Sets the radio driver to NRF24 and the client address to 1
RHReliableDatagram RadioManager(RadioDriver, CLIENT_ADDRESS);

// Declare unsigned 8-bit motorcontrol array
// 2 Bytes for motor speeds plus 1 byte for direction control
uint8_t motorcontrol[3]; 

// Define the Message Buffer
uint8_t buf[RH_NRF24_MAX_MESSAGE_LEN];

void setup()
{
// Setup Serial Monitor
Serial.begin(9600);

// Initialize RadioManager with defaults - 2.402 GHz (channel 2), 2Mbps, 0dBm
if (!RadioManager.init())
Serial.println("init failed");

// Set initial motor direction as forward
motorcontrol[2] = 0;

}

void loop()
{
// Print to Serial Monitor
Serial.println("Reading motorcontrol values ");

// Read the Joystick X and Y positions
joyposVert = analogRead(joyVert); 
joyposHorz = analogRead(joyHorz);

// Determine if this is a forward or backward motion
// Do this by reading the Verticle Value
// Apply results to MotorSpeed and to Direction

if (joyposVert < 0)
{
// This is Backward
// Set Motors backward
motorcontrol[2] = 1;

//Determine Motor Speeds
// As we are going backwards we need to reverse readings
motorcontrol[0] = map(joyposVert, 0, 1023, 0, 255);
motorcontrol[1] = map(joyposVert, 0, 1023, 0, 255);

}
else if (joyposVert > 1)
{
// This is Forward
// Set Motors forward
motorcontrol[2] = 0;

//Determine Motor Speeds
motorcontrol[0] = map(joyposVert, 0, 1023, 0, 255);
motorcontrol[1] = map(joyposVert, 0, 1023, 0, 255); 

}
else
{
// This is Stopped
motorcontrol[0] = 0;
motorcontrol[1] = 0;
motorcontrol[2] = 0; 

}

// Now do the steering
// The Horizontal position will "weigh" the motor speed
// Values for each motor

if (joyposHorz < 460)
{
// Move Left
// As we are going left we need to reverse readings
// Map the number to a value of 255 maximum
joyposHorz = map(joyposHorz, 460, 0, 0, 255);

motorcontrol[0] = motorcontrol[0] - joyposHorz;
motorcontrol[1] = motorcontrol[1] + joyposHorz;

// Don't exceed range of 0-255 for motor speeds
if (motorcontrol[0] < 0)motorcontrol[0] = 0;
if (motorcontrol[1] > 255)motorcontrol[1] = 255;

}
else if (joyposHorz > 564)
{
// Move Right
// Map the number to a value of 255 maximum
joyposHorz = map(joyposHorz, 564, 1023, 0, 255);

motorcontrol[0] = motorcontrol[0] + joyposHorz;
motorcontrol[1] = motorcontrol[1] - joyposHorz;

// Don't exceed range of 0-255 for motor speeds
if (motorcontrol[0] > 255)motorcontrol[0] = 255;
if (motorcontrol[1] < 0)motorcontrol[1] = 0; 

}

// Adjust to prevent "buzzing" at very low speed
if (motorcontrol[0] < 8)motorcontrol[0] = 0;
if (motorcontrol[1] < 8)motorcontrol[1] = 0;

//Display the Motor Control values in the serial monitor.
Serial.print("Motor A: ");
Serial.print(motorcontrol[0]);
Serial.print(" - Motor B: ");
Serial.print(motorcontrol[1]);
Serial.print(" - Direction: ");
Serial.println(motorcontrol[2]);

//Send a message containing Motor Control data to manager_server
if (RadioManager.sendtoWait(motorcontrol, sizeof(motorcontrol), SERVER_ADDRESS))
{
// Now wait for a reply from the server
uint8_t len = sizeof(buf);
uint8_t from;
if (RadioManager.recvfromAckTimeout(buf, &len, 2000, &from))
{
Serial.print("got reply from : 0x");
Serial.print(from, HEX);
Serial.print(": ");
Serial.println((char*)buf);
}
else
{
Serial.println("No reply, is nrf24_reliable_datagram_server running?");
}
}
else
Serial.println("sendtoWait failed");

delay(100); // Wait a bit before next transmission
}

 

Plane RX

// Include RadioHead ReliableDatagram & NRF24 Libraries
#include <RHReliableDatagram.h>
#include <RH_NRF24.h>

// Include dependant SPI Library 
#include <SPI.h>

// Define addresses for radio channels
#define CLIENT_ADDRESS 1 
#define SERVER_ADDRESS 2

// Motor A Connections
int motorA = 3;


// Motor B Connections
int motorB = 5;


// Create an instance of the radio driver
RH_NRF24 RadioDriver;

// Sets the radio driver to NRF24 and the server address to 2
RHReliableDatagram RadioManager(RadioDriver, SERVER_ADDRESS);

// Define a message to return if values received
uint8_t ReturnMessage[] = "JoyStick Data Received"; 

// Define the Message Buffer
uint8_t buf[RH_NRF24_MAX_MESSAGE_LEN];

void setup()
{
// Setup Serial Monitor
Serial.begin(9600);

// Set all the motor control pins to outputs
pinMode(motorA, OUTPUT);
pinMode(motorB, OUTPUT);


// Initialize RadioManager with defaults - 2.402 GHz (channel 2), 2Mbps, 0dBm
if (!RadioManager.init())
Serial.println("init failed");
} 

void loop()
{
if (RadioManager.available())
{
// Wait for a message addressed to us from the client
uint8_t len = sizeof(buf);
uint8_t from;
if (RadioManager.recvfromAck(buf, &len, &from))

{

//Serial Print the values of joystick
Serial.print("got request from : 0x");
Serial.print(from, HEX);
Serial.print(": MotorA = ");
Serial.print(buf[0]);
Serial.print(" MotorB = ");
Serial.print(buf[1]);
Serial.print(" Dir = ");
Serial.println(buf[2]);




// Drive Motors
analogWrite(motorA, buf[1]);
analogWrite(motorB, buf[0]);

// Send a reply back to the originator client, check for error
if (!RadioManager.sendtoWait(ReturnMessage, sizeof(ReturnMessage), from))
Serial.println("sendtoWait failed");
}
} 
}




Dust + Humidity+temperature control IOT Blynk app + SSD1306 OLED display

Equipment

ESP8266 Node MCU : https://sea.banggood.com/custlink/D3vDysMjrj

OLED Display    : https://sea.banggood.com/custlink/KmDGEQ2O9i

Temperature Humidity  :  https://sea.banggood.com/custlink/3KGGYQzl8A

Dust sensor : https://goo.gl/Bd3Edm

 

Wiring

 

VDO

If my blog help full for all of my friend a cup of coffee for me would be help full for keep this blog online to share good information to community.

 

Code

#include <Adafruit_Sensor.h>

/*************************************************************
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


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

*************************************************************
qwert7yip0[p=]\
This example shows how value can be pushed from Arduino to
the Blynk App.

WARNING :
For this example you'll need Adafruit DHT sensor libraries:
https://github.com/adafruit/Adafruit_Sensor
https://github.com/adafruit/DHT-sensor-library

App project setup:
Value Display widget attached to V5
Value Display widget attached to V6
*************************************************************/

// www.a-arduino.com

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


#include <SPI.h>

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

#include <DHT.h>


//////////oled display

#include <Wire.h> // Only needed for Arduino 1.6.5 and earlier
#include "SSD1306.h" // alias for `#include "SSD1306Wire.h"`

//////////////


// TimeClient settings


/*Dust sensor

*/
int measurePin = A0;
int ledPower = D6;

unsigned int samplingTime = 280;
unsigned int deltaTime = 40;
unsigned int sleepTime = 9680;

float voMeasured = 0;
float calcVoltage = 0;
float dustDensity = 0;

SSD1306 display(0x3c, D3, D4);

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

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

#define DHTPIN D5 // What digital pin we're connected to GPIO14

// Uncomment whatever type you're using!
#define DHTTYPE DHT11 // DHT 11
//#define DHTTYPE DHT22 // DHT 22, AM2302, AM2321
//#define DHTTYPE DHT21 // DHT 21, AM2301

DHT dht(DHTPIN, DHTTYPE);
BlynkTimer timer;

// This function sends Arduino's up time every second to Virtual Pin (5).
// In the app, Widget's reading frequency should be set to PUSH. This means
// that you define how often to send data to Blynk App.
void sendSensor()
{
float h = dht.readHumidity();
float t = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit

if (isnan(h) || isnan(t)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
// You can send any value at any time.
// Please don't send more that 10 values per second.
Blynk.virtualWrite(V5, h);
Blynk.virtualWrite(V6, t);

/******************
* Dust
*****************/
digitalWrite(ledPower,LOW);
delayMicroseconds(samplingTime);

voMeasured = analogRead(measurePin);

delayMicroseconds(deltaTime);
digitalWrite(ledPower,HIGH);
delayMicroseconds(sleepTime);

calcVoltage = voMeasured*(3.0/1024);
dustDensity = 0.17*calcVoltage-0.1;

if ( dustDensity < 0)
{
dustDensity = 0.00;
}

Serial.println("temp:");
Serial.println(t);

Serial.println("Humi:");
Serial.println(h);

Serial.println("Raw Signal Value (0-1023):");
Serial.println(voMeasured);

Serial.println("Voltage:");
Serial.println(calcVoltage);

dustDensity = dustDensity*1000 ;

Serial.println("Dust Density micro gram/m^3:");
Serial.println(dustDensity);


Blynk.virtualWrite(V7,dustDensity);

///////////////////////////////

display.clear();
display.drawString(0, 16, String(t)+"C\t" + String(h) + "%\t"); 
//display.drawString(0, 16, "" + String(t) + "C"); 
display.drawString(0, 32, "Dust: " + String(dustDensity) + "ug/m^3"); 
delay(1000);
}

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

Blynk.begin(auth, ssid, pass);
// You can also specify server:
//Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 8442);
//Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8442);

dht.begin();

// Setup a function to be called every second
timer.setInterval(1000L, sendSensor);


pinMode(ledPower,OUTPUT);


///////////////

display.init();

display.flipScreenVertically();
display.setFont(ArialMT_Plain_16);
display.setTextAlignment(TEXT_ALIGN_LEFT);
dht.begin(); // initialize dht
}

void loop()
{
Blynk.run();
timer.run();
display.display();
}

ESP8266 node MCU + SSD1306 OLED display Build World Clock

 

ESP8266 :       https://usa.banggood.com/custlink/KmmKdHGKTQ

OLED Display : https://usa.banggood.com/custlink/vDmKRFGdvm

 

Wiring

SSD1306 OLED Display >>   ESP8266 Node MCU

I2C protocol

SDA  >>  D3

SCL >> D4

 

Library :

https://drive.google.com/file/d/14Pb_QoJV38tYw_g8n0O–VVPRLLditpZ/view?usp=sharing

 

Add library :

Then select Zip file , Done easy.

 

VDO

Code from File >Example>ESP8266 Weather station > WorldClockDemo

/**The MIT License (MIT)

Copyright (c) 2017 by Daniel Eichhorn

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

See more at https://blog.squix.org
*/

#include <ESP8266WiFi.h>
#include <Ticker.h>
#include <JsonListener.h>
#include "SSD1306Wire.h"
#include "OLEDDisplayUi.h"
#include "Wire.h"
#include "WorldClockClient.h"
#include "icons.h"
#include "fonts.h"

/***************************
* Begin Settings
**************************/
// WIFI
const char* WIFI_SSID = "yourssid";
const char* WIFI_PWD = "yourpassw0rd";

// Setup
const int UPDATE_INTERVAL_SECS = 10 * 60; // Update every 10 minutes

// Display Settings
const int I2C_DISPLAY_ADDRESS = 0x3c;
const int SDA_PIN = D3;
const int SDC_PIN = D4;

// TimeClient settings


// Initialize the oled display for address 0x3c
// sda-pin=14 and sdc-pin=12

SSD1306Wire display(I2C_DISPLAY_ADDRESS, SDA_PIN, SDC_PIN);
OLEDDisplayUi ui ( &display );

/***************************
* End Settings
**************************/
String timeZoneIds [] = {"America/New_York", "Europe/London", "Europe/Paris", "Australia/Sydney"};
WorldClockClient worldClockClient("de", "CH", "E, dd. MMMMM yyyy", 4, timeZoneIds);


// flag changed in the ticker function every 10 minutes
bool readyForUpdate = false;

String lastUpdate = "--";

Ticker ticker;


void updateData(OLEDDisplay *display) {
drawProgress(display, 50, "Updating Time...");
worldClockClient.updateTime();
drawProgress(display, 100, "Done...");
readyForUpdate = false;
delay(1000);
}

void drawProgress(OLEDDisplay *display, int percentage, String label) {
display->clear();
display->setTextAlignment(TEXT_ALIGN_CENTER);
display->setFont(ArialMT_Plain_10);
display->drawString(64, 10, label);
display->drawProgressBar(10, 28, 108, 12, percentage);
display->display();
}

void drawClock(OLEDDisplay *display, int x, int y, int timeZoneIndex, String city, const char* icon) {
display->setTextAlignment(TEXT_ALIGN_LEFT);
display->setFont(ArialMT_Plain_10);
display->drawString(x + 60, y + 5, city);
display->setFont(Crushed_Plain_36);
display->drawXbm(x, y, 60, 60, icon);
display->drawString(x + 60, y + 15, worldClockClient.getHours(timeZoneIndex) + ":" + worldClockClient.getMinutes(timeZoneIndex));

}

void drawFrame1(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y) {
drawClock(display, x, y, 0, "New York", new_york_bits);
}

void drawFrame2(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y) {
drawClock(display, x, y, 1, "London", london_bits);
}

void drawFrame3(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y) {
drawClock(display, x, y, 2, "Paris", paris_bits);
}

void drawFrame4(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y) {
drawClock(display, x, y, 3, "Sydney", sydney_bits);
}


void setReadyForWeatherUpdate() {
Serial.println("Setting readyForUpdate to true");
readyForUpdate = true;
}

// this array keeps function pointers to all frames
// frames are the single views that slide from right to left
FrameCallback frames[] = { drawFrame1, drawFrame2, drawFrame3, drawFrame4};
int numberOfFrames = 4;

void setup() {
Serial.begin(115200);
Serial.println();
Serial.println();

// initialize dispaly
display.init();
display.clear();
display.display();

//display.flipScreenVertically();
display.setFont(ArialMT_Plain_10);
display.setTextAlignment(TEXT_ALIGN_CENTER);
display.setContrast(255);

WiFi.begin(WIFI_SSID, WIFI_PWD);

int counter = 0;
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
display.clear();
display.drawString(64, 10, "Connecting to WiFi");
display.drawXbm(46, 30, 8, 8, counter % 3 == 0 ? activeSymbol : inactiveSymbol);
display.drawXbm(60, 30, 8, 8, counter % 3 == 1 ? activeSymbol : inactiveSymbol);
display.drawXbm(74, 30, 8, 8, counter % 3 == 2 ? activeSymbol : inactiveSymbol);
display.display();

counter++;
}

ui.setTargetFPS(30);

// You can change this to
// TOP, LEFT, BOTTOM, RIGHT
ui.setIndicatorPosition(BOTTOM);

// Defines where the first frame is located in the bar.
ui.setIndicatorDirection(LEFT_RIGHT);

// You can change the transition that is used
// SLIDE_LEFT, SLIDE_RIGHT, SLIDE_TOP, SLIDE_DOWN
ui.setFrameAnimation(SLIDE_LEFT);

// Add frames
ui.setFrames(frames, numberOfFrames);

// Inital UI takes care of initalising the display too.
ui.init();

Serial.println("");

updateData(&display);

ticker.attach(UPDATE_INTERVAL_SECS, setReadyForWeatherUpdate);

}

void loop() {

if (readyForUpdate && ui.getUiState()->frameState == FIXED) {
updateData(&display);
}

int remainingTimeBudget = ui.update();

if (remainingTimeBudget > 0) {
// You can do some work here
// Don't do stuff if you are below your
// time budget.
delay(remainingTimeBudget);
}

}

Robot localization using GPS module and Blynk application

This project have idea when I play PC game long time ago Red Alert is a name  this game you can control your vehicle along to everywhere by using mouse and you can see vehicle move position that you want to.

After that vehicle will do responsibility assignment depend on type of vehicle I found Blynk application very help full to use not take long time learn just follow my tutorial below then Rock and Roll !!!

 

Can control robot and localization in one screen.

 

Equipment

Esp8266 + Shield

https://usa.banggood.com/custlink/3vv3hC9H7e

 

Manual ESP8266 Shield  : https://drive.google.com/file/d/1J8L5ug2CfqHKRvn1K3wJ6W0LCnhLxoiG/view?usp=sharing

Robot Tank

https://usa.banggood.com/custlink/v3KGEWSS3W

 

GPS Module

 

https://sea.banggood.com/custlink/DvKvhra8P1

Wiring

 

 

Setup Blynk application

  Continue reading “Robot localization using GPS module and Blynk application”

How to connect I2C 2 device +BMP180 show Altitude on SSD1306 OLED dispaly

Need add 2 library

OLED display : 

 https://drive.google.com/open?id=1rUimqKF_9CBCUilNDYi2cbV2ajJBQ3Zv

BMP180 :

https://drive.google.com/file/d/1QoBl_1UGxN0x1gEmGAnUGPopdML4bjRN/view?usp=sharing

Add library

Select zip file from download then check result you will see in example file.

or Sketch > include

 

OLED I2C address : 0x3C

BMP180 (GY-68) I2C address :  0x77

VDO

code

 

#include <SFE_BMP180.h>
#include <Wire.h>

//Oled

#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);

// You will need to create an SFE_BMP180 object, here called "pressure":

SFE_BMP180 pressure;

double baseline; // baseline pressure

void setup()
{
Serial.begin(9600);
Serial.println("REBOOT");

display.begin(SSD1306_SWITCHCAPVCC, 0x3c); //initialize I2C addr 0x3c
display.clearDisplay(); // clears the screen and buffer

// Initialize the sensor (it is important to get calibration values stored on the device).

if (pressure.begin())
Serial.println("BMP180 init success");
else
{
// Oops, something went wrong, this is usually a connection problem,
// see the comments at the top of this sketch for the proper connections.

Serial.println("BMP180 init fail (disconnected?)\n\n");
while(1); // Pause forever.
}

// Get the baseline pressure:

baseline = getPressure();

Serial.print("baseline pressure: ");
Serial.print(baseline);
Serial.println(" mb");


}

void loop()
{


double a,P;

// Get a new pressure reading:

P = getPressure();

// Show the relative altitude difference between
// the new reading and the baseline reading:

a = pressure.altitude(P,baseline);

display.clearDisplay(); // clears the screen and buffer

Serial.print("relative altitude: ");
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0,0);
display.println("relative alt");
if (a >= 0.0) Serial.print(" "); // add a space for positive numbers
Serial.print(a,1);

display.setTextSize(2);
display.println(a,1);
display.setTextColor(BLACK, WHITE);
Serial.print(" meters, ");

display.setTextSize(1);
display.println("meters");
display.setTextColor(BLACK, WHITE);
display.display();
if (a >= 0.0) Serial.print(" "); // add a space for positive numbers
Serial.print(a*3.28084,0);
Serial.println(" feet");

delay(500);



}


double getPressure()
{
char status;
double T,P,p0,a;

// You must first get a temperature measurement to perform a pressure reading.

// Start a temperature measurement:
// If request is successful, the number of ms to wait is returned.
// If request is unsuccessful, 0 is returned.

status = pressure.startTemperature();
if (status != 0)
{
// Wait for the measurement to complete:

delay(status);

// Retrieve the completed temperature measurement:
// Note that the measurement is stored in the variable T.
// Use '&T' to provide the address of T to the function.
// Function returns 1 if successful, 0 if failure.

status = pressure.getTemperature(T);
if (status != 0)
{
// Start a pressure measurement:
// The parameter is the oversampling setting, from 0 to 3 (highest res, longest wait).
// If request is successful, the number of ms to wait is returned.
// If request is unsuccessful, 0 is returned.

status = pressure.startPressure(3);
if (status != 0)
{
// Wait for the measurement to complete:
delay(status);

// Retrieve the completed pressure measurement:
// Note that the measurement is stored in the variable P.
// Use '&P' to provide the address of P.
// Note also that the function requires the previous temperature measurement (T).
// (If temperature is stable, you can do one temperature measurement for a number of pressure measurements.)
// Function returns 1 if successful, 0 if failure.

status = pressure.getPressure(P,T);
if (status != 0)
{
return(P);
}
else Serial.println("error retrieving pressure measurement\n");
}
else Serial.println("error starting pressure measurement\n");
}
else Serial.println("error retrieving temperature measurement\n");
}
else Serial.println("error starting temperature measurement\n");
}

SSD1306 OLED Display

 

 

 

OLED 0.96″ I2C IIC SPI Serial 128X64 OLED LCD LED Display Module For Arduino 51 Series

Needn’t backlight, the display unit can self-luminous
High resolution: 128 * 64
Viewing angle:> 160 °
Supports many control chip: Fully compatible with Arduino, 51 Series, MSP430 Series, STM32 / 2, CSR IC, etc.
Ultra-low power consumption: full screen lit 0.08W
Voltage: 3V ~ 5V DC
Working Temperature: -30 ? ~ 70 ?
Module Size: 27.0MM * 27.0MM * 4.1MM
I2C/IIC Interface, need 2 IO only.
Driver IC: SSD1306
Blue – yellow
I2C address 0x3C

library /code

https://drive.google.com/file/d/1rUimqKF_9CBCUilNDYi2cbV2ajJBQ3Zv/view?usp=sharing

Wiring

OLED -> Arduino
Vcc – > 3.3 / 5 V
Gnd -> Gnd
SCL -> A5
SDA -> A4

CODE

#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);
void setup() {
display.begin(SSD1306_SWITCHCAPVCC, 0x3c); //initialize I2C addr 0x3c
display.clearDisplay(); // clears the screen and buffer
display.drawPixel(127, 63, WHITE);


display.drawLine(0, 63, 127, 21, WHITE);
display.drawCircle(110, 50, 12, WHITE);
display.fillCircle(45, 50, 8, WHITE);
display.drawTriangle(70, 60, 90, 60, 80, 46, WHITE);
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0,0);
display.println("Welcome to");
display.setTextSize(2);
display.println("Arduino");
display.setTextColor(BLACK, WHITE);
display.setTextSize(1);
display.println("www.a-arduino.com");
display.setTextColor(WHITE, BLACK);
display.display();
}

void loop() {
}

Code

/*********************************************************************
This is an example for our Monochrome OLEDs based on SSD1306 drivers

Pick one up today in the adafruit shop!
------> http://www.adafruit.com/category/63_98

This example is for a 128x32 size display using I2C to communicate
3 pins are required to interface (2 I2C and one reset)

Adafruit invests time and resources providing this open source code, 
please support Adafruit and open-source hardware by purchasing 
products from Adafruit!

Written by Limor Fried/Ladyada for Adafruit Industries. 
BSD license, check license.txt for more information
All text above, and the splash screen must be included in any redistribution
*********************************************************************/

#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);

#define NUMFLAKES 10
#define XPOS 0
#define YPOS 1
#define DELTAY 2


#define LOGO16_GLCD_HEIGHT 16 
#define LOGO16_GLCD_WIDTH 16 
static const unsigned char PROGMEM logo16_glcd_bmp[] =
{ B00000000, B11000000,
B00000001, B11000000,
B00000001, B11000000,
B00000011, B11100000,
B11110011, B11100000,
B11111110, B11111000,
B01111110, B11111111,
B00110011, B10011111,
B00011111, B11111100,
B00001101, B01110000,
B00011011, B10100000,
B00111111, B11100000,
B00111111, B11110000,
B01111100, B11110000,
B01110000, B01110000,
B00000000, B00110000 };

#if (SSD1306_LCDHEIGHT != 32)
#error("Height incorrect, please fix Adafruit_SSD1306.h!");
#endif

void setup() { 
Serial.begin(9600);

// by default, we'll generate the high voltage from the 3.3v line internally! (neat!)
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3C (for the 128x32)
// init done

// Show image buffer on the display hardware.
// Since the buffer is intialized with an Adafruit splashscreen
// internally, this will display the splashscreen.
display.display();
delay(2000);

// Clear the buffer.
display.clearDisplay();

// draw a single pixel
display.drawPixel(10, 10, WHITE);
// Show the display buffer on the hardware.
// NOTE: You _must_ call display after making any drawing commands
// to make them visible on the display hardware!
display.display();
delay(2000);
display.clearDisplay();

// draw many lines
testdrawline();
display.display();
delay(2000);
display.clearDisplay();

// draw rectangles
testdrawrect();
display.display();
delay(2000);
display.clearDisplay();

// draw multiple rectangles
testfillrect();
display.display();
delay(2000);
display.clearDisplay();

// draw mulitple circles
testdrawcircle();
display.display();
delay(2000);
display.clearDisplay();

// draw a white circle, 10 pixel radius
display.fillCircle(display.width()/2, display.height()/2, 10, WHITE);
display.display();
delay(2000);
display.clearDisplay();

testdrawroundrect();
delay(2000);
display.clearDisplay();

testfillroundrect();
delay(2000);
display.clearDisplay();

testdrawtriangle();
delay(2000);
display.clearDisplay();

testfilltriangle();
delay(2000);
display.clearDisplay();

// draw the first ~12 characters in the font
testdrawchar();
display.display();
delay(2000);
display.clearDisplay();

// draw scrolling text
testscrolltext();
delay(2000);
display.clearDisplay();

// text display tests
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0,0);
display.println("Hello, world!");
display.setTextColor(BLACK, WHITE); // 'inverted' text
display.println(3.141592);
display.setTextSize(2);
display.setTextColor(WHITE);
display.print("0x"); display.println(0xDEADBEEF, HEX);
display.display();
delay(2000);
display.clearDisplay();

// miniature bitmap display
display.drawBitmap(30, 16, logo16_glcd_bmp, 16, 16, 1);
display.display();
delay(1);

// invert the display
display.invertDisplay(true);
delay(1000); 
display.invertDisplay(false);
delay(1000); 
display.clearDisplay();

// draw a bitmap icon and 'animate' movement
testdrawbitmap(logo16_glcd_bmp, LOGO16_GLCD_HEIGHT, LOGO16_GLCD_WIDTH);
}


void loop() {

}


void testdrawbitmap(const uint8_t *bitmap, uint8_t w, uint8_t h) {
uint8_t icons[NUMFLAKES][3];

// initialize
for (uint8_t f=0; f< NUMFLAKES; f++) {
icons[f][XPOS] = random(display.width());
icons[f][YPOS] = 0;
icons[f][DELTAY] = random(5) + 1;

Serial.print("x: ");
Serial.print(icons[f][XPOS], DEC);
Serial.print(" y: ");
Serial.print(icons[f][YPOS], DEC);
Serial.print(" dy: ");
Serial.println(icons[f][DELTAY], DEC);
}

while (1) {
// draw each icon
for (uint8_t f=0; f< NUMFLAKES; f++) {
display.drawBitmap(icons[f][XPOS], icons[f][YPOS], bitmap, w, h, WHITE);
}
display.display();
delay(200);

// then erase it + move it
for (uint8_t f=0; f< NUMFLAKES; f++) {
display.drawBitmap(icons[f][XPOS], icons[f][YPOS], bitmap, w, h, BLACK);
// move it
icons[f][YPOS] += icons[f][DELTAY];
// if its gone, reinit
if (icons[f][YPOS] > display.height()) {
icons[f][XPOS] = random(display.width());
icons[f][YPOS] = 0;
icons[f][DELTAY] = random(5) + 1;
}
}
}
}


void testdrawchar(void) {
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0,0);

for (uint8_t i=0; i < 168; i++) {
if (i == '\n') continue;
display.write(i);
if ((i > 0) && (i % 21 == 0))
display.println();
} 
display.display();
delay(1);
}

void testdrawcircle(void) {
for (int16_t i=0; i<display.height(); i+=2) {
display.drawCircle(display.width()/2, display.height()/2, i, WHITE);
display.display();
delay(1);
}
}

void testfillrect(void) {
uint8_t color = 1;
for (int16_t i=0; i<display.height()/2; i+=3) {
// alternate colors
display.fillRect(i, i, display.width()-i*2, display.height()-i*2, color%2);
display.display();
delay(1);
color++;
}
}

void testdrawtriangle(void) {
for (int16_t i=0; i<min(display.width(),display.height())/2; i+=5) {
display.drawTriangle(display.width()/2, display.height()/2-i,
display.width()/2-i, display.height()/2+i,
display.width()/2+i, display.height()/2+i, WHITE);
display.display();
delay(1);
}
}

void testfilltriangle(void) {
uint8_t color = WHITE;
for (int16_t i=min(display.width(),display.height())/2; i>0; i-=5) {
display.fillTriangle(display.width()/2, display.height()/2-i,
display.width()/2-i, display.height()/2+i,
display.width()/2+i, display.height()/2+i, WHITE);
if (color == WHITE) color = BLACK;
else color = WHITE;
display.display();
delay(1);
}
}

void testdrawroundrect(void) {
for (int16_t i=0; i<display.height()/2-2; i+=2) {
display.drawRoundRect(i, i, display.width()-2*i, display.height()-2*i, display.height()/4, WHITE);
display.display();
delay(1);
}
}

void testfillroundrect(void) {
uint8_t color = WHITE;
for (int16_t i=0; i<display.height()/2-2; i+=2) {
display.fillRoundRect(i, i, display.width()-2*i, display.height()-2*i, display.height()/4, color);
if (color == WHITE) color = BLACK;
else color = WHITE;
display.display();
delay(1);
}
}

void testdrawrect(void) {
for (int16_t i=0; i<display.height()/2; i+=2) {
display.drawRect(i, i, display.width()-2*i, display.height()-2*i, WHITE);
display.display();
delay(1);
}
}

void testdrawline() { 
for (int16_t i=0; i<display.width(); i+=4) {
display.drawLine(0, 0, i, display.height()-1, WHITE);
display.display();
delay(1);
}
for (int16_t i=0; i<display.height(); i+=4) {
display.drawLine(0, 0, display.width()-1, i, WHITE);
display.display();
delay(1);
}
delay(250);

display.clearDisplay();
for (int16_t i=0; i<display.width(); i+=4) {
display.drawLine(0, display.height()-1, i, 0, WHITE);
display.display();
delay(1);
}
for (int16_t i=display.height()-1; i>=0; i-=4) {
display.drawLine(0, display.height()-1, display.width()-1, i, WHITE);
display.display();
delay(1);
}
delay(250);

display.clearDisplay();
for (int16_t i=display.width()-1; i>=0; i-=4) {
display.drawLine(display.width()-1, display.height()-1, i, 0, WHITE);
display.display();
delay(1);
}
for (int16_t i=display.height()-1; i>=0; i-=4) {
display.drawLine(display.width()-1, display.height()-1, 0, i, WHITE);
display.display();
delay(1);
}
delay(250);

display.clearDisplay();
for (int16_t i=0; i<display.height(); i+=4) {
display.drawLine(display.width()-1, 0, 0, i, WHITE);
display.display();
delay(1);
}
for (int16_t i=0; i<display.width(); i+=4) {
display.drawLine(display.width()-1, 0, i, display.height()-1, WHITE); 
display.display();
delay(1);
}
delay(250);
}

void testscrolltext(void) {
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(10,0);
display.clearDisplay();
display.println("Happy new year 2019");
display.display();
delay(1);

display.startscrollright(0x00, 0x0F);
delay(2000);
display.stopscroll();
delay(1000);
display.startscrollleft(0x00, 0x0F);
delay(2000);
display.stopscroll();
delay(1000); 
display.startscrolldiagright(0x00, 0x07);
delay(2000);
display.startscrolldiagleft(0x00, 0x07);
delay(2000);
display.stopscroll();
}

Altitude using BMP180

This project make Altitude measuring using BMP180 pressure sensor convert pressure to be altitude.

GY-68 Module

GY-68 BMP180 Digital Barometric Pressure Sensor Board Module for for RC Drone FPV Racing Multi Rotor

Wiring

 

Hardware connections:

– (GND) to GND
+ (VDD) to 3.3V

(WARNING: do not connect + to 5V or the sensor will be damaged!)

You will also need to connect the I2C pins (SCL and SDA) to your
Arduino. The pins are different on different Arduinos:

Any Arduino pins labeled: SDA SCL
Uno, Redboard, Pro: A4 A5
Mega2560, Due: 20 21
Leonardo: 2 3

 

Code

 

Load SFE BMP180 Library  link  :  https://drive.google.com/file/d/1QoBl_1UGxN0x1gEmGAnUGPopdML4bjRN/view?usp=sharing

/* SFE_BMP180 altitude example sketch

This sketch shows how to use the Bosch BMP180 pressure sensor
as an altimiter.
https://www.sparkfun.com/products/11824

Like most pressure sensors, the BMP180 measures absolute pressure.
Since absolute pressure varies with altitude, you can use the pressure
to determine your altitude.

Because pressure also varies with weather, you must first take a pressure
reading at a known baseline altitude. Then you can measure variations
from that pressure





Hardware connections:

- (GND) to GND
+ (VDD) to 3.3V

(WARNING: do not connect + to 5V or the sensor will be damaged!)

You will also need to connect the I2C pins (SCL and SDA) to your
Arduino. The pins are different on different Arduinos:

Any Arduino pins labeled: SDA SCL
Uno, Redboard, Pro: A4 A5
Mega2560, Due: 20 21
Leonardo: 2 3

Leave the IO (VDDIO) pin unconnected. This pin is for connecting
the BMP180 to systems with lower logic levels such as 1.8V

Have fun! -Your friends at SparkFun.

The SFE_BMP180 library uses floating-point equations developed by the
Weather Station Data Logger project: http://wmrx00.sourceforge.net/

Our example code uses the "beerware" license. You can do anything
you like with this code. No really, anything. If you find it useful,
buy me a beer someday.

V10 Mike Grusin, SparkFun Electronics 10/24/2013
V1.1.2 Updates for Arduino 1.6.4 5/2015
*/

// Your sketch must #include this library, and the Wire library.
// (Wire is a standard library included with Arduino.):

#include <SFE_BMP180.h>
#include <Wire.h>

// You will need to create an SFE_BMP180 object, here called "pressure":

SFE_BMP180 pressure;

double baseline; // baseline pressure

void setup()
{
Serial.begin(9600);
Serial.println("REBOOT");

// Initialize the sensor (it is important to get calibration values stored on the device).

if (pressure.begin())
Serial.println("BMP180 init success");
else
{
// Oops, something went wrong, this is usually a connection problem,
// see the comments at the top of this sketch for the proper connections.

Serial.println("BMP180 init fail (disconnected?)\n\n");
while(1); // Pause forever.
}

// Get the baseline pressure:

baseline = getPressure();

Serial.print("baseline pressure: ");
Serial.print(baseline);
Serial.println(" mb");
}

void loop()
{
double a,P;

// Get a new pressure reading:

P = getPressure();

// Show the relative altitude difference between
// the new reading and the baseline reading:

a = pressure.altitude(P,baseline);

Serial.print("relative altitude: ");
if (a >= 0.0) Serial.print(" "); // add a space for positive numbers
Serial.print(a,1);
Serial.print(" meters, ");
if (a >= 0.0) Serial.print(" "); // add a space for positive numbers
Serial.print(a*3.28084,0);
Serial.println(" feet");

delay(500);
}

double getPressure()
{
char status;
double T,P,p0,a;

// You must first get a temperature measurement to perform a pressure reading.

// Start a temperature measurement:
// If request is successful, the number of ms to wait is returned.
// If request is unsuccessful, 0 is returned.

status = pressure.startTemperature();
if (status != 0)
{
// Wait for the measurement to complete:

delay(status);

// Retrieve the completed temperature measurement:
// Note that the measurement is stored in the variable T.
// Use '&T' to provide the address of T to the function.
// Function returns 1 if successful, 0 if failure.

status = pressure.getTemperature(T);
if (status != 0)
{
// Start a pressure measurement:
// The parameter is the oversampling setting, from 0 to 3 (highest res, longest wait).
// If request is successful, the number of ms to wait is returned.
// If request is unsuccessful, 0 is returned.

status = pressure.startPressure(3);
if (status != 0)
{
// Wait for the measurement to complete:
delay(status);

// Retrieve the completed pressure measurement:
// Note that the measurement is stored in the variable P.
// Use '&P' to provide the address of P.
// Note also that the function requires the previous temperature measurement (T).
// (If temperature is stable, you can do one temperature measurement for a number of pressure measurements.)
// Function returns 1 if successful, 0 if failure.

status = pressure.getPressure(P,T);
if (status != 0)
{
return(P);
}
else Serial.println("error retrieving pressure measurement\n");
}
else Serial.println("error starting pressure measurement\n");
}
else Serial.println("error retrieving temperature measurement\n");
}
else Serial.println("error starting temperature measurement\n");
}




MIT Inventor application control robot using WiFi

 

VDO

 

Code

#include <ESP8266WiFi.h>

/* define port */
WiFiClient client;
WiFiServer server(80);

/* WIFI settings */
const char* ssid = "your wifi";
const char* password = "wifi password";

/* connect WiFi*/

/* data received from application */
String  data =""; 

/* define L298N or L293D motor control pins */
int leftMotorForward = 2;     /* GPIO2(D4) -> IN3   */
int rightMotorForward = 15;   /* GPIO15(D8) -> IN1  */
int leftMotorBackward = 0;    /* GPIO0(D3) -> IN4   */
int rightMotorBackward = 13;  /* GPIO13(D7) -> IN2  */


/* define L298N or L293D enable pins */
int rightMotorENB = 14; /* GPIO14(D5) -> Motor-A Enable */
int leftMotorENB = 12;  /* GPIO12(D6) -> Motor-B Enable */

void setup()
{

  Serial.begin(9600);
  
  /* initialize motor control pins as output */
  pinMode(leftMotorForward, OUTPUT);
  pinMode(rightMotorForward, OUTPUT); 
  pinMode(leftMotorBackward, OUTPUT);  
  pinMode(rightMotorBackward, OUTPUT);

  /* initialize motor enable pins as output */
  pinMode(leftMotorENB, OUTPUT); 
  pinMode(rightMotorENB, OUTPUT);

  /* start server communication */
  connectWiFi();
  server.begin();
}

void loop()
{
    /* If the server available, run the "checkClient" function */  
    client = server.available();
    if (!client) return; 
    data = checkClient ();

/************************ Run function according to incoming data from application *************************/

    /* If the incoming data is "forward", run the "MotorForward" function */
    if (data == "forward") MotorForward();
    /* If the incoming data is "backward", run the "MotorBackward" function */
    else if (data == "backward") MotorBackward();
    /* If the incoming data is "left", run the "TurnLeft" function */
    else if (data == "left") TurnLeft();
    /* If the incoming data is "right", run the "TurnRight" function */
    else if (data == "right") TurnRight();
    /* If the incoming data is "stop", run the "MotorStop" function */
    else if (data == "stop") MotorStop();

    Serial.println(data);
} 

/********************************************* FORWARD *****************************************************/
void MotorForward(void)   
{
  digitalWrite(leftMotorENB,HIGH);
  digitalWrite(rightMotorENB,HIGH);
  digitalWrite(leftMotorForward,HIGH);
  digitalWrite(rightMotorForward,HIGH);
  digitalWrite(leftMotorBackward,LOW);
  digitalWrite(rightMotorBackward,LOW);
}

/********************************************* BACKWARD *****************************************************/
void MotorBackward(void)   
{
  digitalWrite(leftMotorENB,HIGH);
  digitalWrite(rightMotorENB,HIGH);
  digitalWrite(leftMotorBackward,HIGH);
  digitalWrite(rightMotorBackward,HIGH);
  digitalWrite(leftMotorForward,LOW);
  digitalWrite(rightMotorForward,LOW);
}

/********************************************* TURN LEFT *****************************************************/
void TurnLeft(void)   
{
  digitalWrite(leftMotorENB,HIGH);
  digitalWrite(rightMotorENB,HIGH); 
  digitalWrite(leftMotorForward,LOW);
  digitalWrite(rightMotorForward,HIGH);
  digitalWrite(rightMotorBackward,LOW);
  digitalWrite(leftMotorBackward,HIGH);  
}

/********************************************* TURN RIGHT *****************************************************/
void TurnRight(void)   
{
  digitalWrite(leftMotorENB,HIGH);
  digitalWrite(rightMotorENB,HIGH);
  digitalWrite(leftMotorForward,HIGH);
  digitalWrite(rightMotorForward,LOW);
  digitalWrite(rightMotorBackward,HIGH);
  digitalWrite(leftMotorBackward,LOW);
}

/********************************************* STOP *****************************************************/
void MotorStop(void)   
{
  digitalWrite(leftMotorENB,LOW);
  digitalWrite(rightMotorENB,LOW);
  digitalWrite(leftMotorForward,LOW);
  digitalWrite(leftMotorBackward,LOW);
  digitalWrite(rightMotorForward,LOW);
  digitalWrite(rightMotorBackward,LOW);
}

/********************************** RECEIVE DATA FROM the APP ******************************************/
String checkClient (void)
{
  while(!client.available()) delay(1); 
  String request = client.readStringUntil('\r');
  request.remove(0, 5);
  request.remove(request.length()-9,9);
  return request;
}

void connectWiFi()
{
  Serial.println("Connecting to WIFI");
  WiFi.begin(ssid, password);
  while ((!(WiFi.status() == WL_CONNECTED)))
  {
    delay(300);
    Serial.print("..");
  }
  Serial.println("");
  Serial.println("WiFi connected");
  Serial.println("NodeMCU Local IP is : ");
  Serial.print((WiFi.localIP()));
}