Arduino IoT Cloud Amazon Alexa Integration

Kuo, Li-Wen
2 min readApr 6, 2021

--

/*
Sketch generated by the Arduino IoT Cloud Thing “Office”
https://create.arduino.cc/cloud/things/f2c77d46-5abb-41e2-a8bb-3990155f342c

Arduino IoT Cloud Properties description

The following variables are automatically generated and updated when changes are made to the Thing properties

CloudTemperature temperature;
CloudDimmedLight meetingRoom;
CloudColoredLight loungeArea;

Properties which are marked as READ/WRITE in the Cloud Thing will also have functions
which are called when their values are changed from the Dashboard.
These functions are generated with the Thing and added at the end of this sketch.
*/

#include “thingProperties.h”
#include <Arduino_MKRENV.h>

#define PIN_MEETING_ROOM 5
#define PIN_LOUNGE_AREA_R 2
#define PIN_LOUNGE_AREA_B 3
#define PIN_LOUNGE_AREA_G 4

void setup() {
// Initialize serial and wait for port to open:
Serial.begin(9600);
// This delay gives the chance to wait for a Serial Monitor without blocking if none is found
delay(1500);

if (!ENV.begin()) {
Serial.println(“Failed to initialize MKR ENV shield!”);
while (1);
}

// Defined in thingProperties.h
initProperties();

// Connect to Arduino IoT Cloud
ArduinoCloud.begin(ArduinoIoTPreferredConnection);

/*
The following function allows you to obtain more information
related to the state of network and IoT Cloud connection and errors
the higher number the more granular information you’ll get.
The default is 0 (only errors).
Maximum is 4
*/
setDebugMessageLevel(2);
ArduinoCloud.printDebugInfo();
}

void loop() {
ArduinoCloud.update();
// Your code here
temperature = ENV.readTemperature();
delay(1000);
}

void onMeetingRoomChange() {
uint8_t brightness = map(meetingRoom.getBrightness(), 0, 100, 0, 255);
if (meetingRoom.getSwitch()) {
Serial.println(brightness);
analogWrite(PIN_MEETING_ROOM, brightness);
}
else{
analogWrite(PIN_MEETING_ROOM, LOW);
}
}

void onLoungeAreaChange() {
uint8_t r, g, b;
loungeArea.getValue().getRGB(r, g, b);
if (loungeArea.getSwitch()) {
Serial.println(“R:”+String(r)+” G:”+String(g)+ “ B:”+String(b));
analogWrite(PIN_LOUNGE_AREA_R, r);
analogWrite(PIN_LOUNGE_AREA_B, b);
analogWrite(PIN_LOUNGE_AREA_G, g);
}
else{
Serial.println(“Lamp Off”);
analogWrite(PIN_LOUNGE_AREA_R, 0);
analogWrite(PIN_LOUNGE_AREA_B, 0);
analogWrite(PIN_LOUGE_AREA_G, 0);
}
}

--

--

No responses yet