Рет қаралды 55
Today I will show you how to use a Keyestudio 5v relay to control a dc motor.
Most dc motors are too large to connect directly to an arduino, so you need a power supply too. It is an electromagnetic switching device used to control a large current with a smaller current.
Code:
void setup() {
// put your setup code here, to run once:
pinMode(8,OUTPUT); // Sets the pin that will be used to trigger the relay.
}
void loop() {
// put your main code here, to run repeatedly:
digitalWrite(8,HIGH); // Turns the relay on.
delay(1500); // Waits 1500 milliseconds or 1.5 seconds.
digitalWrite(8,LOW); // Turns the relay off.
delay(1500); // Waits 1500 milliseconds or 1.5 seconds.
}