Interfacing Arduino with 5V Relay /
Controlling High Voltage Device with Arduino
Code in Action:
See also:
Code:
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2);
// defines relayPin
const int relayPin = 2;
// defines variables
void setup() {
lcd.init(); // initialize the lcd
lcd.backlight(); // lcd backlight ON
lcd.setCursor(0,0); // 0 row, 0 column
pinMode(relayPin, OUTPUT); // Sets the relayPin as an Output
}
void loop() {
lcd.clear();
// Clears the trigPin
digitalWrite(relayPin, HIGH);
lcd.clear();
lcd.print("Relay OFF");
delay(1000);
digitalWrite(relayPin, LOW);
lcd.clear();
lcd.print("Relay ON");
delay(1000);
}
No comments:
Post a Comment