Earn Maker Points on Every Order! Learn More!

IOT Home Automation using Blynk and NodeMCU

Back to Blog
IOT Home Automation using Blynk and NodeMCU - IOT Home Automation using Blynk and NodeMCU - IOT Home Automation using Blynk and NodeMCU - IOT Home Automation using Blynk and NodeMCU

IOT Home Automation using Blynk and NodeMCU

NodeMCU is very popular in Home Automation. It’s WiFi capabilities and Arduino IDE support making it easier for IoT Applications. It is very tiny and has many Digital I/O pins, Serial Communication and I2C Communication. NodeMCU has a micro USB port to program it using your existing mobile cable (no additional programmer needed). There is a successor called ESP32 Development board which has more Analog pins and Digital pins. You can use any one of them for this project according to your requirements. Here we will be using NodeMCU.

Blynk is a mobile application which has its own server to process user requests. It is an open source application and anybody can use it in their Home Automation to control devices, monitor sensor data and get a notification by some trigger actions. It has a nice GUI with Graphs, Timers, Slider, Joystick and even Video Streaming. You can also make your own app and publish it in Google play store.

Components required:

Hardware:

  • NodeMCU Development board – Buy Now
  • 4 Channel Relay – Buy Now
  • USB cable

Software required:

Circuit Diagram:

Home Automation with NodeMCU_v2

Example Relay connection with AC Devices. Consider the relay as a switch:

1CH Relay with phase -  -  -Note: For example purpose, we have connected Relay at D0, D1, D2 and D3. You need to make sure there should not be alternate functions to that pins. Because the D0 pin has connected with Onboard LED (D4 has TXD1 function), whenever you Power ON the NodeMCU it blinks for a second. In case you have connected a Tube Light, it will flash during startup. So please refer the NodeMCU pinout and assign the proper pins without any conflictions.

P.S – I found that the D1, D2, D5, D6 are good to use for without any flickering of Relays.

Caution: If you are using AC Power supply, please connect it carefully as it is High Voltage and have Risk of electric shock or short circuit.

Check this tutorial for Voice Controlled Home Automation using Google Assistant – an upgraded version of this tutorial.

Check this tutorial for implementing this Relay with Two-Way Switches to control from both of them.

NodeMCU Pinout:

 nodemcu_pins

Download Blynk Application from Google Play store:

Download and install the Blynk App Here:

Android

Apple

Create a Blynk App:

Step1: For new users Sign Up and old users just Log in.

Step2: Create a New Project and Choose NodeMCU board in the Choose device drop-down and then click create.

Blynk1-choose-board

Blynk2-create-project

Step 3: Now you will receive an email with the Authentication Token. You need to place it in the Arduino Code. Before that, we will finish the App Creation.

Step 4: Click on the ‘+’ Icon on the top right corner. Now Widget box will open, We need 4 buttons to control the relay. So add 4 buttons by choosing it here.

Blynk3-add-buttons

Step 5: Now tap on the button from the Homepage to configure it. Choose the Output Pin D0 and Select the Mode as Switch. Then go back. Configure the remaining buttons in the same way.

Blynk4-configure-buttons

Step 6: Now we have the App ready.

Blynk5-FinalApp

Step 7: Now connect the NodeMCU to the PC and open Arduino IDE.

Install the Blynk library from Sketch>Include Library> Manage Library and search for blynk and install it. Or you can install using Git Method from here.

In case, you are using ESP8266 or NodeMCU for the first time you need to add NodeMCU on boards manager and the ESP8266Wifi.h library to be installed. Otherwise, skip to step 8.

Installing ESP8266 Boards:

Navigate to Tools>Board>Boards Manager. Search for esp8266 and install esp8266 boards.

Installing Arduino Master (or Arduino Core) library:

The ESP8266Wifi.h library is included in Arduino Master(Core Library). You need to download and extract the file. Then navigate to libraries in the extracted file (Example: C:\Users\YourPCName\Downloads\Arduino-master\Arduino-master\libraries). Then copy all ESP Related folders or all the folders (depending upon your choice) and paste in inside C:\Program Files (x86)\Arduino\libraries.

Source Path

Source Path (Extracted File location of Arduino Core library)

destination-location-skip-file

Destination Path (Arduino Libraries location)

Now we have set up everything.

Step 8: Copy the following code or Open File->Examples and navigate to Blynk->WiFi->NodeMCU.

You need to modify only three things in this code.

