Posts

ESP 8266- DHT11 Interfacing

Image
  // Include the DHT11 library for interfacing with the sensor. #include <DHT11.h> DHT11 dht11(5); void setup() {     // Initialize serial communication to allow debugging and data readout.     // Using a baud rate of 9600 bps.     Serial.begin(9600);          // dht11.setDelay(500); // Set this to the desired delay. Default is 500ms. } void loop() {     int temperature = 0;     int humidity = 0;     // Attempt to read the temperature and humidity values from the DHT11 sensor.     int result = dht11.readTemperatureHumidity(temperature, humidity);     // Check the results of the readings.     // If the reading is successful, print the temperature and humidity values.     // If there are errors, print the appropriate error messages.     if (result == 0) {         Serial.print("Temperature: ");         Seri...

LED ON/OFF Using Blynk

 Program / #define BLYNK_AUTH_TOKEN "auth token" #define BLYNK_TEMPLATE_ID "template id" #define BLYNK_TEMPLATE_NAME "LED control " #define BLYNK_PRINT Serial #include <ESP8266WiFi.h>   #include <BlynkSimpleEsp8266.h>   char auth[] = BLYNK_AUTH_TOKEN; char ssid[] = "wifi name";  // Enter your Wifi Username char pass[] = "wifi password";  // Enter your Wifi password int ledpin = D0; void setup() {        Serial.begin(115200);   Blynk.begin(auth, ssid, pass);       pinMode(ledpin,OUTPUT); } void loop() {   Blynk.run();  }

Soil moisture sensor interfacing with ESP8266

Image
  Program const int sensor_pin = A0;  /* Connect Soil moisture analog sensor pin to A0 of NodeMCU */ void setup() {   Serial.begin(9600); /* Define baud rate for serial communication */ } void loop() {   float moisture_percentage;   moisture_percentage = ( 100.00 - ( (analogRead(sensor_pin)/1023.00) * 100.00 ) );   Serial.print("Soil Moisture(in Percentage) = ");   Serial.print(moisture_percentage);   Serial.println("%");   delay(1000); }

PIR Sensor Interfacing with ESP8266

Image
Program  #define pir D1  #define LED D2 void setup() {   Serial.begin(9600);   pinMode(pir, INPUT);   // declare pir sensor pin as input   pinMode(LED, OUTPUT);  // declare LED as output } void loop() {   long state = digitalRead(pir);     if(state == HIGH) {       Serial.println("Motion Detected");       digitalWrite (LED, HIGH);       delay(5000);     }     else {       Serial.println("Motion not detected");       digitalWrite (LED, LOW);       delay(1000);       } }

ESP 8266- External LED Blink

Image
  #define LED D0             void setup()   { pinMode(LED, OUTPUT);     } void loop() { digitalWrite(LED, HIGH);                         delay(1000);             digitalWrite(LED, LOW); delay(1000); }

ESP 8266- Servo Motor Interfacing

Image
#include <Servo.h> #define servopin D0 Servo myservo;                  // create servo object to control a servo void setup()  {   myservo.attach(servopin,400,2500);  // attaches the servo on D0 }   void loop() {   int pos;     for (pos = 0; pos <= 180; pos += 1) {  // goes from 0 degrees to 180 degrees     // in steps of 1 degree     myservo.write(pos);  // tell servo to go to position in variable 'pos'     delay(15);           // waits 15ms for the servo to reach the position   }   for (pos = 180; pos >= 0; pos -= 1) {  // goes from 180 degrees to 0 degrees     myservo.write(pos);                  // tell servo...

ESP 8266- Ultrasonic Sensor Interfacing

Image
  #define trigPin D0 #define echoPin D1 long duration; int distance;   void setup() {   Serial.begin(9600); // Starts the serial communication   pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output   pinMode(echoPin, INPUT); // Sets the echoPin as an Input }   void loop() {   // Clears the trigPin   digitalWrite(trigPin, LOW);   delayMicroseconds(2);   // Sets the trigPin on HIGH state for 10 micro seconds   digitalWrite(trigPin, HIGH);   delayMicroseconds(10);   digitalWrite(trigPin, LOW);     // Reads the echoPin, returns the sound wave travel time in microseconds   duration = pulseIn(echoPin, HIGH);     // Calculate the distance   distance = duration * 0.034/2;   // 0.034 means velocity of sound in cm/us         // Prints the distance on the Serial Monitor   Serial.print("Distance: "); ...