Skip to main content

Latest Post

What is Industry 4.0?

  What is Industry 4.0 and what are some of the technologies that are driving it? Industry 4.0 is a term that refers to the fourth industrial revolution, which is characterized by the integration of digital technologies, such as artificial intelligence, cloud computing, big data, the internet of things, robotics, and 3D printing, into the manufacturing sector. Industry 4.0 aims to create smart factories that are more efficient, flexible, and responsive to customer needs and market changes. Some of the technologies that are enabling Industry 4.0 are: - Artificial intelligence (AI) : AI is the ability of machines to perform tasks that normally require human intelligence, such as reasoning, learning, decision-making, and problem-solving. AI can help optimize production processes, improve product quality, reduce costs, and enhance customer satisfaction. - Cloud computing: Cloud computing is delivering computing services, such as servers, storage, databases, software, and analytics, over t

Home Automation 2.0

How does home automation work?

Home automation is a network of hardware, communication, and electronic interfaces that work to integrate everyday devices with one another via the Internet. Each device has sensors and is connected through Wi-Fi, so you can manage them from your smartphone or tablet whether you’re at home, or miles away. This allows you to turn on the lights, lock the front door, or even turn down the heat, no matter where you are.

What are the benefits of home automation?

The purpose of a home automation system is to streamline how your home functions. Consider some of these benefits:
  • Remote access: Control your home from mobile devices, including your laptop, tablet, or smartphone.
  • Comfort: Use home automation to make your home a more comfortable, livable space. Preprogram your thermostat with your preferred settings so that your home is always at a comfortable temperature, set up smart speakers to play music when you get home from work, or adjust your lights to soften or brighten based on the time of day.
  • Convenience: Program devices to turn on automatically at certain times, or access their settings remotely from anywhere with an Internet connection. When you don’t have to remember to lock the door behind you or switch off the lights, you can turn your attention to more important things.
  • Increased safety: Smart fire detectors, carbon monoxide monitors, pressure sensors, and other home automation security features can help protect your home from disaster.
  • Energy efficiency: Home automation allows you to be more mindful of your power usage. For example, you can save on energy bills by reducing the length of time that lights stay on, or by lowering temperatures when you leave a room.

Requirements

  • Node MCU
  • DHT11
  • 4 Ch relay
  • Toggle switches X 4
  • Hi-Link (220V AC to 12V DC)

Circuit Diagram



Program


#define BLYNK_TEMPLATE_ID "**your ID***"
#define BLYNK_DEVICE_NAME "*****name*****"
#define BLYNK_AUTH_TOKEN "***********Your Auth***********"

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "WIFI NAME";
char pass[] = "WIFI PASSWORD";

bool fetch_blynk_state = true;  //true or false


//#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>        
#include <BlynkSimpleEsp8266.h>
#include <DHT.h>  

#define DHTPIN D4 //D4  pin connected with DHT

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

 
// define the GPIO connected with Relays and switches
#define RelayPin1 5  //D1
#define RelayPin2 4  //D2
#define RelayPin3 14 //D5
#define RelayPin4 12 //D6

#define SwitchPin1 10  //SD3
#define SwitchPin2 D3   //D3
#define SwitchPin3 13  //D7
#define SwitchPin4 3   //RX

#define wifiLed   16   //D0

//Change the virtual pins according the rooms
#define VPIN_BUTTON_1    V1
#define VPIN_BUTTON_2    V2
#define VPIN_BUTTON_3    V3
#define VPIN_BUTTON_4    V4

#define VPIN_BUTTON_C    V5
#define VPIN_TEMPERATURE V6
#define VPIN_HUMIDITY    V7

// Relay State
bool toggleState_1 = LOW; //Define integer to remember the toggle state for relay 1
bool toggleState_2 = LOW; //Define integer to remember the toggle state for relay 2
bool toggleState_3 = LOW; //Define integer to remember the toggle state for relay 3
bool toggleState_4 = LOW; //Define integer to remember the toggle state for relay 4

// Switch State
bool SwitchState_1 = LOW;
bool SwitchState_2 = LOW;
bool SwitchState_3 = LOW;
bool SwitchState_4 = LOW;

int wifiFlag = 0;
float temperature1 = 0;
float humidity1   = 0;

char auth[] = BLYNK_AUTH_TOKEN;

