Control an AC Bulb with an Arduino AC Switch Using Two Push Buttons
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
263-Arduino Code to control Triac BTA16 600B RobotDyn AC Switch module
语言: C++
/**************
* RobotDyn AC Switch
*
* Turn AC Load ON or OFF with Triac BTA16 600B module and Arduino
* The AC load is turned ON using a push button switch and turned OFF using another push button switch
*
* 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/stCqftdAjI4
*
* Get this code and other Arduino codes from Robojax.com
Learn Arduino step by step in a structured course with all materials, 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 switchTurnON 2
#define switchTurnOFF 3
#define powerControlPin 5 //
const int loadON = HIGH;
const int loadOFF = LOW;
int loadState = loadOFF;// initial state of load
void setup() {
Serial.begin(9600);
pinMode(powerControlPin, OUTPUT);
pinMode(switchTurnON, INPUT_PULLUP);//push button to turn AC load ON
pinMode(switchTurnOFF, INPUT_PULLUP);//push button to turn AC load OFF
Serial.println("Robojax AC Switch Demo");
}
void loop()
{
if( digitalRead(switchTurnON) == LOW)
{
loadState = loadON;
delay(100);
Serial.println("load ON");
}
if( digitalRead(switchTurnOFF) == LOW)
{
loadState = loadOFF;
delay(100);
Serial.println("load OFF");
}
digitalWrite(powerControlPin,loadState);
}// loop end
资源与参考
-
外部BTA16-600B 可控硅数据表(PDF)st.com
文件📁
没有可用的文件。