How to do it...

Before moving to the software side, you must properly configure the electronic components:

  1. Perform all the necessary steps to build the circuit, as shown in the following diagram:
Figure 10.3: Circuit sketch
  1. Compile and upload the following Sketch to Arduino:
int relay_pin_1 = 8;int relay_pin_2 = 9;String command;char receivedChar;// read from serial and concat it to commandvoid readFromSerial() {  while (Serial.available() > 0) {    receivedChar = Serial.read();    command.concat(receivedChar);    delay(10);  }}void setup() {  // put your setup code here, to run once:  pinMode(relay_pin_1, OUTPUT);  pinMode(relay_pin_2, OUTPUT); digitalWrite(relay_pin_1, ...

Get Delphi Cookbook - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.