Paste the Authentication Token that you received in your email at ‘YourAuthToken’. Then add your SSID and Password in the code as ‘YourNetworkName’ and ‘YourPassword’.

Note: In some cases, it might show you warnings for ‘Multiple Libraries found’. It is just a warning to acknowledge which library it is using. Because the Arduino and esp8266 core library have the same libraries. Example Servo.h library. Simply ignore it and upload the program.

/*************************************************************

Download latest Blynk library here:

https://github.com/blynkkk/blynk-library/releases/latest

Downloads, docs, tutorials: http://www.blynk.cc

Sketch generator:           http://examples.blynk.cc

Blynk community:            http://community.blynk.cc

*************************************************************

This example runs directly on NodeMCU.

Note: This requires ESP8266 support package:

https://github.com/esp8266/Arduino

Change WiFi ssid, pass, and Blynk auth token to run :)

*************************************************************/

#define BLYNK_PRINT Serial

#include <ESP8266WiFi.h>

#include <BlynkSimpleEsp8266.h>


// You should get Auth Token in the Blynk App.

// Go to the Project Settings (nut icon).

char auth[] = "YourAuthToken";


// Your WiFi credentials.

// Set password to "" for open networks.

char ssid[] = "YourNetworkName";

char pass[] = "YourPassword";


void setup()

{
/*To avoid relays chatters when connected to blynk, set the pin to HIGH (for Relays that turns OFF at HIGH) 
before blynk.begin function. Eg. for D3 Given Below */

//pinMode(D3, OUTPUT);
//digitalWrite(D3, HIGH);

Serial.begin(9600);

Blynk.begin(auth, ssid, pass);

Blynk.syncAll(); //This will sync the last state of your device

}

void loop()

{

Blynk.run();

}

Once it completes, Choose the right port and Board then upload the code. That’s it! Your Home Automation Project is ready. You can test it in your Blynk app by turning ON and OFF. It can work from anywhere in the world with an internet connection.

Blynk6-testing

The advanced version of the app is continued in the next tutorial. It can control the devices using your Voice Commands using Google Assistant on your Phone or Google Home. Check out the tutorial, if you want to upgrade your project with Voice Control – Voice Controlled Home Automation | Google Assistant | NodeMCU

Share this post