BlynkTimer timer;
DHT dht(DHTPIN, DHTTYPE);

// When App button is pushed - switch the state

BLYNK_WRITE(VPIN_BUTTON_1) {
  toggleState_1 = param.asInt();
  digitalWrite(RelayPin1, !toggleState_1);
}

BLYNK_WRITE(VPIN_BUTTON_2) {
  toggleState_2 = param.asInt();
  digitalWrite(RelayPin2, !toggleState_2);
}

BLYNK_WRITE(VPIN_BUTTON_3) {
  toggleState_3 = param.asInt();
  digitalWrite(RelayPin3, !toggleState_3);
}

BLYNK_WRITE(VPIN_BUTTON_4) {
  toggleState_4 = param.asInt();
  digitalWrite(RelayPin4, !toggleState_4);
}

BLYNK_WRITE(VPIN_BUTTON_C) {
  all_SwitchOff();
}

void all_SwitchOff(){
  toggleState_1 = 0;
  digitalWrite(RelayPin1, HIGH);
Blynk.virtualWrite(VPIN_BUTTON_1, toggleState_1);
delay(100);

  toggleState_2 = 0;
  digitalWrite(RelayPin2, HIGH);
Blynk.virtualWrite(VPIN_BUTTON_2, toggleState_2);
delay(100);

  toggleState_3 = 0;
digitalWrite(RelayPin3, HIGH);
Blynk.virtualWrite(VPIN_BUTTON_3, toggleState_3);
delay(100);

  toggleState_4 = 0;
digitalWrite(RelayPin4, HIGH);
Blynk.virtualWrite(VPIN_BUTTON_4, toggleState_4);
delay(100);

  Blynk.virtualWrite(VPIN_HUMIDITY, humidity1);
  Blynk.virtualWrite(VPIN_TEMPERATURE, temperature1);
}

void checkBlynkStatus() { // called every 2 seconds by SimpleTimer

  bool isconnected = Blynk.connected();
  if (isconnected == false) {
    wifiFlag = 1;
    Serial.println("Blynk Not Connected");
    digitalWrite(wifiLed, HIGH);
  }
  if (isconnected == true) {
    wifiFlag = 0;
    if (!fetch_blynk_state){
    Blynk.virtualWrite(VPIN_BUTTON_1, toggleState_1);
    Blynk.virtualWrite(VPIN_BUTTON_2, toggleState_2);
    Blynk.virtualWrite(VPIN_BUTTON_3, toggleState_3);
    Blynk.virtualWrite(VPIN_BUTTON_4, toggleState_4);
    }
    digitalWrite(wifiLed, LOW);
    //Serial.println("Blynk Connected");
  }
}

BLYNK_CONNECTED() {
  // Request the latest state from the server
  if (fetch_blynk_state){
    Blynk.syncVirtual(VPIN_BUTTON_1);
    Blynk.syncVirtual(VPIN_BUTTON_2);
    Blynk.syncVirtual(VPIN_BUTTON_3);
    Blynk.syncVirtual(VPIN_BUTTON_4);
  }
    Blynk.syncVirtual(VPIN_TEMPERATURE);
    Blynk.syncVirtual(VPIN_HUMIDITY);  
}

void readSensor(){
 
  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;
  }
  else {
    humidity1 = h;
    temperature1 = t;
   // Serial.println(temperature1);
   // Serial.println(humidity1);
  }  
}

void sendSensor()
{
  readSensor();
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(VPIN_HUMIDITY, humidity1);
  Blynk.virtualWrite(VPIN_TEMPERATURE, temperature1);
}


