#include <LiquidCrystal_I2C.h>
#include <stdio.h>
const int lcdAddress = 0x27;
LiquidCrystal_I2C lcd(lcdAddress, 16, 2);
const int relayPin = 2;
const String turnOn = "ON";
const String turnOff = "OFF";
void setup() {
Serial.begin(9600);
lcd.init();
lcd.backlight();
redirectLCDOutput();
printf("LED: OFF");
pinMode(relayPin, OUTPUT);
digitalWrite(relayPin, LOW);
redirectSerialOutput();
printf("Commands:\nON Turn on the relay\nOFF Turn off the relay");
}
void loop() {
redirectLCDOutput();
if (Serial.available() > 0) {
String command = Serial.readStringUntil('\n');
if (command == turnOn) {
digitalWrite(relayPin, HIGH);
printf("LED: ON ");
} else if (command == turnOff) {
digitalWrite(relayPin, LOW);
printf("LED: OFF");
}
}
}
uno:A5.2
uno:A4.2
uno:AREF
uno:GND.1
uno:13
uno:12
uno:11
uno:10
uno:9
uno:8
uno:7
uno:6
uno:5
uno:4
uno:3
uno:2
uno:1
uno:0
uno:IOREF
uno:RESET
uno:3.3V
uno:5V
uno:GND.2
uno:GND.3
uno:VIN
uno:A0
uno:A1
uno:A2
uno:A3
uno:A4
uno:A5
relay1:VCC
relay1:GND
relay1:IN
relay1:NC
relay1:COM
relay1:NO
led1:A
led1:C
lcd1:GND
lcd1:VCC
lcd1:SDA
lcd1:SCL
r1:1
r1:2