Comments (82)

  • Bello Isaac

    Thanks for the tutorial. Here is my challenge, I uses Node MCU V3 but here I have the failure report when uploading.

    Sketch uses 235849 bytes (22%) of program storage space. Maximum is 1044464 bytes.
    Global variables use 34312 bytes (41%) of dynamic memory, leaving 47608 bytes for local variables. Maximum is 81920 bytes.
    Uploading 240000 bytes from C:\Users\ISAACB~1\AppData\Local\Temp\arduino_build_96048/NodeMCU.ino.bin to flash at 0x00000000
    …………………………………………………………………….. [ 34% ]
    …………………………………………………………………….. [ 68% ]
    ………………………………………………………………… [ 100% ]
    Invalid library found in C:\Users\Isaac Bello\Documents\Arduino\libraries\NODE_MCU: C:\Users\Isaac Bello\Documents\Arduino\libraries\NODE_MCU
    Invalid library found in C:\Users\Isaac Bello\Documents\Arduino\libraries\NODE_MCU: C:\Users\Isaac Bello\Documents\Arduino\libraries\NODE_MCU

    Please help me ASAP.

    August 10, 2018 at 6:53 AM
    • Sharath

      1. The program needs the ESP8266 WiFi library. It is available in the Arduino Master library. You can download it here – https://github.com/esp8266/Arduino

      Note: You need to extract this file and navigate to the libraries folder (inside this you find all the library folders), then copy paste the ESP libraries that you needed or copy-paste all libraries according to your choice into this path – C:\Program Files (x86)\Arduino\libraries\

      2. It seems like you are using a wrong library file folder. By default, There is no library named as ‘NODE_MCU’. Maybe you extracted the downloaded filename itself instead of the library name (which contents might be available inside that folder).

      The libraries are installed in two places –
      The main Arduino IDE Location – C:\Program Files (x86)\Arduino\libraries\
      User Work Space – C:\Users\John_Doe\Documents\Arduino\libraries\

      Inside these two locations, all the libraries will be available. And it will start with the Library names like Servo. ESP8266, Blynk, LiquidCrystal, Wire and more. Inside that library names the src, examples folders exist.

      3. If the library is available in both locations, delete any one of it.

      August 13, 2018 at 1:18 PM
      • Raji

        We are not getting to download the Arduino master app

        March 15, 2019 at 1:36 PM
        • Sharath

          It’s not an app actually. It is a core library file that Arduino needs. You can able to see clone and download option on GitHub and then extract and navigate to libraries folder (refer the above mentioned steps)

          March 15, 2019 at 1:48 PM
  • Ahson Ahmed

    sarahth your work is excellent can you modify the code for reading 4 switch data which will light up led on blynk app

    October 24, 2018 at 6:06 PM
    • Sharath

      Try This. It is modified for a single button and LED Widget. Mentioned places to add by yourself. Didn’t tested but it might work.

      #define BLYNK_PRINT Serial

      #include

      #include
      const int btnPin1 = 1; // Your Physical Button Pin
      //Add similar way for other buttons too like prev

      WidgetLED led1(V1); //Virtual Pins that u selected on BlynkApp
      //Add the similar way for other virtual buttons too like prev line

      BlynkTimer timer;

      // Your WiFi credentials.
      // Set password to "" for open networks.
      char auth[] = "YourAuthToken";
      char ssid[] = "YourNetworkName";
      char pass[] = "YourPassword";

      //Button Function

      boolean btnState1 = false;
      void buttonLedWidget1()
      {
      // Read button
      boolean isPressed = (digitalRead(btnPin1) == LOW);

      // If state has changed...
      if (isPressed != btnState1) {
      if (isPressed) {
      led1.on();
      } else {
      led1.off();
      }
      btnState1 = isPressed;
      }

      //Create other functions for other LED Widgets here (Name accordingly)

      }

      void setup()
      {

      Serial.begin(9600);

      Blynk.begin(auth, ssid, pass);

      Blynk.syncAll(); //This will sync the last state of your device
      pinMode(btnPin1, INPUT_PULLUP); //Always High - To be grounded (LOW) when button pressed.
      timer.setInterval(500L, buttonLedWidget1); //buttonLedWidget1 function called every 500ms
      }

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

      October 24, 2018 at 8:41 PM
  • Bello Isaac

    I actually did all required and it works perfectly, I can now control my home appliances from anywhere. Many thanks for your time Sharat

    November 1, 2018 at 12:18 PM
    • Sharath

      Awesome! Can you tell what problem that you faced and how did you solved. It will help others too.

      November 2, 2018 at 10:54 AM
      • Jagadeesh

        Sir ,when the current off the all lights are off and another case when current off all lights on .you can charge the code pls

        November 30, 2019 at 10:56 PM
  • Krishna Singh

    Sir i want to ask
    Which WIFI password i have to enter in the CODE
    Please tell me.
    I dont have h wifi router installed at my home so please tell me .
    How to connect nodemcu to my blynk app.

    Help me please…..
    Thank you

    November 1, 2018 at 9:36 PM
    • Sharath

      You can turn on ‘Wi-Fi Hotspot’ on your mobile phone and enter that credentials and use it. Anyway you are going to use the Blynk App on your smartphone, so you can use the same mobile’s hotspot. But the connected hotspot should be in its Wi-Fi Range with NodeMCU.

      November 2, 2018 at 10:44 AM
  • Rahul

    Hello,
    I have done all the above connections and have successfully turned on a LED.
    But, when I try to use a relay, the output bulb doesn’t glow.
    The LED on the relay board does turn ON, but the bulb doesn’t show any changes.
    The bulb stays ON when I connect to the NC port, and stays OFF when I connect to the NO port.
    I’ve done the exact some connection as above.
    Please help me, I’m losing my mind over this.

    December 29, 2018 at 9:42 AM
    • Sharath

      The relay has 3 terminals,
      1 NO (Normally Open. Eg. a disconnected wire)
      1 COM (Common. Eg a terminal of the power supply, say Negative)
      1 NC (Normally Closed, Eg The COM (Negative) and this terminal are contacted together in idle state).

      Now positive end of the power supply to be connected directly to the light.
      The other end (-ve) from light should be connected to the NO Terminal of relay.
      The negative from the battery should be connected to COM of Relay.

      Think of relay as a switch that connects two broken wires together. In place of negative terminal you cut it and join it in COM and NO.

      Try switching it in both NO and NC Connections even if the light is ON, try to turn off.
      Check you can hear the relay switching sound happens.
      Check the Bulb is working properly in direct power supply.

      January 1, 2019 at 1:01 PM
  • Jeyashree

    Hu ,,I am a basic learner of nodemcu so pls kindly explain me how to get aur token and network name and ssid

    January 1, 2019 at 3:16 PM
    • Sharath

      On the Blynk app on your android phone, click the ‘Gear Icon’ on the top. Inside that, you can see ‘Auth tokens’, either you can send that tokens to your email or copy it to the clipboard and then send it via WhatsApp or SMS. Sending it to email and copy-pasting to the code seems to be a preferred method.

      Regarding the network name,ssid – It is just your Wi-Fi Username (SSID) and Password. If you don’t have a Wi-Fi Router, then you can turn on Wi-Fi hotspot on your mobile and put its username and password.

      January 2, 2019 at 9:48 AM
      • Jagadeesh

        Sir ,when the current off the all lights are off and another case when current off all lights on .you can charge the code pls

        November 30, 2019 at 10:58 PM
  • Aqeel_mughal

    Hello Dear:
    I want to ask you how to increase Blynk battery in free and one more thing need your help I am working on it to control the all devices actually we make a model and then perform action . its really help me but how to control the fan speed and motors too

    January 31, 2019 at 2:30 PM
    • Sharath

      We can’t increase the battery for free. Before it was cheaper actually now it is a little higher. I think that 1000+1000 is more sufficient that you already got some free points. For speed control, there is no existing controller right now for AC appliances. Either you need to use a stepper/servo on the Fan speed control knob with a belt and program it or some switching circuit (it might be bulky and costlier too).

      January 31, 2019 at 7:16 PM
  • Sivaprakash B

    How to bypass the automation circuit if I need to manually control the appliances through the switchboard.

    February 1, 2019 at 3:19 AM
  • Sanjana sharma

    How to connect “phase via common terminal ” and “neutral”?

    February 13, 2019 at 8:05 PM
  • Sanjana k

    can you tel me how use slider to control fan using bylnk app ? please .

    February 14, 2019 at 9:48 AM
    • Sharath

      You can’t control an AC Fan speed using existing hardware. Only smaller DC Motors can be controlled using a PWM Controller.

      February 14, 2019 at 11:20 AM
  • Anil kumar

    hello…..
    i need to control the appliances using blynk and also with the google commands, please can u provide the program for this…..

    February 17, 2019 at 8:09 AM
  • anirudh chawla

    Could not write build preferences file
    java.io.FileNotFoundException: C:\Users\ASMITA\AppData\Local\Temp\build924115131595931435.tmp\NodeMCU.cpp (The system cannot find the path specified)
    at java.io.FileOutputStream.open0(Native Method)
    at java.io.FileOutputStream.open(FileOutputStream.java:270)
    at java.io.FileOutputStream.(FileOutputStream.java:213)
    at java.io.FileOutputStream.(FileOutputStream.java:162)
    at processing.app.debug.Compiler.preprocess(Compiler.java:1268)
    at processing.app.debug.Compiler.preprocess(Compiler.java:1228)
    at processing.app.debug.Compiler.compile(Compiler.java:358)
    at processing.app.debug.Compiler.build(Compiler.java:121)
    at processing.app.Sketch.build(Sketch.java:1109)
    at processing.app.Sketch.build(Sketch.java:1084)
    at processing.app.Editor$BuildHandler.run(Editor.java:1955)
    at java.lang.Thread.run(Thread.java:745)
    java.lang.NullPointerException
    at processing.app.debug.Compiler.adviseDuplicateLibraries(Compiler.java:477)
    at processing.app.debug.Compiler.build(Compiler.java:128)
    at processing.app.Sketch.build(Sketch.java:1109)
    at processing.app.Sketch.build(Sketch.java:1084)
    at processing.app.Editor$BuildHandler.run(Editor.java:1955)
    at java.lang.Thread.run(Thread.java:745)

    sir its showing this error…what to do for this

    February 24, 2019 at 9:02 AM
    • Sharath

      Just change the board from current to any other board and compile once. Then select again NodeMCU and try upload. It seems your chached file is cleared. So if u change it to some other board and back to NodeMCU it will rebuild the file again.

      February 24, 2019 at 9:29 AM
  • pravesh jain

    I’m doing the same as you have shown in your article but I’m getting “wasn’t online yet” problem.

    February 27, 2019 at 2:44 PM
    • Sharath

      Are you using the correct SSID, Password and Authentication Token? To check if you are connected to Wi-Fi use IP Scanner for Android (Advanced IP Scanner for PC) and search for networks. If you can find the nodeMCU related manufacturer name, then the problem is with Blynk Server (it might have down).

      Also note that, you have a proper Internet Connection.

      February 27, 2019 at 2:50 PM
  • Anil kumar

    Arduino: 1.8.8 (Windows 7), Board: “NodeMCU 1.0 (ESP-12E Module), 80 MHz, Flash, Disabled, 4M (no SPIFFS), v2 Lower Memory, Disabled, None, Only Sketch, 115200”

    new_mar04a:3:9: error: #include expects “FILENAME” or

    #include

    ^

    exit status 1
    #include expects “FILENAME” or

    This report would have more information with
    “Show verbose output during compilation”
    option enabled in File -> Preferences.

    March 4, 2019 at 1:10 PM
    • Sharath

      You must have ESP8266 library and Blynk library properly installed.
      The header file should have mentioned on the top with proper open and closing symbols.
      #include
      #include

      Also check the double quotes are in text editor format (“”). In MS Office or Formatted webpages it adds stylings like curved quotes. It is a different unicode character that the programmable one. Try to check that quotes too

      March 4, 2019 at 2:08 PM
  • jaipranesh

    i need to on two bulb using relay i need that digital read program

    March 5, 2019 at 8:01 PM
    • Sharath

      You don’t need any program changes for this, you can create a button widget and mention the pin (Slide to Switch for ON/OFF Switch) on the Blynk App.

      March 6, 2019 at 10:39 AM
  • anut

    can you teach me how to programing blynk local server to board. i’ved done try to program my local server to board but it cant connect to local server ( IP address). can you help me? ive put my program below for your reference.

    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”, 80);
    //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8080);
    }

    March 7, 2019 at 11:55 AM
  • anut

    I’ve seen that video but I tried to use it in window 10. I managed to make blynk server but when I tried to program to board, my blynk server can not connect to board. why? can you teach me?

    March 8, 2019 at 1:04 PM
    • Sharath

      In the above code you mentioned. You are using the Wi-Fi mode only. You have to comment it and uncomment the IPAddress line with your IP Address.

      Modified code here (change it to your IP that was set in Blynk app)

      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”, 80);

      Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8080); //uncommented code
      }

      March 9, 2019 at 11:37 AM
  • anut

    okay, thank you for your information. i still have a question. how to use local server to ifttt. im new to this …could you explain me in detail. how to make webhook request to my local server and which url should i use …my current local server url is 192.168……….

    March 11, 2019 at 9:55 AM
    • Sharath

      It won’t work with IFTTT probably. Because, when you trigger with local IP it actually triggers the local IP of that server only. So it won’t work. You need to find an alternative solution like ngrok, and port forward (not safe) your router with ngrok with its given IP.

      March 11, 2019 at 12:48 PM
  • naveen koreddi

    THANK YOU SO MUCH sir
    i followed all the above steps….
    without any error i got a good result….
    but i have some doubts sir so can u send your contact number to my mail…..

    March 14, 2019 at 11:28 AM
  • NAVEEN KOREDDI

    sir if i want to control this with more than one mobile then how it is possible

    March 14, 2019 at 10:43 PM
    • Sharath

      In somewhere in blynk website they told you can use the same username and password for multiple devices. Also, they have some pricing plans to make it as an app as well as publish in Playstore. Kindly check blynk official website and forum for more details.

      March 15, 2019 at 1:43 PM
  • Sneha

    We are not getting software how to do…

    March 15, 2019 at 11:43 PM
  • dengdang

    i got problem for my coding. our buzzer still on if we dont on the buzzer and our notfucation we ddnt receive.

    March 23, 2019 at 8:42 PM
    • Sharath

      You can just alter the terminals of the buzzer and check.

      For notifications, you have to use this function

      Blynk.notify(“Hey, You have a notification!”); //Display on Blynk app

      Other Notifications:
      Blynk.email(“[email protected]”, “Subject”, “Your message goes here”); //For Email Notification
      Blynk.tweet(“Hey! My NodeMCU can tweet now!”); //For twitter notification

      March 24, 2019 at 9:29 AM
  • MOHITP

    I new to software and I have downloaded blynk application with mobile from apple store but unable to join with wifi network. what to do ?

    April 9, 2019 at 5:01 PM
    • Sharath

      Blynk can work with your mobile internet also?

      The Wi-Fi needed for here is for NodeMCU. So we are creating a portable hotspot (Wi-Fi Tethering). Normally you can use your Home network too.

      April 10, 2019 at 2:06 PM
  • MOHITP

    Thanks dear Sharath for your guidence. I am learner and would like to ask you, How to confirm blynk application is working ok and giving command to NodeMCU ? ( communication between blynk and NodeMCU).When I touch button on screen it goes into setting of pin and no changes in output of NodeMCU. ( program uploading and wi-fi network name,password with token inserted in program). Also tell me how to check functioning of uploaded program with NodeMCU?

    April 24, 2019 at 4:22 PM
    • Sharath

      In step 6, you can able to see the Cog Wheel,+ icon and Play Icon on the top right. It denotes it is in editor mode. If you touch any pins it goes to edit the pin numbers.

      You have to click the Play icon to make it Live Mode. This screenshot you can see at the last step. On this, a chip symbol with red mark denotes the NodeMCU is not connected to the Server. If you click on that chip icon, it shows you the last connected date, time and status of the NodeMCU as well as ONLINE/OFFLINE.

      If you want to check the function of the program open serial monitor in the Arduino IDE, It shows the status and IP address and all.

      April 24, 2019 at 4:53 PM
  • MOHITP

    Thanks sir,
    After making play button on, red dot appears and message displays ” wasn’t online yet”. what is the problem ?

    Also serial monitor after uploading successfully remains blank. please guide.

    regards,

    April 25, 2019 at 11:08 PM
    • Sharath

      In the code, you have to change your Wi-Fi network name its password, and the Authentication token you got in email for that project dashboard properly. Wi-Fi must have an internet connection. If the NodeMCU is connected to the blynk server, the serial monitor displays a big blynk logo and shows as connected.

      April 26, 2019 at 10:19 AM
  • MOHITP

    Sir,
    I have already done what you told, but not getting result. Also no logo at serial monitor. what to check and how to overcome ?

    April 26, 2019 at 8:24 PM
    • Sharath

      Just verify all the steps once. I tested it in the evening nly.

      April 26, 2019 at 10:07 PM
  • MOHITP

    Thanks sir. I am having two problems. One after downloading Blynk application in ios system after red dot appears on top with ” wasn’t online yet ” means not able to join online with wifi. what may be problem? Other is after successful uploading code with NODEmcu, serial monitor remains blank with box on top and curser.( right top corner shows “SEND”. what can be done sir ?

    April 28, 2019 at 6:24 PM
  • MOHITP

    sir I tried Blynk application with both ios and Android based mobile but not succeeded. How to test both separately i.e blynk application with phone and NodeMcu function working ?
    regards,

    April 28, 2019 at 6:42 PM
  • zakwan

    Sir, can you show me how to insert my coding in coding blynk? i want it to run this coding using push button in blynk. Below are my coding.
    Regards,

    #define FLOAT_SENSOR 2 // the number of the pushbutton pin
    int solenoid = 22; //pin solenoid valve to drain water out
    int Liquid_level = 0;
    int waterlevel = 5;
    int pump = 21;
    int perismatic = 23;

    void setup()
    {

    pinMode(solenoid,OUTPUT);
    pinMode(waterlevel,INPUT);
    pinMode(pump,OUTPUT);
    pinMode(FLOAT_SENSOR, INPUT_PULLUP);
    pinMode(perismatic,OUTPUT);
    }
    void loop()
    {
    do{
    digitalWrite(solenoid, HIGH); // Turn on the solenoid valve
    }while(digitalRead(5) == HIGH);
    digitalWrite(solenoid, LOW);

    do{
    digitalWrite(solenoid, LOW);
    digitalWrite(pump, HIGH);

    }while(digitalRead(FLOAT_SENSOR) == LOW && digitalRead(FLOAT_SENSOR)==LOW);

    digitalWrite(solenoid, LOW);
    digitalWrite(pump, LOW);
    digitalWrite(perismatic, HIGH);
    delay(5000);
    digitalWrite(perismatic, LOW);

    while(1){}
    }

    May 1, 2019 at 8:18 PM
    • Sharath

      Fine but I didn’t understand what you are saying. Does it need to display sensor values or you need to control solenoid or any other?

      May 2, 2019 at 2:29 PM
  • Ranjith

    Hello,
    I have done all the above connections and have successfully turned on a LED.
    But, when I try to use a relay, the output bulb doesn’t glow.

    How to fix it pls reply

    May 31, 2019 at 7:33 AM

Leave a Reply

Back to Blog