void manual_control()
{
  if (digitalRead(SwitchPin1) == LOW && SwitchState_1 == LOW) {
    digitalWrite(RelayPin1, LOW);
    toggleState_1 = HIGH;
    SwitchState_1 = HIGH;
    Blynk.virtualWrite(VPIN_BUTTON_1, toggleState_1);
    Serial.println("Switch-1 on");
  }
  if (digitalRead(SwitchPin1) == HIGH && SwitchState_1 == HIGH) {
    digitalWrite(RelayPin1, HIGH);
    toggleState_1 = LOW;
    SwitchState_1 = LOW;
    Blynk.virtualWrite(VPIN_BUTTON_1, toggleState_1);
    Serial.println("Switch-1 off");
  }
  if (digitalRead(SwitchPin2) == LOW && SwitchState_2 == LOW) {
    digitalWrite(RelayPin2, LOW);
    toggleState_2 = HIGH;
    SwitchState_2 = HIGH;
    Blynk.virtualWrite(VPIN_BUTTON_2, toggleState_2);
    Serial.println("Switch-2 on");
  }
  if (digitalRead(SwitchPin2) == HIGH && SwitchState_2 == HIGH) {
    digitalWrite(RelayPin2, HIGH);
    toggleState_2 = LOW;
    SwitchState_2 = LOW;
    Blynk.virtualWrite(VPIN_BUTTON_2, toggleState_2);
    Serial.println("Switch-2 off");
  }
  if (digitalRead(SwitchPin3) == LOW && SwitchState_3 == LOW) {
    digitalWrite(RelayPin3, LOW);
    toggleState_3 = HIGH;
    SwitchState_3 = HIGH;
    Blynk.virtualWrite(VPIN_BUTTON_3, toggleState_3);
    Serial.println("Switch-3 on");
  }
  if (digitalRead(SwitchPin3) == HIGH && SwitchState_3 == HIGH) {
    digitalWrite(RelayPin3, HIGH);
    toggleState_3 = LOW;
    SwitchState_3 = LOW;
    Blynk.virtualWrite(VPIN_BUTTON_3, toggleState_3);
    Serial.println("Switch-3 off");
  }
  if (digitalRead(SwitchPin4) == LOW && SwitchState_4 == LOW) {
    digitalWrite(RelayPin4, LOW);
    toggleState_4 = HIGH;
    SwitchState_4 = HIGH;
    Blynk.virtualWrite(VPIN_BUTTON_4, toggleState_4);
    Serial.println("Switch-4 on");
  }
  if (digitalRead(SwitchPin4) == HIGH && SwitchState_4 == HIGH) {
    digitalWrite(RelayPin4, HIGH);
    toggleState_4 = LOW;
    SwitchState_4 = LOW;
    Blynk.virtualWrite(VPIN_BUTTON_4, toggleState_4);
    Serial.println("Switch-4 off");
  }
}  

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

  pinMode(RelayPin1, OUTPUT);
  pinMode(RelayPin2, OUTPUT);
  pinMode(RelayPin3, OUTPUT);
  pinMode(RelayPin4, OUTPUT);

  pinMode(wifiLed, OUTPUT);

  pinMode(SwitchPin1, INPUT_PULLUP);
  pinMode(SwitchPin2, INPUT_PULLUP);
  pinMode(SwitchPin3, INPUT_PULLUP);
  pinMode(SwitchPin4, INPUT_PULLUP);

  //During Starting all Relays should TURN OFF
  digitalWrite(RelayPin1, !toggleState_1);
  digitalWrite(RelayPin2, !toggleState_2);
  digitalWrite(RelayPin3, !toggleState_3);
  digitalWrite(RelayPin4, !toggleState_4);

  dht.begin();    // Enabling DHT sensor

  digitalWrite(wifiLed, HIGH);

  //Blynk.begin(auth, ssid, pass);
  WiFi.begin(ssid, pass);
  timer.setInterval(2000L, checkBlynkStatus);
  timer.setInterval(1000L, sendSensor);
  Blynk.config(auth);
  delay(1000);
 
  if (!fetch_blynk_state){
    Blynk.virtualWrite(VPIN_BUTTON_1, toggleState_1);
    Blynk.virtualWrite(VPIN_BUTTON_2, toggleState_2);
    Blynk.virtualWrite(VPIN_BUTTON_3, toggleState_3);
    Blynk.virtualWrite(VPIN_BUTTON_4, toggleState_4);
  }
}

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



Video

Comments

Popular

Playing with Buttons

Button Pushbuttons or switches connect two points in a circuit when you press them. This example turns on the built-in LED on pin 13 when you press the button. Hardware Arduino Board Momentary button or Switch 10K ohm resistor hook-up wires breadboard Circuit diagram Code // constants won't change. They're used here to // set pin numbers: const int buttonPin = 2 ;     // the number of the pushbutton pin const int ledPin =   13 ;      // the number of the LED pin // variables will change: int buttonState = 0 ;         // variable for reading the pushbutton status void setup () {   Serial . begin ( 9600 );   // initialize the LED pin as an output:   pinMode (ledPin, OUTPUT);   // initialize the pushbutton pin as an input:   pinMode (buttonPin, INPUT); } void loop () {   // read the state of the pushbutton value:   buttonState = digitalRead (buttonPin);   // Show the state of pushbutton on serial monitor   Serial . println (buttonState);   // check if the pushbutton is p

