Professional Documents
Culture Documents
1 Button (Coding Arduino)
1 Button (Coding Arduino)
1 Button (Coding Arduino)
*
* Written by Ahmad Nejrabi for Roboja Video,
www.Robojax.com
* Date: Dec 14, 2017, in Ajax, Ontario, Canada
* 2 button added Feb 09, 2018 for 1 button at 08:51
* Permission granted to share this code given that
this
* note is kept with the code.
* Disclaimer: this code is "AS IS" and for educational
purpose only.
* http://robojax.com/learn/arduino/
*
*/
void setup() {
// Robojax.com code and video tutorial for push
button ON and OFF
Serial.begin(9600);
pinMode(pbuttonPin, INPUT_PULLUP);
pinMode(relayPin, OUTPUT);
pinMode(pbuttonPin2, INPUT_PULLUP);
pinMode(relayPin2, OUTPUT);
void loop() {
// Robojax.com code and video tutorial for push button
ON and OFF (2 relay)
val = digitalRead(pbuttonPin);// read the push button
value
val2 = digitalRead(pbuttonPin2);// read the push
button 2 value
pushed = 1-pushed;
delay(100);
}
if(pushed == HIGH){
Serial.println("Light ON");
digitalWrite(relayPin, LOW);
}else{
Serial.println("Light OFF");
digitalWrite(relayPin, HIGH);
pushed2 = 1-pushed2;
delay(100);
}
lightON2 = val2;
if(pushed2 == HIGH){
Serial.println("Light ON");
digitalWrite(relayPin2, LOW);
}else{
Serial.println("Light OFF");
digitalWrite(relayPin2, HIGH);