Devices & Components
Arduino® Nano ESP32
Servomotor Tower Pro SG 90
Basic Red 5mm LED
Geared DC Motor
Hardware & Tools
Hot glue gun (generic)
Soldering kit
Software & Tools
Arduino IDE
Arduino IoT Cloud
Project description
Code
Code for home automation
js
this code is generated using Arduino IOT Cloud
1/* 2 Sketch generated by the Arduino IoT Cloud Thing "Untitled" 3 https://create.arduino.cc/cloud/things/681ea777-4dd4-4919-ae36-0e1873cecb83 4 5 Arduino IoT Cloud Variables description 6 7 The following variables are automatically generated and updated when changes are made to the Thing 8 9 String msg; 10 int angle; 11 int data; 12 bool status; 13 bool val; 14 15 Variables which are marked as READ/WRITE in the Cloud Thing will also have functions 16 which are called when their values are changed from the Dashboard. 17 These functions are generated with the Thing and added at the end of this sketch. 18*/ 19 20#include "thingProperties.h" 21 22#include <SoftwareSerial.h> 23SoftwareSerial mySerial(3, 4); // RX, TX 24 25int LED = 10; 26int MOTOR = 7; 27int EN = 5; 28int SERVO = 9; 29int SENSOR = A6; 30 31 32 33 34 35void Sendtext(String a, String b){ 36 mySerial.print(a+".txt=\""+b+"\""); 37 mySerial.write(0xff); 38 mySerial.write(0xff); 39 mySerial.write(0xff); 40} 41 42 43 44void setup() { 45 // Initialize serial and wait for port to open: 46 Serial.begin(9600); 47 mySerial.begin(9600); 48 pinMode(LED,OUTPUT); 49 pinMode(MOTOR,OUTPUT); 50 pinMode(SERVO,OUTPUT); 51 pinMode(EN,OUTPUT); 52 53 digitalWrite(EN,HIGH); 54 55 // This delay gives the chance to wait for a Serial Monitor without blocking if none is found 56 delay(1500); 57 58 // Defined in thingProperties.h 59 initProperties(); 60 61 // Connect to Arduino IoT Cloud 62 ArduinoCloud.begin(ArduinoIoTPreferredConnection); 63 64 /* 65 The following function allows you to obtain more information 66 related to the state of network and IoT Cloud connection and errors 67 the higher number the more granular information you’ll get. 68 The default is 0 (only errors). 69 Maximum is 4 70 */ 71 setDebugMessageLevel(2); 72 ArduinoCloud.printDebugInfo(); 73 } 74 75 76 77 78 79 80void loop() { 81 ArduinoCloud.update(); 82 data = analogRead(A6); 83 int pulsewidth = map(angle,0,180,544,2400); 84 digitalWrite(SERVO,HIGH); 85 delayMicroseconds(pulsewidth); 86 digitalWrite(SERVO,LOW); 87 88 Sendtext("t1",msg); 89 90 91} 92 93 94 95/* 96 Since Val is READ_WRITE variable, onValChange() is 97 executed every time a new value is received from IoT Cloud. 98*/ 99void onValChange() { 100 digitalWrite(LED,val); 101} 102 103/* 104 Since Status is READ_WRITE variable, onStatusChange() is 105 executed every time a new value is received from IoT Cloud. 106*/ 107void onStatusChange() { 108 digitalWrite(MOTOR,status); 109} 110 111/* 112 Since Angle is READ_WRITE variable, onAngleChange() is 113 executed every time a new value is received from IoT Cloud. 114*/ 115void onAngleChange() { 116// servomove(angle); 117} 118 119 120 121 122/* 123 Since Msg is READ_WRITE variable, onMsgChange() is 124 executed every time a new value is received from IoT Cloud. 125*/ 126void onMsgChange() { 127 // Add your code here to act upon Msg change 128}
Downloadable files
HMI File
nextion 3.2 inch hmi
ARDUINO ESP32.HMI
Documentation
Arduino nano esp32 official documentation
https://docs.arduino.cc/hardware/nano-esp32
Comments
Only logged in users can leave comments