Home Automation

A smart system made by using Node MCU dev board. What is Node MCU? NodeMCU is an open-source firmware for which open-source prototyping board designs are available. The name "NodeMCU" combines "node" and "MCU" (micro-controller unit). The term "NodeMCU" strictly speaking refers to the firmware rather than the associated development kits.  Both the firmware and prototyping board designs are open source. Requirments Node MCU 4 channel relay toggle switch * 4 Hi-links (220v ac to 5v dc) Circuit Diagram Program #ifdef ENABLE_DEBUG         #define DEBUG_ESP_PORT Serial         #define NODEBUG_WEBSOCKETS         #define NDEBUG #endif #include <Arduino.h> #include <ESP8266WiFi.h> #include "SinricPro.h" #include "SinricProSwitch.h" #include <map> #define WIFI_SSID         "your wifi name"     #define WIFI_PASS         "your wifi pass" #define APP_KEY           "this code is prov

Turn LED On and Off Through LDR

  LDR An LDR ( Light Dependent Resistor ) is a component that has a (variable) resistance that changes with the light intensity that falls upon it. This allows them to be used in light sensing circuits. A photoresistor is made of a high resistance semiconductor. Hardware Required Arduino Board LED 220 ohm resistor LDR 10k ohms resistor Circuit Diagram Code int ldr=A0; //Set A0(Analog Input) for LDR. int value= 0 ; void setup () { Serial . begin ( 9600 ); pinMode ( 3 ,OUTPUT); } void loop () { value= analogRead (ldr); //Reads the Value of LDR(light). Serial . println ( "LDR value is :" ); //Prints the value of LDR to Serial Monitor. Serial . println (value); if (value< 300 )   {     digitalWrite ( 3 ,HIGH); //Makes the LED glow in Dark.   }   else   {     digitalWrite ( 3 ,LOW); //Turns the LED OFF in Light.   } }

Temperature sensor

About the LM35 The LM35 is an inexpensive, precision Centigrade temperature sensor made by  Texas Instruments . It provides an output voltage that is linearly proportional to the Centigrade temperature and is, therefore, very easy to use with the Arduino. The sensor does not require any external calibration or trimming to provide accuracies of ±0.5°C at room temperature and ±1°C over the −50°C to +155°C temperature range. One of the downsides of the sensor is that it requires a negative bias voltage to read negative temperatures. So if that is needed for your project, I recommend using the DS18B20 or TMP36 instead. The TMP36 by Analog Devices is very similar to the LM35 and can read temperatures from -40°C to 125°C without any external components Note that the sensor operates on a voltage range of 4 to 30 V and that the output voltage is independent of the supply voltage. The LM35 is part of a series of analog temperature sensors sold by Texas Instruments. Other members of the series i

MQ2 Gas Sensor

 About Gas Sensor The MQ series of gas sensors use a small heater inside with an electrochemical sensor. They are sensitive to a range of gasses and are used indoors at room temperature. The output is an analog signal and can be read with an analog input of the Arduino. The MQ-2 Gas Sensor module is useful for gas leakage detection in homes and industries. It can detect LPG, i-butane, propane, methane, alcohol, hydrogen, and smoke. Some modules have a built-in variable resistor to adjust the sensitivity of the sensor. Note:  The sensor becomes very hot after a while, don't touch it! Required  Arduino UNO Breadboard MQ-2 Gas sensor module Red, Green led 5mm 220 Ohm Buzzer The connections are pretty easy: The MQ-5 sensor Pin-> Wiring to Arduino Uno A0-> Analog pins D0-> none GND-> GND VCC-> 5V other components Pin-> Wiring to Arduino Uno D13-> +ve of buzzer GND-> -ve of buzzer D12-> anode of red light D11-> anode of green light GND-> cathode of red li

