diff --git a/Code for IDE (Telegram Bot)/IDE_LDR/IDE_LDR.ino b/Code for IDE (Telegram Bot)/IDE_LDR/IDE_LDR.ino index a2e234b..2b6a3e0 100644 --- a/Code for IDE (Telegram Bot)/IDE_LDR/IDE_LDR.ino +++ b/Code for IDE (Telegram Bot)/IDE_LDR/IDE_LDR.ino @@ -1,4 +1,4 @@ -//This is LDR with Telegram +//Telegram Bot with Light-Dependent-Resistor #include #include @@ -13,8 +13,8 @@ char PASS[] = " "; WiFiSSLClient client; UniversalTelegramBot bot(BOTtoken, client); -int Bot_mtbs = 1000; -long Bot_lasttime; +int Bot_mtbs = 1000; //mean time between messages +long Bot_lasttime; //last scan messages which is done int LDRvalue; @@ -54,9 +54,9 @@ void loop() { for (int i = 0; i < numNewMessages; i++) { - if (bot.messages[i].text == "/LDR") + if (bot.messages[i].text == "/LDR") //NOTE to give the LDR ~30 seconds time { - if (LDRvalue <= 200) + if (LDRvalue <= 200) //lowest detection of LDR are below 200 (if you cover it with your finger and wait) bot.sendMessage(bot.messages[i].chat_id, "DARK : Analog Value = " + String(LDRvalue), ""); else if (LDRvalue > 200 && LDRvalue <= 500) @@ -65,7 +65,7 @@ void loop() { else if (LDRvalue > 500 && LDRvalue <= 800) bot.sendMessage(bot.messages[i].chat_id, "BRIGHT LIGHT : Analog Value = " + String(LDRvalue), ""); - else if (LDRvalue > 800) + else if (LDRvalue > 800) //highest detection of LDR is above 800 (if you point a flash-light and wait) bot.sendMessage(bot.messages[i].chat_id, "FULL DAY LIGHT : Analog Value = " + String(LDRvalue), ""); } @@ -73,7 +73,7 @@ void loop() { if (bot.messages[i].text == "help") { - bot.sendMessage(bot.messages[i].chat_id, "Hello ASSEMBLY attendee! I am your bot! \n Use following commands: \n /ON - turns on the LED connected \n /OFF - turns off LED connected \n /TEMP - gives temperature \n /HUMID - gives humidity \n /Increase - increases LED brightness \n /Decrease - decreases LED brightness \n /ONservo - pushes servo out \n /OFFservo - pulls servo back \n /TRYservo - test servo", ""); + bot.sendMessage(bot.messages[i].chat_id, "Hello ASSEMBLY attendee! I am your bot! \n Use following commands: \n /ON - turns on the LED connected \n /OFF - turns off LED connected \n /TEMP - gives temperature \n /HUMID - gives humidity \n /Increase - increases LED brightness \n /Decrease - decreases LED brightness \n /FADE - shows led fading \n /ONservo - pushes servo out \n /OFFservo - pulls servo back \n /TRYservo - test servo", ""); } diff --git a/Code for IDE (Telegram Bot)/IDE_LED/IDE_LED.ino b/Code for IDE (Telegram Bot)/IDE_LED/IDE_LED.ino index 79e9a5b..4de636e 100644 --- a/Code for IDE (Telegram Bot)/IDE_LED/IDE_LED.ino +++ b/Code for IDE (Telegram Bot)/IDE_LED/IDE_LED.ino @@ -1,19 +1,19 @@ -//This is for the Telegram Bot with LED alone (ON, OFF, FADE) +//Telegram Bot with LED alone for ON, OFF, FADE -#include //for creating wifi connection +#include //for creating wifi connection #include //for the Telegram bot -char SSID[] = " "; //insert network name -char PASS[] = " "; //insert network password +char SSID[] = " "; //insert network name +char PASS[] = " "; //insert network password -#define BOTtoken " " //insert your unique BOT token +#define BOTtoken " " //insert your unique BOT token #define LEDPIN 2 int pulse = 0 ; WiFiSSLClient client; UniversalTelegramBot bot(BOTtoken, client); -int Bot_mtbs = 1000; -long Bot_lasttime; +int Bot_mtbs = 1000; //mean time between scan messages +long Bot_lasttime; //last time scan has been done void setup() { @@ -49,16 +49,14 @@ void loop() { for (int i = 0; i < numNewMessages; i++) { if (bot.messages[i].text == "/ON") { - pulse = pulse+255; + pulse = 255; bot.sendMessage(bot.messages[i].chat_id,"LED is ON!", ""); - // will print the value of the pulse in the serial monitor } - if (bot.messages[i].text == "/Increase") { // if you sent this command to your bot + if (bot.messages[i].text == "/Increase") { if(pulse <= 225 ) //if pulse is smaller than or equal to 255 { pulse = pulse+30; // add 30 to the pulse - bot.sendMessage(bot.messages[i].chat_id,"Brightness Increased!", ""); // the message the bot will send to you - // will print the value of the pulse in the serial monitor + bot.sendMessage(bot.messages[i].chat_id,"Brightness Increased!", ""); } else @@ -84,10 +82,10 @@ void loop() { } - if (bot.messages[i].text == "/OFF") { // if you text the bot /OFF - pulse = 0; // the pulse will be set to 0 (it will be turned off) + if (bot.messages[i].text == "/OFF") { + pulse = 0; // the pulse will be set to 0 (turned off) bot.sendMessage(bot.messages[i].chat_id,"LED is OFF!", ""); // The bot will notifiy you that it is turned off - Serial.println(pulse); // will print the value of the pulse in the serial monitor + Serial.println(pulse); // will print the value of the pulse in the serial monitor } if (bot.messages[i].text == "/FADE") @@ -108,13 +106,13 @@ void loop() { } pulse = 0; - bot.sendMessage(bot.messages[i].chat_id,"LED has faded!", ""); // The bot will notifiy you that it is turned off + bot.sendMessage(bot.messages[i].chat_id,"LED has faded!", ""); // The bot will notifiy you that it has faded } if (bot.messages[i].text == "help") { - bot.sendMessage(bot.messages[i].chat_id, "Hello ASSEMBLY attendee! I am your bot! \n Use following commands: \n /ON - turns on the LED connected \n /OFF - turns off LED connected \n /TEMP - gives temperature \n /HUMID - gives humidity \n /FADE - shows you the LED fading \n /Increase - increases LED brightness \n /Decrease - decreases LED brightness \n /ONservo - pushes servo out \n /OFFservo - pulls servo back \n /TRYservo - test servo", ""); + bot.sendMessage(bot.messages[i].chat_id, "Hello ASSEMBLY attendee! I am your bot! \n Use following commands: \n /ON - turns on the LED connected \n /OFF - turns off LED connected \n /TEMP - gives temperature \n /HUMID - gives humidity \n /FADE - shows you the LED fading \n /Increase - increases LED brightness \n /Decrease - decreases LED brightness \n /FADE - shows led fading \n /ONservo - pushes servo out \n /OFFservo - pulls servo back \n /TRYservo - test servo", ""); } diff --git a/Code for IDE (Telegram Bot)/IDE_Servo/IDE_Servo.ino b/Code for IDE (Telegram Bot)/IDE_Servo/IDE_Servo.ino index 98dd91e..64ac564 100644 --- a/Code for IDE (Telegram Bot)/IDE_Servo/IDE_Servo.ino +++ b/Code for IDE (Telegram Bot)/IDE_Servo/IDE_Servo.ino @@ -9,13 +9,13 @@ char SSID[] = " "; // ENTER NETWORK SSID & PASS char PASS[] = " "; #define BOTtoken " " //YOUR BOT TOKEN -#define servoPin 13 +#define servoPin 13 // Servo to 5V and signal to pin 13 WiFiSSLClient client; UniversalTelegramBot bot(BOTtoken, client); -int Bot_mtbs = 1000; -long Bot_lasttime; +int Bot_mtbs = 1000; //mean time between messages +long Bot_lasttime; //last scan Servo myservo; // create servo object to control a servo @@ -51,14 +51,14 @@ void loop() { Serial.println("Got response from Telegram bot"); for (int i = 0; i < numNewMessages; i++) { - - if (bot.messages[i].text == "/ONservo") { + myservo.attach(servoPin); myservo.write(90); // sets the servo position bot.sendMessage(bot.messages[i].chat_id, "Servo is ON", ""); } if (bot.messages[i].text == "/OFFservo") { + myservo.write(0); myservo.detach(); // sets the servo position bot.sendMessage(bot.messages[i].chat_id, "Servo is OFF", ""); } @@ -78,7 +78,7 @@ void loop() { if (bot.messages[i].text == "help") { - bot.sendMessage(bot.messages[i].chat_id, "Hello ASSEMBLY attendee! I am your bot! \n Use following commands: \n /ON - turns on the LED connected \n /OFF - turns off LED connected \n /TEMP - gives temperature \n /HUMID - gives humidity \n /Increase - increases LED brightness \n /Decrease - decreases LED brightness \n /ONservo - pushes servo out \n /OFFservo - pulls servo back \n /TRYservo - test servo", ""); + bot.sendMessage(bot.messages[i].chat_id, "Hello ASSEMBLY attendee! I am your bot! \n Use following commands: \n /ON - turns on the LED connected \n /OFF - turns off LED connected \n /TEMP - gives temperature \n /HUMID - gives humidity \n /Increase - increases LED brightness \n /Decrease - decreases LED brightness \n /FADE - shows led fading \n /ONservo - pushes servo out \n /OFFservo - pulls servo back \n /TRYservo - test servo", ""); } diff --git a/Code for IDE (Telegram Bot)/IDE_Temperature_Humidity/IDE_Temperature_Humidity.ino b/Code for IDE (Telegram Bot)/IDE_Temperature_Humidity/IDE_Temperature_Humidity.ino index 3aadc4e..07ceb22 100644 --- a/Code for IDE (Telegram Bot)/IDE_Temperature_Humidity/IDE_Temperature_Humidity.ino +++ b/Code for IDE (Telegram Bot)/IDE_Temperature_Humidity/IDE_Temperature_Humidity.ino @@ -1,5 +1,4 @@ -//This is for Temperature sensor ONLY -//with TELEGRAM +//Telegram bot with sensor only #include #include @@ -69,7 +68,7 @@ void loop() { if (bot.messages[i].text == "help") { - bot.sendMessage(bot.messages[i].chat_id, "Hello ASSEMBLY attendee! I am your bot! \n Use following commands: \n /ON - turns on the LED connected \n /OFF - turns off LED connected \n /TEMP - gives temperature \n /HUMID - gives humidity \n /Increase - increases LED brightness \n /Decrease - decreases LED brightness \n /ONservo - pushes servo out \n /OFFservo - pulls servo back \n /TRYservo - test servo", ""); + bot.sendMessage(bot.messages[i].chat_id, "Hello ASSEMBLY attendee! I am your bot! \n Use following commands: \n /ON - turns on the LED connected \n /OFF - turns off LED connected \n /TEMP - gives temperature \n /HUMID - gives humidity \n /Increase - increases LED brightness \n /Decrease - decreases LED brightness \n /FADE - shows led fading \n /ONservo - pushes servo out \n /OFFservo - pulls servo back \n /TRYservo - test servo", ""); } diff --git a/Code for IoT Cloud/IoTCloud_code/IoTCloud_code.ino b/Code for IoT Cloud/IoTCloud_code/IoTCloud_code.ino index d969beb..60d7a8f 100644 --- a/Code for IoT Cloud/IoTCloud_code/IoTCloud_code.ino +++ b/Code for IoT Cloud/IoTCloud_code/IoTCloud_code.ino @@ -1,6 +1,5 @@ -/* - Sketch generated by the Arduino IoT Cloud Thing "bnb" - https://create.arduino.cc/cloud/things/d4947908-6129-40cb-83b8-4b0a58358ad9 +/* + Sketch generated by the Arduino IoT Cloud Thing Arduino IoT Cloud Properties description @@ -16,7 +15,7 @@ */ #include //for sensor #include //for sensor -#include +#include #include "thingProperties.h" @@ -30,55 +29,52 @@ 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); + delay(1500); // Defined in thingProperties.h initProperties(); // Connect to Arduino IoT Cloud - ArduinoCloud.begin(ArduinoIoTPreferredConnection); - + ArduinoCloud.begin(ArduinoIoTPreferredConnection); //initializes Arduino Cloud + /* 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(); - pinMode(ledPin, OUTPUT); - dht.begin(); - + pinMode(LEDPIN, OUTPUT); + dht.begin(); //initializes DHT sensor + } void loop() { - ArduinoCloud.update(); - + ArduinoCloud.update(); //updates Arduino Cloud to check for values onTemperatureChange(); onHumidityChange(); - } -void onLightChange() +void onLightChange() { -analogWrite(LEDPIN, light); + analogWrite(LEDPIN, light); //writes the value of 'light' chosen by widget } void onTemperatureChange() { - - temperature = dht.readTemperature(); + + temperature = dht.readTemperature(); //reads the temperature from sensor + //the variable 'temperature' is automatically generated and declared by the cloud } void onHumidityChange() { - humidity = dht.readHumidity(); + humidity = dht.readHumidity(); //reads humidity from sensor + //the variable 'temperature' is automatically generated and declared by the cloud } - - - diff --git a/Connections/DHT11Sensor_bb.jpg b/Connections/DHT11Sensor_bb.jpg new file mode 100644 index 0000000..bb23129 Binary files /dev/null and b/Connections/DHT11Sensor_bb.jpg differ diff --git a/Connections/FullCircuitforMKR_bb.jpg b/Connections/FullCircuitforMKR_bb.jpg new file mode 100644 index 0000000..dfbd9f6 Binary files /dev/null and b/Connections/FullCircuitforMKR_bb.jpg differ diff --git a/Connections/LDR_bb.jpg b/Connections/LDR_bb.jpg new file mode 100644 index 0000000..6b5281c Binary files /dev/null and b/Connections/LDR_bb.jpg differ diff --git a/Connections/LED_bb.jpg b/Connections/LED_bb.jpg new file mode 100644 index 0000000..67f4201 Binary files /dev/null and b/Connections/LED_bb.jpg differ diff --git a/Connections/ServoMotor_bb.jpg b/Connections/ServoMotor_bb.jpg new file mode 100644 index 0000000..4c49b62 Binary files /dev/null and b/Connections/ServoMotor_bb.jpg differ diff --git a/DHT11Connection.jpg b/DHT11Connection.jpg deleted file mode 100644 index 7e86a4e..0000000 Binary files a/DHT11Connection.jpg and /dev/null differ diff --git a/Code for IDE (Telegram Bot)/IDE_FINAL_all_/IDE_FINAL_all_.ino b/FINAL/FINAL.ino similarity index 62% rename from Code for IDE (Telegram Bot)/IDE_FINAL_all_/IDE_FINAL_all_.ino rename to FINAL/FINAL.ino index 63d5956..a4ef360 100644 --- a/Code for IDE (Telegram Bot)/IDE_FINAL_all_/IDE_FINAL_all_.ino +++ b/FINAL/FINAL.ino @@ -6,10 +6,10 @@ #include //only for Servo -char SSID[] = ""; // ENTER NETWORK SSID & PASS -char PASS[] = ""; +char SSID[] = " "; // ENTER NETWORK SSID & PASS +char PASS[] = " "; -#define BOTtoken "" //YOUR BOT TOKEN +#define BOTtoken " " //YOUR BOT TOKEN #define LEDPIN 2 //YOUR PIN NUMBER ON BOARD #define DHTPIN 5 #define LDRPIN A0 @@ -72,70 +72,69 @@ void loop() { for (int i = 0; i < numNewMessages; i++) { if (bot.messages[i].text == "/ON") { - pulse = pulse+255; - bot.sendMessage(bot.messages[i].chat_id,"LED is ON!", ""); - Serial.println(pulse); // will print the value of the pulse in the serial monitor - } - if (bot.messages[i].text == "/Increase") { // if you sent this command to your bot - if(pulse <= 225 ) //if pulse is smaller than or equal to 255 + pulse = 255; + bot.sendMessage(bot.messages[i].chat_id, "LED is ON!", ""); + + } + if (bot.messages[i].text == "/Increase") { + if (pulse <= 225 ) { - pulse = pulse+30; // add 30 to the pulse - bot.sendMessage(bot.messages[i].chat_id,"Brightness Increased!", ""); // the message the bot will send to you - Serial.println(pulse); // will print the value of the pulse in the serial monitor + pulse = pulse + 30; // add 30 to the pulse + bot.sendMessage(bot.messages[i].chat_id, "Brightness Increased!", ""); // the message the bot will send to you + } - + else { pulse = 255; // if the first condition did not apply then pulse will be 255 bot.sendMessage(bot.messages[i].chat_id, "Cannot increase further! ", ""); } - + } - if (bot.messages[i].text == "/Decrease") { // if you sent this command to your bot - if(pulse >= 30 ) // if the pulse is greater than or equal to 30 - { - pulse = pulse -30 ; // substract 30 - bot.sendMessage(bot.messages[i].chat_id, "Brightness Decreased!", ""); - Serial.println(pulse); // will print the value of the pulse in the serial monitor - - } - else - { - pulse = 0; // otherwise the pulse is 0 - bot.sendMessage(bot.messages[i].chat_id, "Cannot decrease further! ", ""); // the bot will notifiy you that LED cannot be decreased further - } - - - } - if (bot.messages[i].text == "/OFF") { // if you text the bot /OFF - pulse = 0; // the pulse will be set to 0 (it will be turned off) - bot.sendMessage(bot.messages[i].chat_id,"LED is OFF!", ""); // The bot will notifiy you that it is turned off - Serial.println(pulse); // will print the value of the pulse in the serial monitor + if (bot.messages[i].text == "/Decrease") { // if you sent this command to your bot + if (pulse >= 30 ) // if the pulse is greater than or equal to 30 + { + pulse = pulse - 30 ; // substract 30 + bot.sendMessage(bot.messages[i].chat_id, "Brightness Decreased!", ""); + + } + else + { + pulse = 0; // otherwise the pulse is 0 + bot.sendMessage(bot.messages[i].chat_id, "Cannot decrease further! ", ""); // the bot will notifiy you that LED cannot be decreased further } -if (bot.messages[i].text == "/FADE") - { + } + if (bot.messages[i].text == "/OFF") { + pulse = 0; //pulse will be set to 0 (it will be turned off) + bot.sendMessage(bot.messages[i].chat_id, "LED is OFF!", ""); - pulse = 0; - while (pulse < 255) - { - pulse = pulse + 40; - analogWrite(LEDPIN, pulse); - delay(300); } - while (pulse > 0) + + + if (bot.messages[i].text == "/FADE") { - pulse = pulse - 40; - analogWrite(LEDPIN, pulse); - delay(300); + //fades to full brightness then goes back to being off + + pulse = 0; + while (pulse < 255) + { + pulse = pulse + 40; + analogWrite(LEDPIN, pulse); + delay(300); + } + while (pulse > 0) + { + pulse = pulse - 40; + analogWrite(LEDPIN, pulse); + delay(300); + } + pulse = 0; + + bot.sendMessage(bot.messages[i].chat_id, "LED has faded!", ""); } - pulse = 0; - bot.sendMessage(bot.messages[i].chat_id,"LED has faded!", ""); // The bot will notifiy you that it is turned off - - - } if (bot.messages[i].text == "/TEMP") bot.sendMessage(bot.messages[i].chat_id, "Temperature is " + String(myTemperature) + "*C", ""); @@ -144,7 +143,7 @@ if (bot.messages[i].text == "/FADE") if (bot.messages[i].text == "/LDR") { - if (LDRvalue <= 200) + if (LDRvalue <= 200) //least value of detection bot.sendMessage(bot.messages[i].chat_id, "DARK : Analog Value = " + String(LDRvalue), ""); else if (LDRvalue > 200 && LDRvalue <= 500) @@ -158,12 +157,15 @@ if (bot.messages[i].text == "/FADE") } - if (bot.messages[i].text == "/ONservo") { + if (bot.messages[i].text == "/ONservo") + { + myservo.attach(servoPin); myservo.write(90); // sets the servo position bot.sendMessage(bot.messages[i].chat_id, "Servo is ON", ""); } if (bot.messages[i].text == "/OFFservo") { + myservo.write(0); myservo.detach(); // sets the servo position bot.sendMessage(bot.messages[i].chat_id, "Servo is OFF", ""); } @@ -173,7 +175,7 @@ if (bot.messages[i].text == "/FADE") delay(700); myservo.write(90); // sets the servo position delay(700); - myservo.write(0); + myservo.write(0); delay(700); myservo.write(90); // sets the servo position delay(700); @@ -194,5 +196,5 @@ if (bot.messages[i].text == "/FADE") } Bot_lasttime = millis(); } -analogWrite(LEDPIN,pulse); + analogWrite(LEDPIN, pulse); } diff --git a/Final Code/IDE_FINAL_all_/IDE_FINAL_all_.ino b/Final Code/IDE_FINAL_all_/IDE_FINAL_all_.ino deleted file mode 100644 index 63d5956..0000000 --- a/Final Code/IDE_FINAL_all_/IDE_FINAL_all_.ino +++ /dev/null @@ -1,198 +0,0 @@ -#include -#include -#include //for sensor -#include //for sensor -#include //for sensor -#include //only for Servo - - -char SSID[] = ""; // ENTER NETWORK SSID & PASS -char PASS[] = ""; - -#define BOTtoken "" //YOUR BOT TOKEN -#define LEDPIN 2 //YOUR PIN NUMBER ON BOARD -#define DHTPIN 5 -#define LDRPIN A0 -#define DHTTYPE DHT11 -#define servoPin 13 - - -WiFiSSLClient client; -UniversalTelegramBot bot(BOTtoken, client); -int Bot_mtbs = 1000; -long Bot_lasttime; - -Servo myservo; // create servo object to control a servo - -int pulse = 0; //pulse initial value - -// Seensor configuration -DHT dht(DHTPIN, DHTTYPE); -float myTemperature; -float myHumidity; -int LDRvalue; - - -void setup() -{ - Serial.begin(9600); //YOUR SERIAL MONITOR SHOULD BE 9600 - delay(2000); - Serial.print("Connecting to Wifi Network: "); - Serial.println(SSID); - while (WiFi.begin(SSID, PASS) != WL_CONNECTED) - { - Serial.println(".. Loading connection .. "); - delay(500); - } - - Serial.println(""); - Serial.println("WiFi connected"); - Serial.println("IP address: "); - IPAddress ip = WiFi.localIP(); - Serial.println(ip); - Serial.println(" "); - pinMode(LEDPIN, OUTPUT); - myservo.attach(servoPin); // attaches the servo on pin 13 to the servo object - myservo.write(0); // sets the servo position -} -void loop() { - - LDRvalue = analogRead(LDRPIN); - - - - if (millis() > Bot_lasttime + Bot_mtbs) - { - dht.begin(); - myTemperature = dht.readTemperature(); - myHumidity = dht.readHumidity(); - int numNewMessages = bot.getUpdates(bot.last_message_received + 1); - while (numNewMessages) { - Serial.println("Got response from Telegram bot"); - for (int i = 0; i < numNewMessages; i++) { - - if (bot.messages[i].text == "/ON") { - pulse = pulse+255; - bot.sendMessage(bot.messages[i].chat_id,"LED is ON!", ""); - Serial.println(pulse); // will print the value of the pulse in the serial monitor - } - if (bot.messages[i].text == "/Increase") { // if you sent this command to your bot - if(pulse <= 225 ) //if pulse is smaller than or equal to 255 - { - pulse = pulse+30; // add 30 to the pulse - bot.sendMessage(bot.messages[i].chat_id,"Brightness Increased!", ""); // the message the bot will send to you - Serial.println(pulse); // will print the value of the pulse in the serial monitor - } - - else - { - pulse = 255; // if the first condition did not apply then pulse will be 255 - bot.sendMessage(bot.messages[i].chat_id, "Cannot increase further! ", ""); - } - - } - if (bot.messages[i].text == "/Decrease") { // if you sent this command to your bot - if(pulse >= 30 ) // if the pulse is greater than or equal to 30 - { - pulse = pulse -30 ; // substract 30 - bot.sendMessage(bot.messages[i].chat_id, "Brightness Decreased!", ""); - Serial.println(pulse); // will print the value of the pulse in the serial monitor - - } - else - { - pulse = 0; // otherwise the pulse is 0 - bot.sendMessage(bot.messages[i].chat_id, "Cannot decrease further! ", ""); // the bot will notifiy you that LED cannot be decreased further - } - - - } - if (bot.messages[i].text == "/OFF") { // if you text the bot /OFF - pulse = 0; // the pulse will be set to 0 (it will be turned off) - bot.sendMessage(bot.messages[i].chat_id,"LED is OFF!", ""); // The bot will notifiy you that it is turned off - Serial.println(pulse); // will print the value of the pulse in the serial monitor - } - - -if (bot.messages[i].text == "/FADE") - { - - pulse = 0; - while (pulse < 255) - { - pulse = pulse + 40; - analogWrite(LEDPIN, pulse); - delay(300); - } - while (pulse > 0) - { - pulse = pulse - 40; - analogWrite(LEDPIN, pulse); - delay(300); - } - pulse = 0; - - bot.sendMessage(bot.messages[i].chat_id,"LED has faded!", ""); // The bot will notifiy you that it is turned off - - - } - if (bot.messages[i].text == "/TEMP") - bot.sendMessage(bot.messages[i].chat_id, "Temperature is " + String(myTemperature) + "*C", ""); - - if (bot.messages[i].text == "/HUMID") - bot.sendMessage(bot.messages[i].chat_id, "Humidity is " + String(myHumidity) + "%", ""); - - if (bot.messages[i].text == "/LDR") - { - if (LDRvalue <= 200) - bot.sendMessage(bot.messages[i].chat_id, "DARK : Analog Value = " + String(LDRvalue), ""); - - else if (LDRvalue > 200 && LDRvalue <= 500) - bot.sendMessage(bot.messages[i].chat_id, "DIM LIGHT : Analog Value = " + String(LDRvalue), ""); - - else if (LDRvalue > 500 && LDRvalue <= 800) - bot.sendMessage(bot.messages[i].chat_id, "BRIGHT LIGHT : Analog Value = " + String(LDRvalue), ""); - - else if (LDRvalue > 800) - bot.sendMessage(bot.messages[i].chat_id, "FULL DAY LIGHT : Analog Value = " + String(LDRvalue), ""); - - } - - if (bot.messages[i].text == "/ONservo") { - myservo.write(90); // sets the servo position - bot.sendMessage(bot.messages[i].chat_id, "Servo is ON", ""); - } - - if (bot.messages[i].text == "/OFFservo") { - myservo.detach(); // sets the servo position - bot.sendMessage(bot.messages[i].chat_id, "Servo is OFF", ""); - } - - if (bot.messages[i].text == "/TRYservo") { - myservo.write(0); // sets the servo position - delay(700); - myservo.write(90); // sets the servo position - delay(700); - myservo.write(0); - delay(700); - myservo.write(90); // sets the servo position - delay(700); - myservo.write(0); // sets the servo position - bot.sendMessage(bot.messages[i].chat_id, "Servo tested", ""); - } - - if (bot.messages[i].text == "help") - { - bot.sendMessage(bot.messages[i].chat_id, "Hello ASSEMBLY attendee! I am your bot! \n Use following commands: \n /ON - turns on the LED connected \n /OFF - turns off LED connected \n /TEMP - gives temperature \n /HUMID - gives humidity \n /Increase - increases LED brightness \n /Decrease - decreases LED brightness \n /FADE - shows led fading \n /ONservo - pushes servo out \n /OFFservo - pulls servo back \n /TRYservo - test servo", ""); - } - - - Serial.println("User sent " + bot.messages[i].text); - - } - numNewMessages = bot.getUpdates(bot.last_message_received + 1); - } - Bot_lasttime = millis(); - } -analogWrite(LEDPIN,pulse); -} diff --git a/FullCircuitConnetion.jpg b/FullCircuitConnetion.jpg deleted file mode 100644 index 3efdc29..0000000 Binary files a/FullCircuitConnetion.jpg and /dev/null differ diff --git a/LDRconnection.jpg b/LDRconnection.jpg deleted file mode 100644 index 03ade47..0000000 Binary files a/LDRconnection.jpg and /dev/null differ diff --git a/LEDconnection.jpg b/LEDconnection.jpg deleted file mode 100644 index 11591a5..0000000 Binary files a/LEDconnection.jpg and /dev/null differ diff --git a/README.md b/README.md index 989dc43..8b13789 100644 --- a/README.md +++ b/README.md @@ -1,154 +1 @@ -# Arduino_IOT - -PART 1: Arduino IoT cloud -The first method being discussed is setting up this automation system on Arduino IoT cloud. Due to the compilation time limitation, we will only be compiling for an LED and DHT11 temperature sensor and use widgets to control them. - -● Setup: -1. Create an account on Arduino Create -2. Click on Arduino IoT Cloud -3. Follow the instructions on the screen to install Arduino Create Plugin and to setup your WiFi MKR 1010 Board - -● LED and DHT11 sensor: -1. Once the Arduino MKR WiFi 1010 Board is set, create a new ‘Thing’. -2. Click ‘Add Property’ to create a new variable that can also be controlled by the cloud. We need three properties for this task. -3. ‘light’ would be the property for the LED as well as its variable name. -The value type is int and the range is between 0 and 255. -Ensure ‘read and write’ is checked. -4. ‘temperature’ would be the property for the DHT11 sensor as well as its variable name. - The value type is float and the range is between -100 and 100. -Ensure ‘read only’ is checked. -5. ‘Humidity’ is another property for the DHT11 sensor as well as its variable name. -The value type is float and the range is between -100 and 100. -Ensure ‘read only’ is checked. -6. Click ‘Edit Sketch’ -7. On the left click ‘Libraries’ -8. Click ‘Custom’ -9. Import libraries from the github repository ‘All Libraries’ file. We need: - - Adafruit_Sensor.h - - DHT.h -10. From the github repository, find the code to be used called “IoTCloud_code” -11. Delete the existing code in the sketch and copy paste the “IoTCloud_code” -12. In sketch, in the ‘Secret’ Tab, enter the SSID and password of your WiFi network -13. Click ‘Upload’ button at the top -14. Click ‘Go to IoT Cloud’ at the top -15. Go to ‘Dashboard’ in order to view your properties as widgets that you can control - - -PART 2: IDE WITH TELEGRAM BOT - -Step 1: Install Arduino IDE. -Step 2: Connect your Arduino Board to the computer and install the drivers 'Arduino AVR Boards' and 'Arduino SAMD Boards'. -Step 3: Install all libraries needed. -Step 4: Install Telegram. -Step 5: Now we will try to set the Telegram bot, after you sign up for an account, go to the search bar and type @BotFather. -Step 6: Start a chat with BotFather by typing /start, after the /start command you will see the help list. - - -Step 7: Type /newbot, then type the name of your bot. BotFather will then ask you for a username. Your bot’s username must end in ‘bot’. If both the name and username are valid, you will receive a long string of chars called TOKEN. This is your personal ‘key’ used to communicate with Telegram servers (will be used in the Arduino code). - - . - - -Step 8: Before we begin, you can access the full code here, note that I won’t be posting full lines of code in this tutorial, I will only be mentioning the important parts of the code that come with each connection we do. Now let’s start with the first connection which is the LED, this is how the circuit is connected (use the 470 ohm resistor): - - -Also, just a quick note, on this part of the code: - -you will have to add your WiFi’s network and password. And on this part of the code: - -you will have to add your BOT Token given to you by the BotFather. - -Now, back to the LED, before the setup function, we added: - -and inside the setup function, we added: - -which sets the LED pin as output. - - - - -Now, inside the loop function, this is the bit of code we added: - - -We added an if-statement, this line of code: if (bot.messages[i].text == "/ON") means if YOU, the user, texted your bot the command /ON (to turn the LED on), then we will be adding 255 to the value of pulse we already initialised, therefore, pulse = 0 + 255 = 255. And this line of code: bot.sendMessage(bot.messages[i].chat_id,"LED is ON!", ""); will program your bot to inform you that the LED is on. As for this line of: Serial.println(pulse); this will print the value of the pulse returned into the serial monitor. The second condition is when you text your bot the command /Increase (to increase the LED’s brightness), if the pulse of the LED smaller than or equal to 255, then we increment by 30, else the pulse will equal 255. - - -We are still not done, inside the loop function we have more lines of code: - - - -If you texted the bot the command /Decrease (to decrease the LED’s brightness), and the pulse is larger than or equal to 30, then we will decrement by 30. Else, the pulse will be 0. And if you texted the bot the command /OFF, the pulse will be equal to 0 and the LED will be turned off. Finally, at the end of the loop function, outside the if-statement, we added this line of code: -which writes an analog value (PWM wave) to the LEDPIN which is pin 2. - - -Step 9: Now let’s jump into the LDR connection (here we used the 1k ohm resistor): - - -Before the setup function, we added only two lines of code: - -and: - -which is just a declaration. In the setup function we have not added any new line of code. However, in the loop function we did. Starting with this line of code: - -the analogRead() function reads the analog pin value from the specified analog pin which in this case is A0. - - -The rest of the code still inside the loop function is: - - -If you text your bot the command /LDR, there are four statements to follow, if the LDR value is less than or equal to 200 then your bot will inform you that it is DARK (if you place your hand on the LDR, so it won’t be exposed to any source of light) and it will attach the analog value which what the String(LDRvalue) returns. as for the three statements, these lines of code are pretty straightforward and self-explanatory, because they follow the same logic as the first statement. If you expose your LDR to your phone’s flashlight, and then sent your bot the command /LDR, here the LDRvalue will most likely be larger than 800, and hence your telegram bot will inform you that it is FULL DAY LIGHT along with the analog value of your sensor. - - -Step 10: Now for the Servo Motor connection: - -Viewing the code here, notice that we have installed the servo library, hence the #include , now before the setup function, we add these two lines of code: #define servoPin 13 and Servo myservo; (creates servo object to control the servo). Inside the setup function, we added: - - -the first line attached the servo on pin 13 to the servo object, and the second line sets the servo position at 0. Now, here are the lines of code we added inside the loop function: - - - -The code is pretty simple. If you texted your bot the command /ONservo, this will set the servo position at 90 degrees, if you texted you bot the command /OFFservo, this will set the servo position at 0 degrees, and if you texted your bot the command /TRYservo, your servo will change its position between 0 and 90 degrees twice. - - - -Step 11: Finally, for the Temperature/Humidity sensor connection: - - -For the Temperature/Humidity sensor, take a look at the code here, notice that we added three new libraries: - - -Now, before the setup function, these are the lines of code we added: - -the DHTTYPE is just the type of sensor we are using, and: - - -In the setup function we have not added any new code. - - - -As for the loop function, we added these lines of code: - -this will read the value of the temperature and humidity from the sensor. And: - - -the code is pretty simple, if you texted your bot the command /TEMP, your bot should return to you the temperature value, and if you texted your bot the command /HUMID, your bot should return to you the humidity value. - - - - - - - - -References and Tutorials: - -1. https://github.com/The-Assembly/Arduino-IOT - - - - - - - diff --git a/ServoMotorConnection.jpg b/ServoMotorConnection.jpg deleted file mode 100644 index 1f04ed8..0000000 Binary files a/ServoMotorConnection.jpg and /dev/null differ