Want to add two sketches in one

Dear Team,

I have two individual and seperate sketches for esp8266 d1 mini

  1. To make a WIFI connectivity and Internet status monitor device (which will have 2 LED`s and will blink in disconnected status of both the functions separately) and other is for driving 6 channel relay for smart switches using SINRIC.

  2. Both these sketches has no link in between them, but i want to load both these sketches into same microcontoller to save cost, efforts and space.

  3. I am attaching both the codes if any one can combine and make a single code for me it will solve the purpose. I am trying from last 3 days and had no luck hence asking for help, I am a beginner in sketches.

Sketches are as attached.

6 Channel smart switch.txt (6.55 KB)

Netwok status monitor.txt (2.86 KB)

Why does nobody ever Read this before posting a programming question.

Follow this simple rule- there can only be one setup() and one loop() function.

Try to resolve the two sketches then come back here for assistance. Show what you have tried and what compile or operating errors you are getting.

I am a beginner in sketches.

I would recommend you try a couple of simple examples first. Go to

File -> Examples -> 01.Basics
File -> Examples -> 02.Digital

Open a couple of them compile and download them to your board and then start with some small modifications. Try to understand every single line of code. Many have just a few lines. The Arduino Reference can help you with simple explanations of basic functions.


If you have a question, read the "How to post .." and ask. You will be merging sketches in no time. :slight_smile:

Dear Sir,

Thanks for taking efforts to read my post, I have tried to combine both the sketches keeping in mind that there shall be only 1 void setup and void loop respectively. Attached is the code which i tried but didn’t work.Let me know if what best can we do. Thank you so much.

combined sketch.txt (8.45 KB)

Why does nobody ever Read this before posting a programming question.

Read this before posting a programming question.
scroll down to topic 7 and start reading from here

combining these two sketches is a quite demanding task.
For doing it yourself you need quite some knowledge of how programs work.
If you are not willing to invest at least 20 to 30 hours learning how the different commands work
you should google for a ready to use code that does both things and beeing satisfied with the functionlity of that code.

If you are not satisfied there is no way around learning the basic principles of how commands like "while" etc work

As you are a newbee I recommend reading this tutorial: Arduino Programming Course Contents

It is very easy to understand. It has the right mixture between writing about fundamental things and going ahead to get you going. You have the choice:

  • trying to write code with very little knowledge encountering all kinds of problems: compiler-errors, code behaves different than you expected etc which will make you spending time scratching yor head

  • or spending time reading an easy to understand tutorial to gain knowledge that will enable to write code that (most of the time) works

It is completely OK to ask questions here in the forum. Whenever you have posted a question. In the meantime waiting for an answer you could go on reading some lines in this tutorial instead of just waiting or scratching your head about your own code.

best regards Stefan