搜索代码

How to Control an Actuator Using an Arduino and Two Push Buttons

How to Control an Actuator Using an Arduino and Two Push Buttons

This video shows how to control an actuator with two relays and an Arduino. We have two push buttons; one is used to push and the other is used to pull the actuator. This project can work with virtually any actuator and any voltage. Any Arduino module can be used.

282-Code Controlling Actuator using Arduino
语言: C++
++
/*
 * Arduino Code to control DC Actuator using Arduino
 * 
 * This is basic code. I have advanced code which can be used in both 
 * for low-level trigger and high-level trigger relay with clean code.
 * 
 * Written by Ahmad Shamshiri for Robojax.com on 
 * Friday, January 3, 2019 
 * at 17:37 in Ajax, Ontario, Canada
 * Watch video instruction for this code: https://youtu.be/EaoB6lfnS7g
 * 
 * 
 * 
 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/>.
 */


const int relay1 = 2;
const int relay2 = 3;
const int pushButton1=8;
const int pushButton2=9;


void actuatorPull();
void actuatorPush();
void turnOFF();

void setup() {
 // Robojax Actuator code https://youtu.be/_bkNOyPElOo
    pinMode(relay1, OUTPUT);// set pin as output for relay 1
    pinMode(relay2, OUTPUT);// set pin as output for relay 2
    pinMode(pushButton1, INPUT_PULLUP);
    pinMode(pushButton2, INPUT_PULLUP);
    
    // keep the motor off by keeping both HIGH
    digitalWrite(relay1, HIGH); 
    digitalWrite(relay2, HIGH); 

 
  
  Serial.begin(9600);// initialize serial monitor with 9600 baud
  Serial.println("Robojax Actuator Control");
  Serial.println("Using 2 Relays");  
  delay(2000);
}

void loop() {
   // Robojax Actuator code https://youtu.be/_bkNOyPElOo
  while(digitalRead(pushButton1) ==LOW)
  {
   actuatorPull();
  }

  while(digitalRead(pushButton2) ==LOW)
  { 
    actuatorPush();
  }
  
   turnOFF();
          
}// loop end

/*
 * pushes the actuator
 * written by Ahmad Shamshiri 
 * www.Robojax.com
 * Written on January 3, 2019 in Ajax, Ontario, Canada 
 */
void actuatorPush()
{
   // Robojax Actuator code https://youtu.be/_bkNOyPElOo
    digitalWrite(relay1, LOW);// turn relay 1 ON
    digitalWrite(relay2, HIGH);// turn relay 2 OFF  

}//actuatorPush()

/*
 * pulls the actuator
 * written by Ahmad Shamshiri 
 * www.Robojax.com
 * Written on January 3, 2019 in Ajax, Ontario, Canada 
 */
void actuatorPull()
{
   // Robojax Actuator code https://youtu.be/_bkNOyPElOo
    digitalWrite(relay1, HIGH);// turn relay 1 OFF
    digitalWrite(relay2, LOW);// turn relay 2 ON
 
}//actuatorPull()

/*
 * turn off the actuator
 * written by Ahmad Shamshiri 
 * www.Robojax.com
 * Written on January 3, 2019 in Ajax, Ontario, Canada 
 */
void turnOFF()
{
   // Robojax Actuator code https://youtu.be/_bkNOyPElOo
    digitalWrite(relay1, HIGH);// turn relay 1 OFF
    digitalWrite(relay2, HIGH);// turn relay 2 OFF

}//turnOFF()

|||您可能需要的东西

文件📁

没有可用的文件。