Control an AC bulb with an Arduino AC switch using one push button (push-on, push-off)
This video shows how to turn on or off an AC load with an Arduino using a RobotDyn AC Switch Module and a single push button. Push on and push off.
Resources for this sketch
258-Resources for this sketch
Язык: C++
++
/**************
* 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, October 27, 2019 at 18:50 in Ajax, Ontario, Canada
*
* Watch video instructions for this code: https://youtu.be/Nlpkt1jB1NY
*
* Get this code and other Arduino codes from Robojax.com
Learn Arduino step by step in a structured course with all material, wiring diagrams, and libraries
all in one place.
If you found this tutorial helpful, please support me so I can continue creating
content like this.
or make a 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 downloaded 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 and OFF (watch video instructions)
#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
Ресурсы и ссылки
Ресурсов пока нет.
Файлы📁
Нет доступных файлов.