loading

Update (07.02.2017):

I've updated the Windows-Version of the program to control your ESP8266. I've added a "Small Window"-Mode ("SW"): It will dock a micro-version of the program above your taskbar on the left side so that you can access the relays more easily while you work with other programs. It will also be in the foreground all the time.

Hello, and welcome to my first Instructable!

What will this Instructable show me?

I will show you in this Instructable how to control a relay board with 4 relays -or even more- with an Android-Smartphone or a Windows-PC. If you use 4 Relays or less you can use an App for Android or Windows of mine. If you want to use more, you have to continue to develop the code yourself. So, you will get the code I developed yet.

What do I need?

You will need an ESP8266-Module. I'll use a D1 Mini version of the ESP8266 and I recommend to use this one or a similar too because I don't know I you can program other versions of the ESP8266 as easy as with a D1 Mini. You will also need, of course, a relay module like you see in the pictures.

I bought those:

http://ebay.eu/2iQLv3s - Relay Module with 4 relays

http://ebay.eu/2iQUwtr - D1 Mini NodeMCU Module

Step 1: Let's Get Started!

Prepare the ESP8266-Module:

First, download the following files to your Windows-Computer:

NodeMCU-Flasher: https://github.com/nodemcu/nodemcu-flasher

ESPlorer (is attached as ZIP-File down)

init.lua (is attached down)

Flashing the ESP8266-Module:

-Connect the ESP8266-Module with your Computer via USB and wait till all drivers are installed (your system will need a serial-to-USB-driver).

-Open ESP8266Flasher.exe from the NodeMCU-Flasher, select the correct COM-port and click "Flash". This could take a while.

Upload the script to the ESP8266-Module:

-Open ESPlorer. You will need Java to open it.

-Select the correct COM-Port in the right tab on the top and click "Open". Don't worry if it says that it can't autodetect the firmware.

-The right gray windows will be a serial monitor, the left one a code editor. Open the init.lua file.

(It should look like this on the screenshot)

-Enter your Wifi-SSID and your Wifi-Password.

-Press the "Upload"-Button.

Step 2: Something About the Code...

The programs:

You can just download the "EDR.zip"-File for Windows and the "EDR.apk"-File for Android.

(This part is about how much relays you need. If you want to use 4 or less, you can skip this step.)


About init.lua:

Part of the code for the relays:

________________________________________________________________

if(_GET.pin == "ON")then
_on = " selected=true"

gpio.write(1, gpio.HIGH)

elseif(_GET.pin == "OFF")then

_off = " selected=\"true\""

gpio.write(1, gpio.LOW)

elseif(_GET.pin == "ON2")then

_on = " selected=true"

gpio.write(2, gpio.HIGH)

elseif(_GET.pin == "OFF2")then

_off = " selected=\"true\""

gpio.write(2, gpio.LOW)

elseif(_GET.pin == "ON3")then

_on = " selected=true"

gpio.write(3, gpio.HIGH)

elseif(_GET.pin == "OFF3")then

_off = " selected=\"true\""

gpio.write(3, gpio.LOW)

elseif(_GET.pin == "ON4")then

_on = " selected=true"

gpio.write(4, gpio.HIGH)

elseif(_GET.pin == "OFF4")then

_off = " selected=\"true\""

gpio.write(4, gpio.LOW)

end

________________________________________________________________

I am sure, you can find a scheme:

for every Realy there is this block of code:

elseif(_GET.pin == "ON_NUMBER_OF_RELAY")then
_on = " selected=true"

gpio.write(GPIO_NUMBER, gpio.HIGH)

elseif(_GET.pin == "OFF_NUMBER_OF_RELAY")then

_off = " selected=\"true\""

gpio.write(GPIO_NUMBER, gpio.LOW)

Only one more thing. On the beginning of the code is standing:

gpio.mode(1, gpio.OUTPUT)
gpio.mode(2, gpio.OUTPUT)
gpio.mode(3, gpio.OUTPUT)
gpio.mode(4, gpio.OUTPUT)

So will also have to add:

gpio.mode(GPIO_NUMBER.OUTPUT)

I am sure you can handle this ;-)

About the source code of my Windows-Program:

If you want to edit this, you will have to know something about C# and you have to have a Version of Visual Studio 2015 or compatible. I'll attach the project as ZIP-File too (EDR.zip).

About the Android-APP:

If you want the Android-App, you will need the AppInventor2. There is a free online version of it. You can open the attached "EDR.aia"-File there and edit it as you want.

Step 3: The Ending....

So, that's all.

If you have some ideas for this project, just commit it.

-Have fun! :D

hello<br>I am seeing that u r using ESP 8266-12 right!!the firmware u have used to install the Lua script in esp-12 will it work on esp8266-01???
<p>Hi,</p><p>I think it should work too. I'm not totally sure, but it seems like the only different is the pinout and design.<br>But anyway, I won't take any warranty ;-) </p>
<p>Hi. I made this and it's working. But how can access from internet, not from local wireless?</p>
<p>https://<a href="https://portforward.com/" rel="nofollow">portforward</a>.com/</p><p>Can help you config your router for your webserver. </p><p>Sincerely,</p><p><a href="http://www.RLRuby.com" rel="nofollow">www.RLRuby.com</a></p>
To Alaccess it outside your lokal network you need a &quot;special&quot; router like Fritz!Box. Your Router needs a Kind of Domain, and if you open a connection to the Domain (e.g. via a browser) the router is forwarding the request to the local device (e.g. your Esp8266). The Problem: Most router don't support this. So you have to look it up for your own router, I'm sorry. If you get it work, let me know ;-)
*access
Cool.

About This Instructable

5,384views

141favorites

License:

Bio: I am a 16 years old boy living in Germany near Ludwigsburg. I'm very interested in programming and building electronic circuits. Another hobby of ... More »
More by HeinzA1:ESP8266 Relay-control 
Add instructable to: