Skip to content

Instantly share code, notes, and snippets.

const int trigPin = 2; //D4
const int echoPin = 0; //D3
long duration;\\defining variable duration to hold the duration of the reflected wave
int distance;\\defining variable distance to hold the distance of the object from the sensor
void setup() {
pinMode(2, OUTPUT); // Sets the trigPin as an Output
pinMode(0, INPUT); // Sets the echoPin as an Input
Serial.begin(9600); // Starts the serial communication with baud rate 9600
int shockPin = 10; // Use Pin 10 as our Input
int shockVal = HIGH; // This is where we record our shock measurement
boolean bAlarm = false;
unsigned long lastShockTime; // Record the time that we measured a shock
int shockAlarmTime = 250; // Number of milli seconds to keep the shock alarm high
void setup ()
#include "DHT.h"
#define dht_apin A0 // Analog Pin sensor is connected to
dht DHT;
void setup(){
Serial.begin(9600);
delay(500);//Delay to let system boot
Serial.println("DHT11 Humidity & temperature Sensor\n\n");
int led = 13;//LED pin
int sensor = 3; //sensor pin
int val; //numeric variable
void setup()
{
pinMode(led, OUTPUT); //set LED pin as output
pinMode(sensor, INPUT); //set sensor pin as input
}
int Buzzer = 13; // Use buzzer for alert
int FlamePin = 2; // This is for input pin
int Flame = HIGH; // HIGH when FLAME Exposed
void setup() {
pinMode(Buzzer, OUTPUT);
pinMode(FlamePin, INPUT);
Serial.begin(9600);
}
int sensorPin = A0; // Pulse Sensor connected to ANALOG PIN 0
int led = 13; // The on-board Arduino LED
int Signal; // holds the incoming raw data. Signal value can range from 0-1023
int Threshold = 550; // Determine which Signal to “count as a beat”, and which to ingore.
// The SetUp Function:
void setup() {
pinMode(sensorPin,INPUT);
pinMode(led,OUTPUT); // pin that will blink to your heartbeat!
Serial.begin(9600); // Set’s up Serial Communication at certain speed.
}
#include <ArduinoJson.h>
void setup() {
// Initialize Serial port
Serial.begin(9600);
while (!Serial) continue;
// Memory pool for JSON object tree.
//
// Inside the brackets, 200 is the size of the pool in bytes.
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
void setup () {
Serial.begin(115200); //Begin Serial Communication with NodeMCU
const char* ssid = "Your router name";
const char* password = "Your router password";
WiFi.begin(ssid, password); //Connect to WiFi
#include <ESP8266WiFi.h>
#include <PubSubClient.h>
const char* ssid = "YourNetworkName";
const char* password = "YourNetworkPassword";
const char* mqttServer = "m11.cloudmqtt.com";
const int mqttPort = 12948; //your port number
const char* mqttUser = "YourMqttUser";
const char* mqttPassword = "YourMqttUserPassword";