Bulb ON OFF with Push Button

 


 *  RobotDyn AC Switch
 *  
 *  Turn AC Load ON or OFF with Triac BTA16 600B module and Arduino with 1 push button
 *  
 *  the AC load is turned ON using ONE push button (Push ON, Push OFF)
 *  
 *  Written by Ahmad Shamshiri on Friday Oct 27, 2019 at 18:50 in Ajax, Ontario, Canada
 *  
 * Watch video instruction for this code :https://youtu.be/Nlpkt1jB1NY
 * 

 * Get this code and other Arduino codes from Robojax.com
Learn Arduino step by step in structured course with all material, wiring diagram and library
all in once place. Purchase My course on Udemy.com http://robojax.com/L/?id=62

If you found this tutorial helpful, please support me so I can continue creating 
content like this. You can support me on Patreon http://robojax.com/L/?id=63

or make donation using PayPal http://robojax.com/L/?id=64

 *  * This code is "AS IS" without warranty or liability. Free to be used as long as you keep this note intact.* 
 * This code has been download from Robojax.com
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */

#define pushButton 2 // push button to turn ON ond OFF (watch video instruction)
#define powerControlPin 5 //


int loadState = 1;// initial state of load, 1=ON, 0=OFF
 
void setup() {
  Serial.begin(9600);
  pinMode(powerControlPin, OUTPUT);
  
  pinMode(pushButton, INPUT_PULLUP);//push button to turn AC load ON or OFF
  Serial.println("Robojax AC Switch Demo with Push ON, Push OFF");
}

void loop() 
{
  if( digitalRead(pushButton) == LOW)
  {
    loadState = 1-loadState;
    delay(200);

  }
    if(loadState ==1)
    {
    Serial.println("load ON");
    }else{
     Serial.println("load OFF");     
    }
   digitalWrite(powerControlPin,loadState);
  

}// loop end


   

Post a Comment

Previous Post Next Post

Contact Form