Control some 5Volt leds with mqtt

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
Quart
Normal user
Posts: 45
Joined: 16 Jul 2019, 10:08
Location: Sweden
Contact:

Control some 5Volt leds with mqtt

#1 Post by Quart » 20 Aug 2019, 20:12

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 ?

User avatar
dynamicdave
Normal user
Posts: 257
Joined: 30 Jan 2017, 20:25
Location: Hampshire, UK

Re: Control some 5Volt leds with mqtt

#2 Post by dynamicdave » 21 Aug 2019, 14:11

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.

Quart
Normal user
Posts: 45
Joined: 16 Jul 2019, 10:08
Location: Sweden
Contact:

Re: Control some 5Volt leds with mqtt

#3 Post by Quart » 21 Aug 2019, 14:57

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 ?

User avatar
dynamicdave
Normal user
Posts: 257
Joined: 30 Jan 2017, 20:25
Location: Hampshire, UK

Re: Control some 5Volt leds with mqtt

#4 Post by dynamicdave » 21 Aug 2019, 15:24

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

User avatar
dynamicdave
Normal user
Posts: 257
Joined: 30 Jan 2017, 20:25
Location: Hampshire, UK

Re: Control some 5Volt leds with mqtt

#5 Post by dynamicdave » 21 Aug 2019, 16:14

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.
twin_leds.jpg
twin_leds.jpg (28.52 KiB) Viewed 14726 times
LEDS_on_off.jpg
LEDS_on_off.jpg (26.03 KiB) Viewed 14726 times
Last edited by dynamicdave on 21 Aug 2019, 16:24, edited 3 times in total.

User avatar
dynamicdave
Normal user
Posts: 257
Joined: 30 Jan 2017, 20:25
Location: Hampshire, UK

Re: Control some 5Volt leds with mqtt

#6 Post by dynamicdave » 21 Aug 2019, 16:18

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

Quart
Normal user
Posts: 45
Joined: 16 Jul 2019, 10:08
Location: Sweden
Contact:

Re: Control some 5Volt leds with mqtt

#7 Post by Quart » 21 Aug 2019, 16:54

Wow !! Thanks for a great answer.

I Will try that.

But how so I set a pin like Arduino to Hugh/low with mqtt

User avatar
dynamicdave
Normal user
Posts: 257
Joined: 30 Jan 2017, 20:25
Location: Hampshire, UK

Re: Control some 5Volt leds with mqtt

#8 Post by dynamicdave » 21 Aug 2019, 17:27

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).

Quart
Normal user
Posts: 45
Joined: 16 Jul 2019, 10:08
Location: Sweden
Contact:

Re: Control some 5Volt leds with mqtt

#9 Post by Quart » 21 Aug 2019, 20:57

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

User avatar
dynamicdave
Normal user
Posts: 257
Joined: 30 Jan 2017, 20:25
Location: Hampshire, UK

Re: Control some 5Volt leds with mqtt

#10 Post by dynamicdave » 22 Aug 2019, 08:04

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.

ScreenShot071.png
ScreenShot071.png (9.18 KiB) Viewed 14646 times
ScreenShot072.png
ScreenShot072.png (9.39 KiB) Viewed 14646 times
ScreenShot069.png
ScreenShot069.png (9.56 KiB) Viewed 14646 times
ScreenShot070.png
ScreenShot070.png (26.72 KiB) Viewed 14646 times
Attachments
ScreenShot068.png
ScreenShot068.png (32.23 KiB) Viewed 14636 times

Quart
Normal user
Posts: 45
Joined: 16 Jul 2019, 10:08
Location: Sweden
Contact:

Re: Control some 5Volt leds with mqtt

#11 Post by Quart » 22 Aug 2019, 08:59

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.
mqtt.JPG
mqtt.JPG (27.29 KiB) Viewed 14630 times

User avatar
dynamicdave
Normal user
Posts: 257
Joined: 30 Jan 2017, 20:25
Location: Hampshire, UK

Re: Control some 5Volt leds with mqtt

#12 Post by dynamicdave » 22 Aug 2019, 09:02

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 ???

mrwee
Normal user
Posts: 225
Joined: 31 Aug 2016, 12:52

Re: Control some 5Volt leds with mqtt

#13 Post by mrwee » 22 Aug 2019, 09:09

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.

Quart
Normal user
Posts: 45
Joined: 16 Jul 2019, 10:08
Location: Sweden
Contact:

Re: Control some 5Volt leds with mqtt

#14 Post by Quart » 22 Aug 2019, 10:46

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
mqtt.JPG
mqtt.JPG (52.38 KiB) Viewed 14612 times

User avatar
dynamicdave
Normal user
Posts: 257
Joined: 30 Jan 2017, 20:25
Location: Hampshire, UK

Re: Control some 5Volt leds with mqtt

#15 Post by dynamicdave » 22 Aug 2019, 12:22

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.

Quart
Normal user
Posts: 45
Joined: 16 Jul 2019, 10:08
Location: Sweden
Contact:

Re: Control some 5Volt leds with mqtt

#16 Post by Quart » 22 Aug 2019, 12:44

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


mqtt.JPG
mqtt.JPG (17.04 KiB) Viewed 14583 times

User avatar
dynamicdave
Normal user
Posts: 257
Joined: 30 Jan 2017, 20:25
Location: Hampshire, UK

Re: Control some 5Volt leds with mqtt

#17 Post by dynamicdave » 22 Aug 2019, 14:40

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.

User avatar
dynamicdave
Normal user
Posts: 257
Joined: 30 Jan 2017, 20:25
Location: Hampshire, UK

Re: Control some 5Volt leds with mqtt

#18 Post by dynamicdave » 23 Aug 2019, 08:08

Hi to @Quart
Just checking... Did you manage to get MQTT working to operate your LEDs ??

Quart
Normal user
Posts: 45
Joined: 16 Jul 2019, 10:08
Location: Sweden
Contact:

Re: Control some 5Volt leds with mqtt

#19 Post by Quart » 23 Aug 2019, 08:36

@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
mqtt_1.JPG
mqtt_1.JPG (33.86 KiB) Viewed 14505 times
mqtt.JPG
mqtt.JPG (20.26 KiB) Viewed 14505 times

User avatar
dynamicdave
Normal user
Posts: 257
Joined: 30 Jan 2017, 20:25
Location: Hampshire, UK

Re: Control some 5Volt leds with mqtt

#20 Post by dynamicdave » 23 Aug 2019, 09:04

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.

Quart
Normal user
Posts: 45
Joined: 16 Jul 2019, 10:08
Location: Sweden
Contact:

Re: Control some 5Volt leds with mqtt

#21 Post by Quart » 23 Aug 2019, 09:22

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 :D

Visit my webpage and see weahterdata and electric cosnsumtion etc
www.sundshult.se

User avatar
dynamicdave
Normal user
Posts: 257
Joined: 30 Jan 2017, 20:25
Location: Hampshire, UK

Re: Control some 5Volt leds with mqtt

#22 Post by dynamicdave » 23 Aug 2019, 09:42

Wooooo - that's impressive.
Looks like you are collecting a lot of data.
Thanks for sharing your work.

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 41 guests