Devices & Components
Jumper wires (generic)
SparkFun FTDI Basic Breakout - 3.3V
Male-Header 5 Position- 1 Row- Long (0.1")
Sonoff Basic
Hardware & Tools
Soldering iron (generic)
Software & Tools
Arduino IoT Cloud
Project description
Code
Full Code
arduino
1/* 2This sketch only works with IoT Cloud, with the right variables created inside of your Thing. 3*/ 4 5#include "thingProperties.h" 6 7 8//define the outputs 9int relayPin = 12; 10int ledPin = 13; 11 12void setup() { 13 // Initialize serial and wait for port to open: 14 Serial.begin(9600); 15 16 pinMode(relayPin, OUTPUT); //define relay as output 17 18 // This delay gives the chance to wait for a Serial Monitor without blocking if none is found 19 delay(1500); 20 21 // Defined in thingProperties.h 22 initProperties(); 23 24 // Connect to Arduino IoT Cloud 25 ArduinoCloud.begin(ArduinoIoTPreferredConnection); 26 27 /* 28 The following function allows you to obtain more information 29 related to the state of network and IoT Cloud connection and errors 30 the higher number the more granular information you’ll get. 31 The default is 0 (only errors). 32 Maximum is 4 33 */ 34 setDebugMessageLevel(2); 35 ArduinoCloud.printDebugInfo(); 36} 37 38void loop() { 39 ArduinoCloud.update(); 40 //leave the loop empty 41} 42 43void onRelayChange() { 44 // Add your code here to act upon Relay change 45 if (relay) { 46 digitalWrite(relayPin, HIGH); 47 digitalWrite(ledPin, HIGH); 48 } 49 else { 50 digitalWrite(relayPin, LOW); 51 digitalWrite(ledPin, LOW); 52 } 53}
Full Code
arduino
1/* 2This sketch only works with IoT Cloud, with the right variables 3 created inside of your Thing. 4*/ 5 6#include "thingProperties.h" 7 8 9//define 10 the outputs 11int relayPin = 12; 12int ledPin = 13; 13 14void setup() { 15 16 // Initialize serial and wait for port to open: 17 Serial.begin(9600); 18 19 20 pinMode(relayPin, OUTPUT); //define relay as output 21 22 // This delay gives 23 the chance to wait for a Serial Monitor without blocking if none is found 24 delay(1500); 25 26 27 // Defined in thingProperties.h 28 initProperties(); 29 30 // Connect to 31 Arduino IoT Cloud 32 ArduinoCloud.begin(ArduinoIoTPreferredConnection); 33 34 35 /* 36 The following function allows you to obtain more information 37 related 38 to the state of network and IoT Cloud connection and errors 39 the higher number 40 the more granular information you’ll get. 41 The default is 0 (only errors). 42 43 Maximum is 4 44 */ 45 setDebugMessageLevel(2); 46 ArduinoCloud.printDebugInfo(); 47} 48 49void 50 loop() { 51 ArduinoCloud.update(); 52 //leave the loop empty 53} 54 55void 56 onRelayChange() { 57 // Add your code here to act upon Relay change 58 if (relay) 59 { 60 digitalWrite(relayPin, HIGH); 61 digitalWrite(ledPin, HIGH); 62 } 63 64 else { 65 digitalWrite(relayPin, LOW); 66 digitalWrite(ledPin, LOW); 67 68 } 69}
Downloadable files
Circuit
Circuit

Schematic
Schematic

Circuit
Circuit

Comments
Only logged in users can leave comments