Microcontroller Basics Internet of Things
Microcontroller Basics Internet of Things
Microcontroller Basics Internet of Things
1. ESP8266 MODULE
• We are using this today
• Can be programmed by itself but
usually connected to Arduino
• Price: 2 – 5 €
4. OTA WeMos D1
• ESP8266 Embedded
• Works with Arduino IDE
• Price 10 €
• 11 Digital I/O pins
– 10 have PWM/Interrupt
• 1 Analog pin (max 3v3)
• 9 - 24 V input to power jack
• All pins use 0 – 3.3 V
• No experience of this yet
• There is also a miniversion which is good!
OTA WeMos D1 PINOUT
HOW TO CONNECT?
• Cloud
– NearBus?
• Ready made
– Blynk
• Server
– DIY?
CODES
#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
#include <ESP8266_SoftSer.h>
#include <BlynkSimpleShieldEsp8266_SoftSer.h>
#include <SimpleTimer.h>
// Set ESP8266 Serial object
#include <SoftwareSerial.h>
SoftwareSerial EspSerial(2, 3); // RX, TX
ESP8266 wifi(EspSerial);
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "your_auth_token";
float temp;
int tempPin = 1; //analog pin 1
int reading;
float voltage;
SimpleTimer timer;
void setup()
{
// Set console baud rate
Serial.begin(9600);
delay(10);
// Set ESP8266 baud rate
// 9600 is recommended for Software Serial
EspSerial.begin(9600);
delay(10);
Blynk.begin(auth, wifi, "ssid", "password"); // enter wifi name and password to it
timer.setInterval(1000L, sendTemperature);
}
// This function sends the value of "temp" 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. This function is used (instead of
// sending data in the loop function) to avoid over-loading the Blynk servers.
void sendTemperature()
{
// You can send any value at any time.
// Please don't send more that 10 values per second as this will cause a flood error.
Blynk.virtualWrite(V5, temp);
}
void loop()
{
Blynk.run(); // Initiates Blynk
timer.run(); // Initiates SimpleTimer
// This changes the analog pin reading to Celsius degrees,
// which is then sent to Blynk in the SendTemperature function.
reading = analogRead(tempPin);
voltage = reading * 5;
voltage /= 1024;
temp = (voltage-0.5)*100;
}