Thank you so much sir, I used your code and made a few changes, basically you saved my time because I successfully completed my Arduino Code, without this video, I will still be struggling.
I been looking for a neat solution for this (i was looking for a way to control my relay with webserver and also a button!) and seemed like I couldnt find one at all, here and in other videos the code seems convoluted. So i actually stopped for 5 minutes and came out with a more simpler solution! Just follow this logic: 1- The normal button state is always HIGH until its pushed down (LOW) 2- That means you can write a comand that recognizes when the button is LOW during the two possible scenarios; if relaypin is LOW or HIGH 3- So logically, -if relaypin is HIGH and you press the button (buttonpin LOW again), te relaypin should change to LOW (in a "normally open" setting that means the lights would turn ON) -if relaypin is LOW and you presss the button (buttonpin LOW), the relaypin should change to HIGH (in a "normally open" setting that means the lights would turn OFF) So following that idea: int relaypin =7; int buttonpin = 8; void setup() { pinMode(buttonpin, INPUT); digitalWrite(relaypin, HIGH); //This is nesesary for your relay to start in HIGH at startup, so it wont switch on during the few microseconds it takes to switch states) pinMode(relaypin, OUTPUT); void loop() { if (digitalRead(buttonpin) == LOW && digitalRead(relaypin) == HIGH) { delay (400); digitalWrite(relaypin, LOW); } if (digitalRead(buttonpin) == LOW && digitalRead(relaypin) == LOW) { delay (400); digitalWrite(relaypin, HIGH); } You need that delay in the middle (maybe even make it longer) to prevent your relay from switching at the speed of light. Im sure even I can come up with a way to prevent it from keep switching if you keep it pressed long enough. This works well if you were planning to use it with other code, since it is almost isolated in terms of variables.
Assuming you can also turn on/off the light bulb through code in Arduino, right? If so will this sync up and allow you to either manually turn on/off through the button OR turn on/off through code? I'm trying to figure out if I can use this example in a real life scenario where I can control manually and remotely and have everything play nice together. Thanks!
Thank, Great video. I have a question, in the end of the video, resistor leg is in the positive? But in the beginning, resistor leg is in the negative. Hmm,
I like your video and it helped me. One thing I am trying to do but it's not working with that. Let me know can I use wall switch button which is used for 220V appliances? If so then how can I use it, please help me about that. Thank you
this is the video for you. I connected a bulb, you connect a fridge or heater or anything. as long as you pay attention to the current rating of the relay. Read your relay and make sure don't connect a load beyond the limit of the current handling of relay.
Hello Robojax, Thnx a lot for your great TH-cam, It means a lot if you share what you’re good in, so we can learn from each other. I hope you have time for a small simple question. Is there power on your relay coil when the NO contact is closed (when you’re hooked up appliance is on) like a standard relay or does it gets a pulse each time you switch on and off you’re appliance? Greats Bart
thank you for your video, i want to ask about led light, why the led turn on but the relay turn off. and the opposite, this is my condition, in yours led light on the relay turn on
@@robojax thanks. i have solved the problem. but i dont know what project must i create with this arduino. so i leave arduino for now. and back to my daily work. thanks again.
just define all pins and variables . I have explained it fully. so pay attention to the code, watch it 2, 3, , 4 or 10 times until you know how it works. I can assure you can you do it. Here is my ***** Free Arduino Course **** Arduino Step by Step Course (over 100 lectures) Starts here robojax.com/L/?id=338
//Thank so much, I// believe this more self-explanatory int val = LOW; // push value from pin 2 int lightON = LOW;//light status int pushed = LOW;//push status
nice video sir...and also please make operating relay with manual switch operating and mobile operating{wirless operating).iam already told you in last video,
Your request has low priority. Out of over 200,000 views in a month in my channel, only 500 might be interested in mobile. I will do it when I get time for it.
Hi SIr, May i know which switch you are using i need same kind of switches to use in our project. Is this push once power on push again to power off switch? please let me know the part number.
Hello, I had to watch multiple videos to find the answer for you. here at 9:09 of this video th-cam.com/video/3EZecphNdAI/w-d-xo.html I've explained it.
how to i alter the code to make it so the switch only turns the relay on wile the switch is pressed? im planning to use this with a relay shield for a robotic charging base that only turns on when the robot parks on it to avoid causing a short when the contacts touch.
Thank you for making such a great video! I have one question. How can I make it to where I can hold the button down to turn on relay and release will turn it off?
HI, here the the thermocouple video that you control a relay th-cam.com/video/dVh77wT-4Ao/w-d-xo.html always search my channel. I have over 440 videos (Nov 2020) and you will find useful tutorial th-cam.com/users/robojaxTVvideos
Hi. Thanks for the infomative video. I've connected the output of the relay (coms & NO) with 2 jumper wires connected to each other, then to an LED bulb in a breadboard. But it doesn't seemed to light up the LED. why is it so?? and also the wire connecting the output of relay is of the same terminal right (same Single wire)??
Thank you so much it was helpful but I'm facing a problem in coding of push button switch , I want the sensor value to be saved in a reference when push boutton is pressed CODE: int sensorPin = A0; int buttonPin =7 ; int LED = 8; void setup() { pinMode(buttonPin, INPUT_PULLUP); pinMode(LED, OUTPUT); pinMode(sensorPin, INPUT); Serial.begin(9600); } void loop(){ int reff; int sensorValue = analogRead(sensorPin); int buttonValue = digitalRead(buttonPin); while(buttonValue == LOW) { reff = analogRead(sensorPin); Serial.println(sensorValue); } Serial.println(reff); delay(100); } PROBLEM: if i press the button then sensor value should be displayed and get saved to reff , but both are not happening and reff value is not changing it stays at 0 button is working fine ,Every component is working fine i hope that you could help me out in this one Thanks in advance
Thank you for this great video! I'm attempting to use this principle with an LED, but I'm having trouble adding a fade time. I would like to push the button, then the LED fades up in 4 seconds. Then push the button again and the LED fades off in 4 seconds. I've adjusted your code to work with a MOSFET, I just need help adding the dimmer fade. Any ideas?
You are welcome. Your project is different. The output on this project is working like switch either ON or OFF. For fading we need PWM. Here I have written this code which I have not tested but it shoudl work. www.codepile.net/pile/4XyqJNXd please let me know
Hi man, nice video. I have a question, when you turn on the arduino the load is on automaticly? I have a home project where i want to conect a water pump but in power fail i dont want to be on when power comes back, just remain off
I'd like to use code for trains set keto turnouts. It's simple and I understand it. I have played around with the code. I like to have one button to turn on and then off 1 second later.(auto turn off the relay). I have played around will millsec(), Delay () I just cannot get it right.
I will reply to all Subscriber's 🔔 questions. So make sure to Subscribe.😊 Please like 👍 the video and type simple word in the comment. It helps me a lot. Here are my videos on millis th-cam.com/users/robojaxTVsearch?query=millis
I can't find the wiring schematic! Ideally the link to the code and wiring diagrams should be easy to find, ie, at the beginning of the "See More" link. Yes, the code link points to another link which links to a udemy page to get the schematic, really?
code is there but no schematic. you don't need it. I have explained it fully. you can draw it if you need it for school or project using this free software fritzing.org/ the link to the code is for sure there.
Hi , when the pushbutton is being pressed , current from the 5v pin of the Arduino will travel to gnd through the push button , wouldn't this short circuit the Arduino ?
It seems you have not watch the video or have skipped. We never connect a switch one side to 5v and the other side to ground. Of course it will short circuit it. Watch the video again without skipping
You don't need resistor, i used "INPUT_PULLUP" to eliminate the usage of resistor. Watch my video on why use resistor th-cam.com/video/TTqoKcpIWkQ/w-d-xo.html
yes after you turn the relay ON, set delay (10000); But this code is to keep the LIGHT on and wait for another push to go OFF. use this goo.gl/C7vJqx and connect relay to pin 10. After this line digitalWrite(10, HIGH); put this delay (10000); and it will keep the light ON for 10 min and then goes OFF.
if you don't like to use delay(), then using mills() you can do it. Please have a look at this example at the end of page www.lucadentella.it/en/2015/07/21/arduino-delay-vs-millis/
Hello, top video! But I have a problem: everthing is as You have and I download the code but the led is ON and the relay is OF. When I push the bottem relay is ON but the led is OF. It is not on the same time. Have You any idea wath the problem is?
@@robojax HI, it is not the ac lamp what is the problem; led on breadboard is ON, green led of the relay is OFF. Push the bottem;; green led on relay is ON, led on the bb is OFF
@@robojax ok, You have a green led on the bb burning. Only the red led on the relay is burning I push the bottem, led on the bb is going out and the green led is going on.The green led on bb and the green led on the relay are not going buring at the same time that is de problem.
Red is power showing there is power. Green is the actual ON and OFF. Do you hear click? you should hear click when green LED turns ON. If there is click all OK. it should work.
I have two video one without LCD and another with LCD, Robojax Relay Timer. th-cam.com/video/6DGQhQgr7Ak/w-d-xo.html and th-cam.com/video/BhEIFzFSMuE/w-d-xo.html using push button will not make sense. How do you know what is the set time? You will need to have display to tell you the time.
I can't find any videos detailing how to wire this up without using a relay, all I want to do is turn the LED on with a press of the button, and have it stay on until the next press
If you know how to connect LED, then in this code connect your LED to pin 10. Or watch this video th-cam.com/video/2WwedCRwmgA/w-d-xo.html and then come back to this video.
hello mr robojax~ its really nice tutorial~ i am a newbie abour arduino and electronics. i want to ask question, int lighton, is it for what? int for bulb or something? i still dont understand about this code.
i test the code, after uploading the code it will on and off the relay. after 3 sec the relay will on again, but i did not press the button. can you help or check again the code . thank you...
Load is load. Doesn't matter if AC bulb or DC motor. As long as the amount of current the motor needs doesn't exceed the rating of relay, it will work.
HI, thanks for this nice video. I need a little help to add delay of 2 seconds before turning on the relay and when button pressed will off the relay. the precess should be repeated llike - 1. pushed button - delay of 2 secs then relay on. 2. again pushed button - relay off. 3. pushed button - delay of 2 secs then relay on. 4. again pushed button - relay off..............etc the process repeats with button press.....
You are welcome. Yes it is easily doable. Just add delay(2000); after the Serial.println("Light ON"); like this Serial.println("Light ON"); delay(2000); See the full code I have customized for you: codeshare.io/a3ZQjg test it and let me know.
Dear robojax, extreme thanks for your kind reply. the code works. but the real problem i am facing is to add a delay of 2 seconds in the switch case-2 of below code. I need a delay of 2 secs only in case-2 and all other case should work without delay. i tried to add delay command but it pauses all next process. plz help if possible here..... the delay location i have mentioned in below code-----.... int input = 2; int output1 = 3; int output2 = 4; int output3 = 8; int output4 = 9; int output5 = 10; int output6 = 11; int state = 0; int old =0; int buttonpoll=0; void setup() { pinMode(input, INPUT_PULLUP); pinMode(output1, OUTPUT); pinMode(output2, OUTPUT); pinMode(output3, OUTPUT); pinMode(output4, OUTPUT); pinMode(output5, OUTPUT); pinMode(output6, OUTPUT); digitalWrite(output1, LOW); digitalWrite(output2, LOW); digitalWrite(output3, LOW); digitalWrite(output4, LOW); digitalWrite(output5, LOW); digitalWrite(output6, LOW); } void loop() { buttonpoll = digitalRead (input); if (buttonpoll ==1){ delay (80); buttonpoll = digitalRead (input); if (buttonpoll==0){ state = old + 1; }} else { delay(100);} switch(state){ case 1: digitalWrite(output3, LOW); digitalWrite(output4, HIGH); digitalWrite(output5, LOW); digitalWrite(output6, HIGH); digitalWrite(output1, HIGH); digitalWrite(output2, HIGH); old = state; break; case 2: digitalWrite(output3, HIGH); digitalWrite(output4, LOW); digitalWrite(output5, HIGH); digitalWrite(output6, LOW); digitalWrite(output1, LOW); digitalWrite(output2, LOW); //i need here a break of 2 seconds and continue the output1 and 2 High, also continue to next switch case. digitalWrite(output1, HIGH); digitalWrite(output2, HIGH); old = state; break; default: digitalWrite(output1,LOW); digitalWrite(output2, LOW); digitalWrite(output3, LOW); digitalWrite(output4, LOW); digitalWrite(output5, LOW); digitalWrite(output6, LOW); old = 0; break;
delay() will halt all process. This is that it does. You can't continue to the rest of the code before the delay time has not reached to the end. Please use the chareCode.io. you could directly edit the code or create new code see this snag.gy/5jXKr9.jpg After you made change or you created code, just share address.
Glad I could help. Please watch this 30 minuet Arduino course and you will learn very important things about Arduino th-cam.com/video/Mbb2xa1WcRM/w-d-xo.html
hello ! Robojax !! Nice tutorial. I tried the single channel relay code and it just worked fine on my nodemcu. so i thought of making it 4 channel and created my own code referring to single channel code of yours.. But the relay randomly turns on and off. dont know where hv gone wrong. can you please help me out? Thanks in advance...
Hi, Thank you for the complement. Have you looked at the second code at the bottom of the page which shows how to control 2 relay and 2 buttons :robojax.com/learn/arduino/?vid=robojax-pushButton-on-off I am sure once you look at it, it would be clear. Let me know if further help is needed.
Thank you so much for the quick response. Yes after having a look at the 2 channel relay control , then i created the 4 channel code. But its not working as expected. Can you please provide me your email address so that i can mail you the code. Or please ping me on my mail madhukeshnp@gmail.com .
Hi Mr. Robojak, i try to use the 2 button and relay code and it didn't work properly, only relay 2 can turn ON , relay 1 cannot ON. Can you pls help? But i also try the 1 relay code and it's work.
Hi Mr . Robojak, thank you very much for your quick reply, btw can you pls send me the correct code that you have fixed it pls, or can i know where can i get it? Thanks again sir.
Great video. Very helpful thank you so much. Please upload tutorial for TFT touch display with arduino while also using other sensors like temperature and humidity sensor and show that data on tft display
do you want to the relay to be OFF when you turn ON Arduino? as later we don't have first or second. it depends how you see it. Once you press it few times you will forget what is what.
you made me watch the video as this video doesn't need LED. But it has and I mentioned that if you use a relay you don't need LED. but in case you did, the color of the resistor is BLUE, Grey, Brown which is 680Ω but you can use 300Ω to 1000Ω. you and do google/bing search for "resistor color code" you will get something like this www.allaboutcircuits.com/tools/resistor-color-code-calculator/ where you can select color and read the resitors value.
Bro, actually I need your help can you help me please . if you are willing to do please reply me to this mail (dasari17144@iiitd.ac.in) I need your help in fixing the push button with a battery and that push button in connected to ardunio please mail me if you are willing to do. I can tell me clearly ..
Sir i want the bulb to be switched on for 7 seconds and then automatically shut down and again turn on for 7 sec only if push switch is pressed else bulb remains off. Plz suggest me how to do It will solved by only change in programming of audrino?? Plz reply 🙏
Hi, Yes. it is very simple. See the code here th-cam.com/video/58XWVDnB7Ss/w-d-xo.html You have to watch the video to understand what I say. here is the code codeshare.io/5wEdZP
I just checked the code. it should not do it. Without pushing the switch it should not toggle the bulb. Check the code or wiring. if you use INPUT_PULLUP which is in the code, it should not turn ON or oFF by itself.
as soon as you push, if the light is ON will turn OFF and stay OFF and if the light is OFF, as soon as you push the light will turn ON and will stay on until you release the button and push again. Doesn't matter if you keep if for 1 min or 1 hour. no affect.
You must be doing something wrong. Please post your code in this page codeshare.io/ and it will create a URL (addres) for your code, then copy and paste the code by replying to this message.
I just watched the video making sure I have mentioned it and yes I have mentioned it that the code is under the video in the description or you can visit my website. here is how snipboard.io/EG4O2l.jpg
@@robojax hi sir, please ,,, i need your help very urgent how to ensure the wiring between an ACS712 5A sensor + 5v relay + Arduino + a Push button (I trained to carry out my end of study project. The objective of this project is therefore to find a solution to the problems of Smartphone charger accidents. home fires start, We have arrived at an intermediate investigation between the network and the charger. This media is automatically disconnected when the charger is empty or when the battery charge level reaches 100%.) (When you appear on the push button, the phone is charging and when the charger is empty or the battery is 100% reached, the relay disconnects.)
Thanks but this little code for everything I did int relay1 =11; int but =9; int val ; void setup() { pinMode(but,INPUT_PULLUP); pinMode(relay1,OUTPUT); } void loop() { val=digitalRead(relay1); if (digitalRead(but)==LOW){ digitalWrite(relay1,!val); delay(500); } } onnnlyyyy
Thank you so much sir, I used your code and made a few changes, basically you saved my time because I successfully completed my Arduino Code, without this video, I will still be struggling.
Glad I could help!
I been looking for a neat solution for this (i was looking for a way to control my relay with webserver and also a button!) and seemed like I couldnt find one at all, here and in other videos the code seems convoluted.
So i actually stopped for 5 minutes and came out with a more simpler solution! Just follow this logic:
1- The normal button state is always HIGH until its pushed down (LOW)
2- That means you can write a comand that recognizes when the button is LOW during the two possible scenarios; if relaypin is LOW or HIGH
3- So logically, -if relaypin is HIGH and you press the button (buttonpin LOW again), te relaypin should change to LOW (in a "normally open" setting that means the lights would turn ON)
-if relaypin is LOW and you presss the button (buttonpin LOW), the relaypin should change to HIGH (in a "normally open" setting that means the lights would turn OFF)
So following that idea:
int relaypin =7;
int buttonpin = 8;
void setup() {
pinMode(buttonpin, INPUT);
digitalWrite(relaypin, HIGH); //This is nesesary for your relay to start in HIGH at startup, so it wont switch on during the few microseconds it takes to switch states)
pinMode(relaypin, OUTPUT);
void loop() {
if (digitalRead(buttonpin) == LOW && digitalRead(relaypin) == HIGH) {
delay (400);
digitalWrite(relaypin, LOW);
}
if (digitalRead(buttonpin) == LOW && digitalRead(relaypin) == LOW) {
delay (400);
digitalWrite(relaypin, HIGH);
}
You need that delay in the middle (maybe even make it longer) to prevent your relay from switching at the speed of light.
Im sure even I can come up with a way to prevent it from keep switching if you keep it pressed long enough.
This works well if you were planning to use it with other code, since it is almost isolated in terms of variables.
Thank you for your comment and code. It seems to be working. Same task can be done in many ways.
Assuming you can also turn on/off the light bulb through code in Arduino, right? If so will this sync up and allow you to either manually turn on/off through the button OR turn on/off through code? I'm trying to figure out if I can use this example in a real life scenario where I can control manually and remotely and have everything play nice together. Thanks!
In case I have 3 switches and 3 appliances (say bulb, fan, night lamp), can I simply copy the code three times by using appropriate nomenclature?
Thank, Great video.
I have a question, in the end of the video, resistor leg is in the positive? But in the beginning, resistor leg is in the negative. Hmm,
Learn here why we need resistor or not with push button th-cam.com/video/TTqoKcpIWkQ/w-d-xo.html
@@robojax thank you very much
I like your video and it helped me. One thing I am trying to do but it's not working with that. Let me know can I use wall switch button which is used for 220V appliances? If so then how can I use it, please help me about that. Thank you
this is the video for you. I connected a bulb, you connect a fridge or heater or anything. as long as you pay attention to the current rating of the relay. Read your relay and make sure don't connect a load beyond the limit of the current handling of relay.
Hello Robojax,
Thnx a lot for your great TH-cam, It means a lot if you share what you’re good in, so we can learn from each other. I hope you have time for a small simple question. Is there power on your relay coil when the NO contact is closed (when you’re hooked up appliance is on) like a standard relay or does it gets a pulse each time you switch on and off you’re appliance?
Greats
Bart
Hi, you are welcome. here is my video on relay th-cam.com/video/N-fFk51Eb8s/w-d-xo.html
thank you for your video, i want to ask about led light, why the led turn on but the relay turn off. and the opposite, this is my condition, in yours led light on the relay turn on
You are incorrect wiring on the relay NO, NC. Watch the video again.
@@robojax thanks. i have solved the problem. but i dont know what project must i create with this arduino. so i leave arduino for now. and back to my daily work. thanks again.
Great video. I have a question how to modify it to have 2 buttons that control one realy (bulb). Application in stairs.
that needs separate project. can't be explained by few line.
@@robojax Can you preapre video are rather you are not inreasted.
Excellent video. What if i wanted to add two or more then two push buttons? Thankyou
just define all pins and variables . I have explained it fully. so pay attention to the code, watch it 2, 3, , 4 or 10 times until you know how it works. I can assure you can you do it. Here is my ***** Free Arduino Course ****
Arduino Step by Step Course (over 100 lectures) Starts here robojax.com/L/?id=338
//Thank so much,
I// believe this more self-explanatory
int val = LOW; // push value from pin 2
int lightON = LOW;//light status
int pushed = LOW;//push status
I need exactly the same set up including 16 on and off toggle switch with 16 relay.
Search my channel for 16 channel
HO would you change the code to have "3 presses of the button - ON, 3 more presses of button - OFF" ... then start over?
Hello, you can learn it from this video th-cam.com/video/OSwleCBlkuI/w-d-xo.html
Thank you bro
I have a question 🤔
When I press the push button the relay turn off and the led turn on
How can I turn them on together?
They should turn on together because they are after each other in the code , unless you changed it. Or change it to work together.
Hi
This is a very cool idea. Do you still have the code for it? Can't seem to find it in the description.
I have over 400 and all links are in the description. I just checked it and it is there.
nice video sir...and also please make operating relay with manual switch operating and mobile operating{wirless operating).iam already told you in last video,
Your request has low priority. Out of over 200,000 views in a month in my channel, only 500 might be interested in mobile. I will do it when I get time for it.
Hi SIr,
May i know which switch you are using i need same kind of switches to use in our project.
Is this push once power on push again to power off switch?
please let me know the part number.
Hello, you can get Push buttons from Amazon: amzn.to/3eFlwWN
awesome video! great.
Would you mind telling me the meaning of ( pushed = 1 - pushed); why do not give previousState newState
Hello, I had to watch multiple videos to find the answer for you. here at 9:09 of this video th-cam.com/video/3EZecphNdAI/w-d-xo.html I've explained it.
@@robojax ok thank you.
Can you have this push button to keep the light on for a preset time for example for 30 seconds and turn off by itself?
Then you don't need this. You can use this video th-cam.com/video/6DGQhQgr7Ak/w-d-xo.html
how to i alter the code to make it so the switch only turns the relay on wile the switch is pressed? im planning to use this with a relay shield for a robotic charging base that only turns on when the robot parks on it to avoid causing a short when the contacts touch.
learn about push button in this video th-cam.com/video/yyJrqFKn-X4/w-d-xo.html
Thank you for making such a great video! I have one question. How can I make it to where I can hold the button down to turn on relay and release will turn it off?
You are welcome. Here is the simple form. You can use Relay instead of LED in this video th-cam.com/video/2WwedCRwmgA/w-d-xo.html
Robojax q
hi Mr ahmed goood work can we change the push button withe a sensor like a thermocouple withe same cod of the push button
HI, here the the thermocouple video that you control a relay th-cam.com/video/dVh77wT-4Ao/w-d-xo.html always search my channel. I have over 440 videos (Nov 2020) and you will find useful tutorial th-cam.com/users/robojaxTVvideos
-Ahmed- Ahmad
Hi. Thanks for the infomative video. I've connected the output of the relay (coms & NO) with 2 jumper wires connected to each other, then to an LED bulb in a breadboard. But it doesn't seemed to light up the LED. why is it so?? and also the wire connecting the output of relay is of the same terminal right (same Single wire)??
Hi, does the relay clicks? Do you hear that sound of it? If not then either you changed the code or wiring has issue. Check it.
@@robojax hi yes the relay is clicking with LED blinking when linked with arduino code. But serve no output signal.
If relay works then you fix the wiring from relay to your load
@@robojax yes it is working now. thank you!
Will the push button remain the same state after reset
Watch the video.
Thank you so much it was helpful
but I'm facing a problem in coding of push button switch , I want the sensor value to be saved in a reference when push boutton is pressed
CODE:
int sensorPin = A0;
int buttonPin =7 ;
int LED = 8;
void setup() {
pinMode(buttonPin, INPUT_PULLUP);
pinMode(LED, OUTPUT);
pinMode(sensorPin, INPUT);
Serial.begin(9600);
}
void loop(){
int reff;
int sensorValue = analogRead(sensorPin);
int buttonValue = digitalRead(buttonPin);
while(buttonValue == LOW)
{
reff = analogRead(sensorPin);
Serial.println(sensorValue);
}
Serial.println(reff);
delay(100);
}
PROBLEM:
if i press the button then sensor value should be displayed and get saved to reff , but both are not happening and reff value is not changing it stays at 0
button is working fine ,Every component is working fine i hope that you could help me out in this one
Thanks in advance
How to control forward and revese motor using switch and the programing ?
see my comment reply to your other comment. I can see both or all comments on the same page.
Thank you for this great video! I'm attempting to use this principle with an LED, but I'm having trouble adding a fade time. I would like to push the button, then the LED fades up in 4 seconds. Then push the button again and the LED fades off in 4 seconds. I've adjusted your code to work with a MOSFET, I just need help adding the dimmer fade. Any ideas?
You are welcome. Your project is different. The output on this project is working like switch either ON or OFF. For fading we need PWM. Here I have written this code which I have not tested but it shoudl work. www.codepile.net/pile/4XyqJNXd please let me know
If you want to fade on/off a 3v or 5v LED then you don't need a MOSFET, the LED can be directly controlled from any PWM support pin of Arduino.
hellow robojax.. nice video..... i have a question how to make connection if u dont have a resistor.. only using pull up code?
Yes you can I have used in many of my project.
Hi man, nice video.
I have a question, when you turn on the arduino the load is on automaticly?
I have a home project where i want to conect a water pump but in power fail i dont want to be on when power comes back, just remain off
Thank you. I should have done that. I just updated the code you can get it. I added digitalWrite(relayPin, HIGH); inside the setup()
Another cool video 😁
I'd like to use code for trains set keto turnouts. It's simple and I understand it. I have played around with the code. I like to have one button to turn on and then off 1 second later.(auto turn off the relay). I have played around will millsec(), Delay () I just cannot get it right.
I will reply to all Subscriber's 🔔 questions. So make sure to Subscribe.😊
Please like 👍 the video and type simple word in the comment. It helps me a lot.
Here are my videos on millis th-cam.com/users/robojaxTVsearch?query=millis
I can't find the wiring schematic! Ideally the link to the code and wiring diagrams should be easy to find, ie, at the beginning of the "See More" link. Yes, the code link points to another link which links to a udemy page to get the schematic, really?
code is there but no schematic. you don't need it. I have explained it fully. you can draw it if you need it for school or project using this free software fritzing.org/ the link to the code is for sure there.
Thanks for explaining
Robo, would you be willing to build a script to control a few linear actuator using and ardunio? Please let me know
Hi, I am sorry I am very busy with full time job, research work and TH-cam. I might make a video in the future.
Hi , when the pushbutton is being pressed , current from the 5v pin of the Arduino will travel to gnd through the push button , wouldn't this short circuit the Arduino ?
It seems you have not watch the video or have skipped. We never connect a switch one side to 5v and the other side to ground. Of course it will short circuit it. Watch the video again without skipping
@@robojax I am sorry , I meant the I/O pin (pin2 ) , that pin is directly connected via the button to the ground
please watch the other video which is only about push button switch. I have replied.
Como puedo hacerlo con Nodemcu para encender y apagar con el botón y también por wifi ?
th-cam.com/video/wdgWdxV60dg/w-d-xo.html
nice video....keep up the good work.....
Thanks.
use a resistor on the buttom pin (between pin 2 and ground in this case ) to avoid a wrong input value, my input was always high because of that
You don't need resistor, i used "INPUT_PULLUP" to eliminate the usage of resistor. Watch my video on why use resistor th-cam.com/video/TTqoKcpIWkQ/w-d-xo.html
How it could stay on for 10min and then turn off. Without the delay() fuction.
Thanks
yes after you turn the relay ON, set delay (10000); But this code is to keep the LIGHT on and wait for another push to go OFF.
use this goo.gl/C7vJqx and connect relay to pin 10. After this line digitalWrite(10, HIGH); put this delay (10000);
and it will keep the light ON for 10 min and then goes OFF.
I' d like to do tha without the delay(10000). Because the delay holds all the loop. Is it posible to do that with millis()?
if you don't like to use delay(), then using mills() you can do it. Please have a look at this example at the end of page www.lucadentella.it/en/2015/07/21/arduino-delay-vs-millis/
It's so cool.
It has been a great help
Good to hear that. Thanks
thank, very useful for mee, thanks !!!
You are welcome. Here is $200 Arduino course for free Arduino Step by Step Course (over 100 lectures) Starts here robojax.com/L/?id=338
Hello, top video!
But I have a problem: everthing is as You have and I download the code but the led is ON and the relay is OF. When I push the bottem relay is ON but the led is OF. It is not on the same time. Have You any idea wath the problem is?
You have connected your relay wires incorrectly. Watch the video again where I explained the relay wiring.
@@robojax HI, it is not the ac lamp what is the problem; led on breadboard is ON, green led of the relay is OFF. Push the bottem;; green led on relay is ON, led on the bb is OFF
I am sorry which LED? the LED on relay ? There is 2 LED on the relay. One is always ON. that is power. the 2nd turn ON when relay goes ON.
@@robojax ok, You have a green led on the bb burning. Only the red led on the relay is burning I push the bottem, led on the bb is going out and the green led is going on.The green led on bb and the green led on the relay are not going buring at the same time that is de problem.
Red is power showing there is power. Green is the actual ON and OFF. Do you hear click? you should hear click when green LED turns ON. If there is click all OK. it should work.
What version of fritzing is used? Thanks for who can answer :)
I have not looked at version. Every I believe for this purpose, any version will work. I have also edited the image in photoshop.
can you show how to create automatic light on/off with timer use relay on arduino with up and down push button for chose timer.
I have two video one without LCD and another with LCD, Robojax Relay Timer. th-cam.com/video/6DGQhQgr7Ak/w-d-xo.html and th-cam.com/video/BhEIFzFSMuE/w-d-xo.html using push button will not make sense. How do you know what is the set time? You will need to have display to tell you the time.
I can't find any videos detailing how to wire this up without using a relay, all I want to do is turn the LED on with a press of the button, and have it stay on until the next press
If you know how to connect LED, then in this code connect your LED to pin 10. Or watch this video th-cam.com/video/2WwedCRwmgA/w-d-xo.html and then come back to this video.
Hello sir I have seen your video .It is good for one switch ! What about 5-10 switchs
Hi,, you can use the code in this video to control as many bulbs you like: th-cam.com/video/Wbm3MCMgM_s/w-d-xo.html
Can u give me the program of 5 push buttons and one led to ON, 5 indicators for 5 push buttons , one reset button to OFF for all led
I am sorry, I am very busy. What is application for this? if a lot of people need it, I will consider working on it.
@@robojax it's for my home emergency switch, security gaurd will reset the button to turn off the syren
if I used pushbutton same as DOL starter
will it work or not?
what is DOL?
@@robojax Direct On Line
Okay, still I did not understand what you wan to do.
Sir. How can we do it wirelessly?
Watch this video. You need Bluetooth module th-cam.com/video/-E9J9ExdZ20/w-d-xo.html
hello mr robojax~
its really nice tutorial~
i am a newbie abour arduino and electronics.
i want to ask question, int lighton, is it for what? int for bulb or something? i still dont understand about this code.
int lightON = 0;//light status
it remembers the status (oN or OFF) of the light. Check the word "status"
i test the code, after uploading the code it will on and off the relay. after 3 sec the relay will on again, but i did not press the button. can you help or check again the code . thank you...
you must have changed the code. it should work.
Will it be the same diagram if i use DC motor ?
Load is load. Doesn't matter if AC bulb or DC motor. As long as the amount of current the motor needs doesn't exceed the rating of relay, it will work.
how would i add a 3rd mode on 3rd click of button for blink???
see video in U- tube "th-cam.com/video/ojflP6pvTMc/w-d-xo.html"
Very useful ,thanks
Thank you Good video
Glad you enjoyed it
Seriously you saved me from going nuts..
I am pleased hearing that.
HI, thanks for this nice video.
I need a little help to add delay of 2 seconds before turning on the relay and when button pressed will off the relay. the precess should be repeated llike -
1. pushed button - delay of 2 secs then relay on.
2. again pushed button - relay off.
3. pushed button - delay of 2 secs then relay on.
4. again pushed button - relay off..............etc
the process repeats with button press.....
can the same be added in your above relay code
You are welcome. Yes it is easily doable. Just add delay(2000); after the Serial.println("Light ON");
like this
Serial.println("Light ON");
delay(2000);
See the full code I have customized for you: codeshare.io/a3ZQjg
test it and let me know.
Dear robojax,
extreme thanks for your kind reply. the code works. but the real problem i am facing is to add a delay of 2 seconds in the switch case-2 of below code.
I need a delay of 2 secs only in case-2 and all other case should work without delay. i tried to add delay command but it pauses all next process. plz help if possible here..... the delay location i have mentioned in below code-----....
int input = 2;
int output1 = 3;
int output2 = 4;
int output3 = 8;
int output4 = 9;
int output5 = 10;
int output6 = 11;
int state = 0;
int old =0;
int buttonpoll=0;
void setup() {
pinMode(input, INPUT_PULLUP);
pinMode(output1, OUTPUT);
pinMode(output2, OUTPUT);
pinMode(output3, OUTPUT);
pinMode(output4, OUTPUT);
pinMode(output5, OUTPUT);
pinMode(output6, OUTPUT);
digitalWrite(output1, LOW);
digitalWrite(output2, LOW);
digitalWrite(output3, LOW);
digitalWrite(output4, LOW);
digitalWrite(output5, LOW);
digitalWrite(output6, LOW);
}
void loop() {
buttonpoll = digitalRead (input);
if (buttonpoll ==1){
delay (80);
buttonpoll = digitalRead (input);
if (buttonpoll==0){
state = old + 1;
}}
else
{
delay(100);}
switch(state){
case 1:
digitalWrite(output3, LOW);
digitalWrite(output4, HIGH);
digitalWrite(output5, LOW);
digitalWrite(output6, HIGH);
digitalWrite(output1, HIGH);
digitalWrite(output2, HIGH);
old = state;
break;
case 2:
digitalWrite(output3, HIGH);
digitalWrite(output4, LOW);
digitalWrite(output5, HIGH);
digitalWrite(output6, LOW);
digitalWrite(output1, LOW);
digitalWrite(output2, LOW);
//i need here a break of 2 seconds and continue the output1 and 2 High, also continue to next switch case.
digitalWrite(output1, HIGH);
digitalWrite(output2, HIGH);
old = state;
break;
default:
digitalWrite(output1,LOW);
digitalWrite(output2, LOW);
digitalWrite(output3, LOW);
digitalWrite(output4, LOW);
digitalWrite(output5, LOW);
digitalWrite(output6, LOW);
old = 0;
break;
}
}
delay() will halt all process. This is that it does. You can't continue to the rest of the code before the delay time has not reached to the end.
Please use the chareCode.io. you could directly edit the code or create new code see this snag.gy/5jXKr9.jpg
After you made change or you created code, just share address.
Is it possible to add bluetooth and android app with Push button
here check it out th-cam.com/video/-E9J9ExdZ20/w-d-xo.html
hi thnx man i found your code god bless you always...im newbie
Glad I could help. Please watch this 30 minuet Arduino course and you will learn very important things about Arduino th-cam.com/video/Mbb2xa1WcRM/w-d-xo.html
hello !
Robojax !! Nice tutorial. I tried the single channel relay code and it just worked fine on my nodemcu. so i thought of making it 4 channel and created my own code referring to single channel code of yours.. But the relay randomly turns on and off. dont know where hv gone wrong. can you please help me out? Thanks in advance...
Hi, Thank you for the complement. Have you looked at the second code at the bottom of the page which shows how to control 2 relay and 2 buttons :robojax.com/learn/arduino/?vid=robojax-pushButton-on-off
I am sure once you look at it, it would be clear. Let me know if further help is needed.
Thank you so much for the quick response. Yes after having a look at the 2 channel relay control , then i created the 4 channel code. But its not working as expected. Can you please provide me your email address so that i can mail you the code. Or please ping me on my mail madhukeshnp@gmail.com .
is possible connect 3VDC in output?
Arduino has 3.3V and 5V but not 3V. if you get 3.3V relay, and Arduino non with 3.3V, yes can.
@@robojax without arduino, i want use a 2032 3v battery
how can we use multiple relays and buttons
I believe we have such project. Here is how to find Specific TH-cam Video in a channel bit.ly/findTH-camVideo
@@robojax video’s not available
What if I create a toggle button in app inventor what will be the code of it in Arduino?
Never heard of app inventor. But just checked it. it is totally different. you can apply the concept but different method.
Robojax Okay thank you so much
Hi Mr. Robojak, i try to use the 2 button and relay code and it didn't work properly, only relay 2 can turn ON , relay 1 cannot ON. Can you pls help? But i also try the 1 relay code and it's work.
HI Sangar, you are right. There were problem with the code and I fixed it. I have not tested it but it should work. Let me know if there is a problem.
Hi Mr . Robojak, thank you very much for your quick reply, btw can you pls send me the correct code that you have fixed it pls, or can i know where can i get it? Thanks again sir.
Great, i got it, thank you sir really appreaciate your quick response. Thank you again.
Hello, I am having the same problem. Is there an updated code?
very helpful!!! thanks a lot!
You are welcome.
Great video. Very helpful thank you so much.
Please upload tutorial for TFT touch display with arduino while also using other sensors like temperature and humidity sensor and show that data on tft display
Thank you. Sure will do that. I have add it into my list.
Robojax thank you a lot. I will be waiting.
Can i make it in relay off state at first
do you want to the relay to be OFF when you turn ON Arduino? as later we don't have first or second. it depends how you see it. Once you press it few times you will forget what is what.
can I use this code with espnow
Don’t know what is espnow
Thank you sir.
I expect to your more videos
So nice of you
How big is the resistor?
you made me watch the video as this video doesn't need LED. But it has and I mentioned that if you use a relay you don't need LED. but in case you did, the color of the resistor is BLUE, Grey, Brown which is 680Ω but you can use 300Ω to 1000Ω. you and do google/bing search for "resistor color code" you will get something like this www.allaboutcircuits.com/tools/resistor-color-code-calculator/ where you can select color and read the resitors value.
Thank you!
you are very welcome.
.....from Thessaloniki, thank you very much for your help
You are welcome. Ahmad from Canada
Thank you so much this is stuff I need :)
You are welcome.
Bro, actually I need your help can you help me please . if you are willing to do please reply me to this mail (dasari17144@iiitd.ac.in) I need your help in fixing the push button with a battery and that push button in connected to ardunio please mail me if you are willing to do. I can tell me clearly ..
NC actually stands for normally closed. You said normally connected. Love your videos though.
Thank you very much.
Sir i want the bulb to be switched on for 7 seconds and then automatically shut down and again turn on for 7 sec only if push switch is pressed else bulb remains off.
Plz suggest me how to do
It will solved by only change in programming of audrino??
Plz reply 🙏
Hi, Yes. it is very simple. See the code here th-cam.com/video/58XWVDnB7Ss/w-d-xo.html
You have to watch the video to understand what I say.
here is the code codeshare.io/5wEdZP
@@robojax thankyou very much for your help🙏🙏🙏
You are welcome.
i test the code, after uploading the code it will on and off the relay. after 3 sec the relay will on again, but i did not press the button.
I just checked the code. it should not do it. Without pushing the switch it should not toggle the bulb. Check the code or wiring. if you use INPUT_PULLUP which is in the code, it should not turn ON or oFF by itself.
Thank you
Thank you boss
nice tutorial,tnx
You are welcome.
what will happen, if you press the button for 3 minutes? please,
as soon as you push, if the light is ON will turn OFF and stay OFF and if the light is OFF, as soon as you push the light will turn ON and will stay on until you release the button and push again. Doesn't matter if you keep if for 1 min or 1 hour. no affect.
@@robojax thank you sir
NC is normally closed. Not normally connected
You are right. But connected make more sense than closed. For some people closed means the path to current is closed. Which means not connected.
my adruino sey : pbuttonPin was not declaret in thids scope
You must be doing something wrong. Please post your code in this page codeshare.io/ and it will create a URL (addres) for your code, then copy and paste the code by replying to this message.
أهلاً وسهلاً ومرحباً بك-يتعذر التعليق-لا أعلم .
How to control relay with keypad ?
Here are my videos on keypad th-cam.com/users/robojaxTVsearch?query=keypad
just combined them.
Usually we use booalean for 1 and 0 states
by definition Boolean has value of TRUE or FALSE but in Arduino IDE, if you use 1 and 0 it wont 'give you error and works.
where is the sketch of this video ?
I just watched the video making sure I have mentioned it and yes I have mentioned it that the code is under the video in the description or you can visit my website. here is how snipboard.io/EG4O2l.jpg
Nice bro
Thanks
Thank you sir.
you are welcome.
Sir where's the code?
under the video in the description of the video.
thank you sir ,, but please code
The link is in the description under tthe video.
@@robojax thank you sir
you are welcome.
@@robojax hi sir, please ,,, i need your help very urgent
how to ensure the wiring between an ACS712 5A sensor + 5v relay + Arduino + a Push button
(I trained to carry out my end of study project. The objective of this project is therefore to find a solution to the problems of Smartphone charger accidents. home fires start,
We have arrived at an intermediate investigation between the network and the charger. This media is automatically disconnected when the charger is empty or when the battery charge level reaches 100%.) (When you appear on the push button, the phone is charging and when the charger is
empty or the battery is 100% reached, the relay disconnects.)
thx
You are welcome.
Thank you.
you are welcome.
SIR plz help me
you did not mention the problem. how can I help you?
Thanks but this little code for everything I did
int relay1 =11;
int but =9;
int val ;
void setup() {
pinMode(but,INPUT_PULLUP);
pinMode(relay1,OUTPUT);
}
void loop() {
val=digitalRead(relay1);
if (digitalRead(but)==LOW){
digitalWrite(relay1,!val);
delay(500);
}
}
onnnlyyyy
you are welcome. Yes. there are many ways to do it.
Thank you! Very nice video.
Thank you very much
You are welcome