Snowbuddy




Snowman replica that can chat with user to inform them whether outside temperature is safe for outdoor activity or not.

Things used in this project

Hardware components

Arduino MKR1000
Arduino MKR1000
× 1
DHT22 Temperature Sensor
DHT22 Temperature Sensor
× 1
Jumper wires (generic)
Jumper wires (generic)
× 1

Software apps and online services

Arduino Web Editor
Arduino Web Editor
Telegram

Story

Schematics

Hardware Connection

Connect DHT22 temperature sensor to Arduino MKR1000/Genuino MKR1000

Code

Arduino code

Arduino code to interface the Arduino MKR1000 / Genuino MKR1000 with DHT22 temperature sensor and Telegram Bot
Snowbuddyino
 
/*
  This example shows how to program a Telegram Bot
  that provide the surrounding temperature to the user
  The temperature reading is obtained using DHT22. 
  
  Compatible boards:
  Arduino/Genuino mkr1000
  Arduino/Genuino Zero + WiFi shield
*/

#include 
#include 
#include 
#include "DHT.h"

// Initialize sensor input pin & DHT sensor type
#define DHTPIN 2     // what digital pin we're connected to
#define DHTTYPE DHT22   // DHT 22  (AM2302), AM2321
DHT dht(DHTPIN, DHTTYPE);

// initialize variables
float temp;
float hum;
float heat_index;

// Initialize Wifi connection to the router
char ssid[] = "****";             // your network SSID (name)
char pass[] = "****";           // your network key

// Initialize Telegram BOT

const char* BotToken = "306990732:AAH9yHYaBch0wUqPp5uJVDz2UHrZ0TaK7As";
const char* BotName = "Jad's MKR1000";     // your Bot Name 
const char* BotUsername = "Jad_MKR1000_bot"; // your Bot User Name 


WiFiSSLClient client;
TelegramBot bot (BotToken,client);

void get_reading(void);  //function to get the temperature reading


void setup() {

  Serial.begin(115200);
  while (!Serial) {}
  delay(3000);


  // attempt to connect to Wifi network:
  Serial.print("Connecting Wifi: ");
  Serial.println(ssid);
  while (WiFi.begin(ssid, pass) != WL_CONNECTED) {
    Serial.print(".");
    delay(500);
  }
  Serial.println("");
  Serial.println("WiFi connected");

  bot.begin();
  dht.begin();

}

void loop() {

  message m = bot.getUpdates(); // Read new messages

  if ( m.text.equals("Hi!")) {
    get_reading();
    Serial.println("message received");
    Serial.println(temp);
    if (temp<-0) {
    bot.sendMessage(m.chat_id, "The temperature is too cold. Stay indoor!");
  } else {
      bot.sendMessage(m.chat_id, "Enjoy!");
  }
}
}
void get_reading() {
// Wait a few seconds between measurements.
  delay(2000);
  
  //Read temperature
  temp = dht.readTemperature(true);

  // Check if any reads failed and exit early (to try again).
  if isnan(temp) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }

}
Source : Snowbuddy




Leave a Comment

*
= 3 + 4

(Spamcheck Enabled)

Read previous post:
Simple circuit indicates a low battery
Simple circuit indicates a low battery

The Design Idea in Figure 1 indicates a low-battery condition in an audio test instrument that is powered by four...

Close
Scroll to top