Play a melody with a Piezo speaker

  Play a Melody using the tone() function This example shows how to use the  tone()  command to generate notes. It plays a little melody you may have heard before. Hardware Required Arduino board piezo buzzer or a speaker hook-up wires Making header file To make the pitches.h file, either click on the button just below the serial monitor icon and choose "New Tab", or use Ctrl+Shift+N. Then paste in the following code: /************************************************* * Public Constants *************************************************/ # define NOTE_B0 31 # define NOTE_C1 33 # define NOTE_CS1 35 # define NOTE_D1 37 # define NOTE_DS1 39 # define NOTE_E1 41 # define NOTE_F1 44 # define NOTE_FS1 46 # define NOTE_G1 49 # define NOTE_GS1 52 # define NOTE_A1 55 # define NOTE_AS1 58 # define NOTE_B1 62 # define NOTE_C2 65 # define NOTE_CS2 69 # define NOTE_D2 73 # define NOTE_DS2 78 # define NOTE_E2 82 # define NOTE_F2 87 # de

Seven Segment Display Interfacing with Arduino

Seven-Segment Introduction  Let’s start the main part of this tutorial by answering a question: what is a seven-segment display? As its name suggests, a 7-segment device consists of 7  light-emitting diodes . These light-emitting diodes are arranged and packed inside a single display with a specific pattern in mind. If this pattern is controlled in a specific way by turning on and turning off LEDs, a seven-segment device will display a unique number. There is also an extra eighth LED on a seven-segment display which is used to display dots. This dot is sometimes used as a decimal point when we want to display a fractional value.  The picture below shows a seven-segment display and its pinout. The string of eight LEDs on the left side shows the internal connection and a picture on the right side shows how these LEDs are arranged to make a seven-segment display. Pin3 and 8 are common pins. These pins are used to provide either 5 volts or ground in common-anode and common cathode type dis

Mini Oscilloscope via Arduino Nano

What is an oscilloscope?   An  oscilloscope , formerly known as an oscillograph, is an instrument that graphically displays electrical signals and shows how those signals change over time. It measures these signals by connecting with a sensor, which is a device that creates an electrical signal in response to physical stimuli like sound, light, and heat. For instance, a microphone is a sensor that converts sound into an electrical signal. Oscilloscopes are often used when designing, manufacturing, or repairing electronic equipment. Engineers use an oscilloscope to measure electrical phenomena and solve measurement challenges quickly and accurately to verify their designs or confirm that a sensor is working properly. Scientists, engineers, physicists, repair technicians, and educators use oscilloscopes to see signals change over time. An automotive engineer might use an oscilloscope to correlate analog data from sensors with serial data from the engine control unit. Meanwhile, a medical

Fade an LED

  Fade This example demonstrates the use of the  analogWrite()  function in fading an LED off and on. AnalogWrite uses  pulse width modulation (PWM) , turning a digital pin on and off very quickly with different ratio between on and off, to create a fading effect. Hardware Required Arduino board LED 220 ohm resistor hook-up wires Circuit Diagram Code int led = 9 ;           // the PWM pin the LED is attached to int brightness = 0 ;    // how bright the LED is int fadeAmount = 5 ;    // how many points to fade the LED by // the setup routine runs once when you press reset: void setup () {   // declare pin 9 to be an output:   pinMode (led, OUTPUT); } // the loop routine runs over and over again forever: void loop () {   // set the brightness of pin 9:   analogWrite (led, brightness);   // change the brightness for next time through the loop:   brightness = brightness + fadeAmount;   // reverse the direction of the fading at the ends of the fade:   if (brightness <= 0 || bri

Fire Alarm with arduino

Flame Sensor A  flame detector  is a sensor designed to detect and respond to the presence of a flame or fire. Responses to a detected flame depend on the installation but can include sounding an alarm, deactivating a fuel line (such as a propane or a natural gas line), and activating a fire suppression system. The IR Flame sensor used in this project is shown below, these sensors are also called  Fire sensor modules  or  flame detector sensors  sometimes. There are different types of flame detection methods. Some of them are Ultraviolet detector, near IR array detector, infrared (IR) detector, Infrared thermal cameras, UV/IR detector, etc. When fire burns it emits a small amount of Infra-red light, this light will be received by the Photodiode (IR receiver) on the sensor module. Then we use an Op-Amp to check for a change in voltage across the IR Receiver, so that if a fire is detected the output pin (DO) will give 0V(LOW), and if the is no fire the output pin will be 5V(HIGH). In thi