Hi. This is my first post. Apologies in advance if this has been discussed before.
below is the code I am working on. I am able to control only 1 relay connected to humidity data from DHT11. My challenge is I am not able to trigger second relay connected to temperature data. Blynk app led reflects changes basis virtual write but the second relay is not changing state. Relays are fine. Its a 5v 4 relay module that I am using.
I’ve had a quick look through the code and nothing jumps out at me as being a problem, although I’m on an iPad, so it’s more difficult than pasting it into the Arduino IDE.
I’m not a great fan of the “const int relay1 = D5” way if referencing the GPIO pins and if by some chance you’ve selected the wrong board type in Arduino then these won’t work correctly. I think I’d start by putting a meter on each of the GPIO pins and see what’s happening when you trigger each of the relays in the code, just to make sure that it’s not a different pin that’s going high/low.
You also mention that you’re using 5v relays. The ESP8266 uses 3.3v logic levels, and although most 5v relay boards that have opto isolators onboard can operate on 3.3v logic, you still need to be careful how you power them. It’s possible that you’ve killed one of the GPIO outputs on your ESP by connecting it up wrongly at some point.
Thanks Knight for the quick reply. I have checked the code many times but not able to identify the issue.
Board is nodeMCU correctly selected with all settings in the IDE.
Powering the board using 5v via USB connected to 5v2A charger
4 Relay Module is also powered directly from the same charger.
NodeMCU’s logic pins (D5, D6, D7, D8) are connected to Relay Module
I think connections and board selection is right as the Blynk app shows humidity and temperature readings correctly. And humidity Relay is triggering with the slider value connected at V7
Also, I need some help with electronics (maybe something related to Pull up resistors) -
NodeMCU fails to boot if the Relay module is on. I first power the nodeMCU and then manually power the relay board by connecting the 5v pin. Else NodeMCU won boot.
Humidity Pin D5 triggers the relay but the LED on relay module is slightly on instead of completely off.
Will check with the multimeter and update. Issue is I don’t have a working multimeter at the moment
I have commented the relay4 from D8. Still the same issue
Have pulled the wire also at that time. Just did not mention. No luck!
What is the reason that all the 5v relay is on when the PIN is LOW? I think it needs to be connected with resistor.
Instead of multimeter, I just tried it with led. Its not getting on.
I am not able to identify what is causing this issue. Really frustrated at this moment… been 3 days
Hahaha. yes the shopping list is increasing every day
To fix the boot issue. try pulling each wire between the MCU and the relay board in turn until you find which one is the issue.
Also try switching the other relays, is it just relay 2 that’s not behaving? try connecting relay 2 to a different pin, does that work?
You have an “Active Low” relay board, its the way it’s designed. Some boards have the ability to switch between active low and active high by means of a jumper or solder pads that need to be bridged/cut, but its not really an issue as you can write the code to work with the active low switching.
Its just a case of getting the priorities right - your goodies first, followed by SWMBO then the kids/dogs/cats/in-laws etc.
Knight. Thanks a lot for your support. Yes your idea worked.
I changed the pins to D1,D2,D3,D4 and things are now working fine. Strange.
Also, After removing D8 completely from circuit, Node is booting properly. Thanks for the info. I was not aware.
This was my first post on any forum like this. Always been on the consuming side… hahahaaa… Thanks. Everything is working fine now. I’ll update this post with revised code.
Need small help… In the below code, everything is working fine but the virtual LED in Blynk app connected at V29 is not changing state. Relay connected to Blynk timer is working fine but its V29 LED is not reflecting the changes. Below is the code
To be honest, I’m probably not the best person to answer this, as I never write Blynk specific code in Arduino IDE. All of my interactions with Blynk are done in Node-Red.
Having said that, I cant see anything wrong with the V29 code, so I’d start bgy checking the setup of the LED in the the app and maybe delete and re-create that LED and re-link it to V29.
I do have a few comments about the code though…
Your IF statements that control the relays and the LED widgets are a bit odd. To begin with, you have overlapping conditional tests - i.e both tests contain an equals symbol):
if (Soil <= SoilLowTrigger)
if (Soil >= SoilLowTrigger)
Because of the way you’ve structured these, with the second IF being part of an ELSE then you get away with the fact that there are two opposing things that could be done when Soil is exactly equal to SoilLowTrigger. For the sake of your future sanity when you’re debugging this at a later date, I’d suggest that you do one thing if the value is less than or equal to, and another if the value is greater than. But, if you read on, you’ll see that in this instance you don’t need this anyway…
The IF immediately following the ELSE is redundant. The code would be much better like this:
Thanks Knight. I used the mentioned If Else statement but for some reason it was not working. Will try again and repost the code here if it works fine. Thanks for the update.
Also, Earlier I was using Node red logic on RPI to control the Relay box. Was using camera functionality also. But I was not able to resolve the following issues -
How to use it on a low cost device like NodeMCU. RPI with Arduino for Analogue pin read was expensive.
I was not able to push the NodeMCU data to internet for the web dashboard or app. I have no clue how to set up Port forwarding and a far better option is to have the API functionality. Which again I have no idea how to implement.
I will post the JSON code of the NodeRed for you to help me.
Thanks once again for all the help. Really appreciate your time.
Thanks for the shared recommendations. I have updated the code. Now my relays are assigned to D1, D2, D4, D5 & DHT on D0
Everything is working fine now. There is one last issue. Looking forward to a solution.
Issue - Relay 3 connected to D5 i.e. SoilLowTrigger is getting triggered with just the slider movement is not comparing data with the Soilmoisture connected at A0.
Relay3 is getting triggered if the slider value is not 0. anything above 0 simplify triggers the relay.
I want trigger to set the param which is compared with soil reading and thn take action.
Kindly help me solve this last issue.
If you’re going to use Node-Red on RPI then you should install the Blynk WS nodes.
You should then probably run Mosquitto on the RPI and use MQTT as a way of controlling your devices, relays etc.
This is how I use Blynk and it works very well. I don’t run any Blynk code on my ESP devices, just Wi-Fi and MQTT code then logic which controls what the device should do when it receives a particular MQTT message.
I’ve built quite a complex system with 6 different sensors, 7 devices that are being controlled and a Nextion touch screen that works alongside Blynk and Amazon Alexa. Using Node-Red and MQTT makes this a fairly straightforward process that easy to maintain and expand.