Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

Arduino MKR WiFi 1010 Controlled Relay Switching Circuit

View and Edit Project In Cirkit DesignerImage of Arduino MKR WiFi 1010 Controlled Relay Switching Circuit

Circuit Documentation

Summary of the Circuit

This circuit consists of an Arduino MKR WiFi 1010 microcontroller board interfaced with a 5V relay. The Arduino MKR WiFi 1010 is responsible for controlling the relay based on the data received from a LoRa communication module. The relay can switch a separate circuit on or off, which could be used for controlling power to an external device.

Component List

Arduino MKR WiFi 1010

5V Relay

Wiring Details

Arduino MKR WiFi 1010

5V Relay

Documented Code

#include <SPI.h>
#include <LoRa.h>

String contents = "";
String buttonPress = "button pressed";
bool x;

int led = 2;

void setup() {
  pinMode(led, OUTPUT);
  Serial.begin(9600);
  while (!Serial);
  Serial.println("LoRa Receiver");

  if (!LoRa.begin(868E6)) {
    Serial.println("Starting LoRa failed!");
    while (1);
  }
}

void loop() {
  int packetSize = LoRa.parsePacket();
  if (packetSize) {
    Serial.print("Received packet '");

    while (LoRa.available()) {  
      contents += (char)LoRa.read();
    }

    Serial.println(contents);
    Serial.print("' with RSSI ");
    Serial.println(LoRa.packetRssi());
  
    if(contents.equals(buttonPress)){
      x = !x;
    }

    if(x == true) {
      digitalWrite(led, HIGH);
      Serial.println("led on");
    }
    else {
      digitalWrite(led, LOW);
      Serial.println("led off");
    }
    
    contents = "";
  }
}

Filename: sketch.ino

Description: This code is designed to run on the Arduino MKR WiFi 1010. It initializes a LoRa communication module and waits for incoming packets. When a packet is received, it checks if the packet content matches a predefined string "button pressed". If it does, it toggles the state of an LED connected to pin D2, which also controls the relay state. The code also prints the received message and the RSSI (Received Signal Strength Indicator) to the serial monitor.