Control some 5Volt leds with mqtt
Moderators: grovkillen, Stuntteam, TD-er
Control some 5Volt leds with mqtt
Maybe its easy but I a pretty new to ESP EASY.
I have some platsic models I want to put some 5 Volt led into.
Planning to use a presence sensor and when the sensor gets active it sends a MQTT message that turn leds on.
Can that be done ?
I have some platsic models I want to put some 5 Volt led into.
Planning to use a presence sensor and when the sensor gets active it sends a MQTT message that turn leds on.
Can that be done ?
- dynamicdave
- Normal user
- Posts: 258
- Joined: 30 Jan 2017, 20:25
- Location: Hampshire, UK
Re: Control some 5Volt leds with mqtt
The ESP8266 and Wemos D1 Mini are +3V3 devices - so please don't connect +5V to them.
You can use a transistor to buffer the ESP8266 to the 5V LEDs or even a relay or a level shifter.
Small single LEDs normally run off of 1.6V, so you could think about having two in series with a suitable current limiting resistor (to protect the output of the ESP8266).
Another idea would be to use some NeoPixels either in a string or individually inside your model.
ESP-Easy has a device driver for NeoPixels so driving them in very easy.
Let me know if you need more information.
You can use a transistor to buffer the ESP8266 to the 5V LEDs or even a relay or a level shifter.
Small single LEDs normally run off of 1.6V, so you could think about having two in series with a suitable current limiting resistor (to protect the output of the ESP8266).
Another idea would be to use some NeoPixels either in a string or individually inside your model.
ESP-Easy has a device driver for NeoPixels so driving them in very easy.
Let me know if you need more information.
Re: Control some 5Volt leds with mqtt
Thanks for your answer.
The models I make is scale 1/24 so I will probaly use 3mm leds as maximum.
I have just finished a Scania scale 1/14 and used arduino and 5mm leds.
But in my homeautoamtion I use 6-7 ESP8266 and they are great with there small size and WLan.
Did a quick search for neopixel and they look pretty expensive to ordinarie leds.
In this model I am buling now I will appox want 10 leds.
Can I use like 5 output pins with 2 leds on each to get it to work ?
The models I make is scale 1/24 so I will probaly use 3mm leds as maximum.
I have just finished a Scania scale 1/14 and used arduino and 5mm leds.
But in my homeautoamtion I use 6-7 ESP8266 and they are great with there small size and WLan.
Did a quick search for neopixel and they look pretty expensive to ordinarie leds.
In this model I am buling now I will appox want 10 leds.
Can I use like 5 output pins with 2 leds on each to get it to work ?
- dynamicdave
- Normal user
- Posts: 258
- Joined: 30 Jan 2017, 20:25
- Location: Hampshire, UK
Re: Control some 5Volt leds with mqtt
I bought three of these RGB strips for GBP 4.00 from Banggood in China.
https://www.banggood.com/3Pcs-CJMCU-8-B ... rehouse=CN
One of the great things about NeoPixels is you can control the amount of RGB colour in the each one individually or you can send a command so they all react together.
Or you could buy a pack of ten individual Neopixesls for less than GBP 2.00
https://www.banggood.com/10Pcs-DC-5V-3M ... rehouse=CN
https://www.banggood.com/3Pcs-CJMCU-8-B ... rehouse=CN
One of the great things about NeoPixels is you can control the amount of RGB colour in the each one individually or you can send a command so they all react together.
Or you could buy a pack of ten individual Neopixesls for less than GBP 2.00
https://www.banggood.com/10Pcs-DC-5V-3M ... rehouse=CN
- dynamicdave
- Normal user
- Posts: 258
- Joined: 30 Jan 2017, 20:25
- Location: Hampshire, UK
Re: Control some 5Volt leds with mqtt
First of all - you can't use two normal 5mm LEDs in series (driven from the Wemos +3.3V line) as the forward voltage drop across each LED is approx 1.8V.
So two in series is 3.6V which means they won't turn on.
Here are a couple of very quick and VERY rough sketches for you.
One shows two LEDs in series driven from +5V using a transistor.
The other circuit is useful if you want to operate two LEDs of different colour (like a traffic light).
The upper LED comes on when the ESP8266 outputs a logic '0', the other one comes on when the ESP8266 outputs a logic '1'.
Hope this helps.
So two in series is 3.6V which means they won't turn on.
Here are a couple of very quick and VERY rough sketches for you.
One shows two LEDs in series driven from +5V using a transistor.
The other circuit is useful if you want to operate two LEDs of different colour (like a traffic light).
The upper LED comes on when the ESP8266 outputs a logic '0', the other one comes on when the ESP8266 outputs a logic '1'.
Hope this helps.
Last edited by dynamicdave on 21 Aug 2019, 16:24, edited 3 times in total.
- dynamicdave
- Normal user
- Posts: 258
- Joined: 30 Jan 2017, 20:25
- Location: Hampshire, UK
Re: Control some 5Volt leds with mqtt
Here's a link to a project I gave to my IoT students about using NeoPixels.
https://discourse.nodered.org/t/control ... ixels/4560
http://resources-area.co.uk/node-red-fl ... pixels.pdf
https://discourse.nodered.org/t/control ... ixels/4560
http://resources-area.co.uk/node-red-fl ... pixels.pdf
Re: Control some 5Volt leds with mqtt
Wow !! Thanks for a great answer.
I Will try that.
But how so I set a pin like Arduino to Hugh/low with mqtt
I Will try that.
But how so I set a pin like Arduino to Hugh/low with mqtt
- dynamicdave
- Normal user
- Posts: 258
- Joined: 30 Jan 2017, 20:25
- Location: Hampshire, UK
Re: Control some 5Volt leds with mqtt
I don't use Arduino, so I'd have to look it up the same as you.
I use Node-RED and MQTT (Mosquitto).
All my ESP8266s (well they are Wemos D1 Mini devices really) talk to Node-RED running on a Raspberry Pi (which is the sort of server on the system) via MQTT, and Node-RED sends commands to the Wemos also via MQTT.
Let me know if this is anything like your set-up, and if it is I can send you some screenshots of a Node-RED flow and sections of Java-Script.
To opearte a set of LEDs from Node-RED via MQTT is very simple (I'm assuming you are running ESP-Easy in the ESP8266).
I use Node-RED and MQTT (Mosquitto).
All my ESP8266s (well they are Wemos D1 Mini devices really) talk to Node-RED running on a Raspberry Pi (which is the sort of server on the system) via MQTT, and Node-RED sends commands to the Wemos also via MQTT.
Let me know if this is anything like your set-up, and if it is I can send you some screenshots of a Node-RED flow and sections of Java-Script.
To opearte a set of LEDs from Node-RED via MQTT is very simple (I'm assuming you are running ESP-Easy in the ESP8266).
Re: Control some 5Volt leds with mqtt
I also have wemos d1 minis. Running ESP Easy.
I have node red running on a Ubuntu.
I also have a Homey (Homey.com) that Connects all my automation units.
What i need is the ”message” i that ESP reads for turning leds on and off
I have node red running on a Ubuntu.
I also have a Homey (Homey.com) that Connects all my automation units.
What i need is the ”message” i that ESP reads for turning leds on and off
- dynamicdave
- Normal user
- Posts: 258
- Joined: 30 Jan 2017, 20:25
- Location: Hampshire, UK
Re: Control some 5Volt leds with mqtt
Here are some screen-shots that might help.
It's a very simple test flow to turn on/off an LED connected to pin 15 (D8) on the Wemos.
You can obviously change this to use other pins.
D6 (pin 12) is one of my favourite pins I use.
In my set-up the MQTT broker is running on a Raspberry Pi on 192.168.1.147:1883 with Node-RED on 192.168.1.147:1880
The Wemos is on 192.168.1.41 and has a Unit Name of node41 and Unit Number of 41.
All my Wemos Di Minis have fixed addresses on the network as I so many to control.
It's a very simple test flow to turn on/off an LED connected to pin 15 (D8) on the Wemos.
You can obviously change this to use other pins.
D6 (pin 12) is one of my favourite pins I use.
In my set-up the MQTT broker is running on a Raspberry Pi on 192.168.1.147:1883 with Node-RED on 192.168.1.147:1880
The Wemos is on 192.168.1.41 and has a Unit Name of node41 and Unit Number of 41.
All my Wemos Di Minis have fixed addresses on the network as I so many to control.
- Attachments
-
- ScreenShot068.png (32.23 KiB) Viewed 17081 times
Re: Control some 5Volt leds with mqtt
Once again a very good answer
I have my Wemos connected to my Mosquitto and they are sending temp/hum and are importing (mqtt import) some messages from my mosquitto.
I then show them on a oled display.
So lets see if I got this right
1. I connect 2 leds to pin 15 (D8) on my Wemos
2. Post a mqtt message on my mosquitto with /%MY_UNITS_NAME%/gpio/15
Then the led is toggling between on and off depending on its last state of led or can I send on/off commands ?
Here is a picture of my current config of my ESP MQTT config.


I have my Wemos connected to my Mosquitto and they are sending temp/hum and are importing (mqtt import) some messages from my mosquitto.
I then show them on a oled display.
So lets see if I got this right
1. I connect 2 leds to pin 15 (D8) on my Wemos
2. Post a mqtt message on my mosquitto with /%MY_UNITS_NAME%/gpio/15
Then the led is toggling between on and off depending on its last state of led or can I send on/off commands ?
Here is a picture of my current config of my ESP MQTT config.
- dynamicdave
- Normal user
- Posts: 258
- Joined: 30 Jan 2017, 20:25
- Location: Hampshire, UK
Re: Control some 5Volt leds with mqtt
In my first screen-shot I'm using two 'inject' nodes that inject a number... 0 and 1 into the MQTT-Out node.
Your mqtt config is fine PROVIDED the format of the topic matches the MQTT nodes in Node-RED.
I've given up using the forward slash at the start of the topic as it's not recommended in the MQTT spec.
PS:
When you say you are using two LEDS, how are they wired ???
Your mqtt config is fine PROVIDED the format of the topic matches the MQTT nodes in Node-RED.
I've given up using the forward slash at the start of the topic as it's not recommended in the MQTT spec.
PS:
When you say you are using two LEDS, how are they wired ???
Re: Control some 5Volt leds with mqtt
Just a small comment. It's best practice NOT to have a leading '/' when using MQTT. It should be changed in the default settings of ESPEasy.
Re: Control some 5Volt leds with mqtt
WIll change the /
I would prefer to send MQTT message with Homey.
So how can that message look like.
This how a another message is sent with Homey
WDtemp, rain etc is a variable coming from my weather station
I would prefer to send MQTT message with Homey.
So how can that message look like.
This how a another message is sent with Homey
WDtemp, rain etc is a variable coming from my weather station
- dynamicdave
- Normal user
- Posts: 258
- Joined: 30 Jan 2017, 20:25
- Location: Hampshire, UK
Re: Control some 5Volt leds with mqtt
Sorry I have no idea as I've NOT heard of Homey until you mentioned it.
You might find someone on this forum that has experience of how to use it.
Good luck from David.
You might find someone on this forum that has experience of how to use it.
Good luck from David.
Re: Control some 5Volt leds with mqtt
I know how to publish messages the only thing I need is the message.
Something like this
MY_UNITS_NAME/gpio/15/on
or
MY_UNITS_NAME/gpio/15/off
Something like this
MY_UNITS_NAME/gpio/15/on
or
MY_UNITS_NAME/gpio/15/off
- dynamicdave
- Normal user
- Posts: 258
- Joined: 30 Jan 2017, 20:25
- Location: Hampshire, UK
Re: Control some 5Volt leds with mqtt
Just guessing... but I would try a topic of.... YOUR_UNITS_NAME/gpio/15
and a Message of.... 0 or 1 or maybe "0" or "1"
Have you tried looking to see if there are any tutorials on the 'Homey' website ??
Best of luck.
and a Message of.... 0 or 1 or maybe "0" or "1"
Have you tried looking to see if there are any tutorials on the 'Homey' website ??
Best of luck.
- dynamicdave
- Normal user
- Posts: 258
- Joined: 30 Jan 2017, 20:25
- Location: Hampshire, UK
Re: Control some 5Volt leds with mqtt
Hi to @Quart
Just checking... Did you manage to get MQTT working to operate your LEDs ??
Just checking... Did you manage to get MQTT working to operate your LEDs ??
Re: Control some 5Volt leds with mqtt
@dynamicdave yes it works, thanks for your help !
Have just tested with one led at the moment. Will try your setup above on a breadboard this weekend.
Testeded flow in my Homey, when someone press doorbell the led on ESP8266 turns on, wokred perfect
Have just tested with one led at the moment. Will try your setup above on a breadboard this weekend.
Testeded flow in my Homey, when someone press doorbell the led on ESP8266 turns on, wokred perfect
- dynamicdave
- Normal user
- Posts: 258
- Joined: 30 Jan 2017, 20:25
- Location: Hampshire, UK
Re: Control some 5Volt leds with mqtt
Really pleased to hear you got it working.
The format you ended up with is very similar to what I would send from Node-RED via MQTT to a Wemos D1 Mini.
Have a great weekend.
Cheers from David.
PS:
What you could try next is... sending a message to your mobile phone using 'Telegram' telling you someone has pressed your doorbell.
The format you ended up with is very similar to what I would send from Node-RED via MQTT to a Wemos D1 Mini.
Have a great weekend.
Cheers from David.
PS:
What you could try next is... sending a message to your mobile phone using 'Telegram' telling you someone has pressed your doorbell.
Re: Control some 5Volt leds with mqtt
Must say that Homey is a great product. Can connect and use a lot of things and get them to work togheter.
I got a push notice when someone push the doorbell, even got a mail with a picture taken from a webcam
Visit my webpage and see weahterdata and electric cosnsumtion etc
www.sundshult.se
I got a push notice when someone push the doorbell, even got a mail with a picture taken from a webcam

Visit my webpage and see weahterdata and electric cosnsumtion etc
www.sundshult.se
- dynamicdave
- Normal user
- Posts: 258
- Joined: 30 Jan 2017, 20:25
- Location: Hampshire, UK
Re: Control some 5Volt leds with mqtt
Wooooo - that's impressive.
Looks like you are collecting a lot of data.
Thanks for sharing your work.
Looks like you are collecting a lot of data.
Thanks for sharing your work.
Who is online
Users browsing this forum: No registered users and 21 guests