Need help with my code

Hello,I am trying to club two codes into one so can anyone help me

Arduino_Bluetooth_8Lamp_with_Relay.ino (3.47 KB)

blynkh.ino (842 Bytes)

Can you post your code?
(In code tags, of course)
(I've asked a mod to move this topic)

The first help-step is showing you how to post code as a code-section:

  1. open your code in the Arduino-IDE
  2. press Ctrl-t for autoformatting your code
  3. do a right-click with your mouse and choose "copy for forum"
  4. press-alt-tab to change back to your browser
  5. press ctrl-v to insert the clipboard-content into the "write-post-field"
  6. add a detailed description what your code does and how it deviates from what you like the code to do

best regards Stefan

gagan597:
Hello,I am trying to club two codes into one so can anyone help me

Yes. After you have tried to combine them and posted your best attempt (correctly in code tags).

Steve

@Grumpy_Mike's tutorial on merging code

pinMode(2,OUTPUT);digitalWrite (2,OUTPUT); Oops

TheMemberFormerlyKnownAsAWOL:

pinMode(2,OUTPUT);digitalWrite (2,OUTPUT);

Oops

What Awol wants to say but is too lazy to explain in detail is:
the second command

digitalWrite (2,OUTPUT);

does compile but does not do what was intended:
The command above write to IO-pin 2 the number that is symbolised by the pre-defined constant OUTPUT
What it should be is either

digitalWrite (2,LOW);

or

digitalWrite (2,HIGH);

So I'm thinking about what the abbreviation Awol could mean ....
A) W)ery O)stentantive L)azyness fits pretty good.
best regards Stefan

StefanL38:
What Awol wants to say but is too lazy to explain in detail is:
the second command

digitalWrite (2,OUTPUT);

does compile but does not do what was intended:
The command above write to IO-pin 2 the number that is symbolised by the pre-defined constant OUTPUT
What it should be is either

digitalWrite (2,LOW);

or

digitalWrite (2,HIGH);

So I'm thinking about what the abbreviation Awol could mean ....
A) W)ery O)stentantive L)azyness fits pretty good.
best regards Stefan

No, not "too lazy", simply giving space to the OP to explore.
It's a useful, non-overly didactic technique - you could maybe try it.

"OUTPUT" has the same value as "HIGH".
Who is to knows what the OP meant?

"Ostentantive" has no meaning in English.
Neither "Wery". (Maybe "weary" (what I am) or "wherry" (what I row))
Nice try.

The "oops" also refers to the literal "2".

TheMemberFormerlyKnownAsAWOL:
"wherry" (what I row))

:o I learned a new word today!

TheMemberFormerlyKnownAsAWOL:
"Ostentantive" has no meaning in English.

It's "ostentatious"

gagan597:
Hello,I am trying to club two codes into one so can anyone help me

Oh dear, this again.

Computer code is not eggs, flour, and milk - you don't just mix them together in a bowl and get cake.

Start a new sketch with an idea of what the whole sketch will do overall. People get on here and say "I want the arm to move back and forth" when what they really want is for this to happen for a certain period of time when a button is pressed, or when a sensor reading reads something in particular. You don't code the arm and then code the button - you do the overall flow-of-control first, with just Serial.out() print statements saying "the button has been pressed, so start arm movement now".

This clubbed-together sketch of yours, what is the whole thing going to do?

Hello every one i am trying to control 8 channel 5v relay woth nodemcu but when i turn it on the led turns but the relay does not switch can any one help me

gagan597:
Hello every one i am trying to control 8 channel 5v relay woth nodemcu but when i turn it on the led turns but the relay does not switch can any one help me

Post your code.
Post schematic.
Post any relevant links

gagan597:
Hello every one i am trying to control 8 channel 5v relay woth nodemcu but when i turn it on the led turns but the relay does not switch can any one help me

That sounds like a hardware problem. Oh I see what's wrong! Wait a minute, that half eaten sandwich shouldn't be on the work bench. You may be surprised to learn that we can't see your hardware. Without that, how could we possibly guess what is wrong? Please post images of your wiring diagram and your actual connections.

a nodeMCU is a 3.3V-device your relay-board might be a 5V-device where the inputs need 5V to really switch through the phototransistors inside the optocouplers.

So do the following test:

  1. most important step to prevent your nodeMCU from beeing destroyed: DIS-connect nodeMCU from the relay-board.
  2. take a jumperwire and connect it from +5V to an input of the relay-board
    does the relay switch?

If yes. Keep the nodeMCU still DIS-connected from the relay-board
but connect Vin of the nodeMCU-board to the +5V and GND to GND of the 5V power-supply

connect the jumperwire from the 3.3V-pin to an input of the relay-board
does the relay switch?

if relay does not switch: hardware-probelm relay-board needs 5V on input-pins

relay does switch: software-problem post your code

This post is somehow a universal trouble-shooting guide because you did not provide the information you have been asked for. This guide could be expanded to the max to cover all uncertainties that are just uncertainties because you did not provide the information you have been already asked for

So please provide
download-link of the datasheet of the relay-board at least the link from the online-shop you bought it
download-link of the datasheet of the 5V-powersupplay at least the link from the online-shop you bought it

post your code as a codesection superfast using this method
just three steps

  1. press Ctrl-T for autoformatting your code
  2. do a rightclick with the mouse and choose "copy for forum"
  3. paste clipboard into write-window of a posting

best regards Stefan

I am sorry i cant upload my code due to technical issues but i connected 5v power supply to the jd vcc pin of relay and gnd to gnd pin it worked befpre several times and then it stopped working

gagan597:
I am sorry i cant upload my code due to technical issues but i connected 5v power supply to the jd vcc pin of relay and gnd to gnd pin it worked before several times and then it stopped working

If you can paste clipboard-content you can paste code using this superfast three-step-method

There is an automatic function for doing this in the Arduino-IDE
just three steps

  1. press Ctrl-T for autoformatting your code
  2. do a rightclick with the mouse and choose "copy for forum"
  3. paste clipboard into write-window of a posting
    If you really want help. Your potential helpers need detailed information. A sentence like

i connected 5v power supply to the jd vcc pin of relay and gnd to gnd pin it worked before several times and then it stopped working

is useless. There are so many possabilities where the error might be.
If you prefer small-talk you can go on like this. If you want to solve th eproblems do the analysing that I have described in post #14
best regards Stefan

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.