Notes![what is notes.io? What is notes.io?](/theme/images/whatisnotesio.png)
![]() ![]() Notes - notes.io |
int SensorPin =2;
int OutputPin=13;
void setup(){
pinMode(OutputPin, OUTPUT); pinMode(SensorPin, INPUT); Serial.begin(9600)
}
void loop(){
int SensorValue=digitalRead(SensorPin); Serial.print("SensorPin value:"); Serial.println(SensorValue);
delay(1000);
if (SensorValue==LOW)
{
digitalWrite(OutputPin, HIGH);
}
else
{
digitalWrite(OutputPin,LOW);
}
}
------------------------------------------------------------------------------------------------------------
Set 2
#define echoPin 2
#define trigPin 3
long duration;
int distance;
void setup() {
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
Serial.begin(9600);
Serial.println("Distance measurement using Arduino Uno.");
delay(500);
}
void loop() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = duration * 0.0344 / 2;
Serial.print("Distance: ");
Serial.print(distance);
Serial.println(" cm");
delay(100);
}
-----------------------------------------------------------------------------------------------------------
Set 3
const int irPin=10;
void setup() {
// put your setup code here, to run once:
pinMode(irPin,INPUT);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
int val;
val=digitalRead(irPin);
Serial.println(val);
if(val==0)
Serial.println("Obstacle is detected ");
else
Serial.println("no obstacle");
delay(1000);
}
OUTPUT:
0 Obstacle detected
1 no obstacle
-----------------------------------------------------------------------------------------------------------
Set 4
#include <SPI.h>
#include <MFRC522.h>
#define SS_PIN 10
#define RST_PIN A5
MFRC522 rfid(SS_PIN, RST_PIN); // Instance of the class
MFRC522::MIFARE_Key key;
// Init array that will store new NUID
byte nuidPICC[4];
void setup() {
Serial.begin(9600);
SPI.begin(); // Init SPI bus
rfid.PCD_Init(); // Init MFRC522
for (byte i = 0; i < 6; i++) {
key.keyByte[i] = 0xFF;
}
}
void loop() {
// Look for new cards
if ( ! rfid.PICC_IsNewCardPresent())
return;
// Verify if the NUID has been readed
if ( ! rfid.PICC_ReadCardSerial())
return;
for (byte i = 0; i < 4; i++) {
nuidPICC[i] = rfid.uid.uidByte[i];
}
printHex(rfid.uid.uidByte, rfid.uid.size);
Serial.println();
rfid.PICC_HaltA();
rfid.PCD_StopCrypto1();
}
void printHex(byte *buffer, byte bufferSize) {
for (byte i = 0; i < bufferSize; i++) {
Serial.print(buffer[i] < 0x10 ? " 0" : "");
Serial.print(buffer[i], HEX);
}
}
Output:
6D 41 2F 31
AC 9C 01 32
-----------------------------------------------------------------------------------------------------------
Set 5
#include "DHT.h"
#define DHTPIN 2
#define DHTTYPE DHT11 // DHT 11
//#define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321
//#define DHTTYPE DHT21 // DHT 21 (AM2301)
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(9600);
Serial.println(F("DHTxx test!"));
dht.begin();
}
void loop() {
// Wait a few seconds between measurements.
delay(2000);
// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
float h = dht.readHumidity();
// Read temperature as Celsius (the default)
float t = dht.readTemperature();
// Read temperature as Fahrenheit (isFahrenheit = true)
float f = dht.readTemperature(true);
// Check if any reads failed and exit early (to try again).
if (isnan(h) || isnan(t) || isnan(f)) {
Serial.println(F("Failed to read from DHT sensor!"));
return;
}
// Compute heat index in Fahrenheit (the default)
float hif = dht.computeHeatIndex(f, h);
// Compute heat index in Celsius (isFahreheit = false)
float hic = dht.computeHeatIndex(t, h, false);
Serial.print(F("Humidity: "));
Serial.print(h);
Serial.print(F("% Temperature: "));
Serial.print(t);
Serial.print(F("°C "));
Serial.print(f);
Serial.print(F("°F Heat index: "));
Serial.print(hic);
Serial.print(F("°C "));
Serial.print(hif);
Serial.println(F("°F"));
}
-----------------------------------------------------------------------------------------------------------
Set 6
#include <ESP8266WiFi.h>
#include "secrets.h"
#include "ThingSpeak.h" // always include thingspeak header file after other header files and custom macros
char ssid[] = SECRET_SSID; // your network SSID (name)
char pass[] = SECRET_PASS; // your network password
int keyIndex = 0; // your network key Index number (needed only for WEP)
WiFiClient client;
unsigned long myChannelNumber = SECRET_CH_ID;
const char * myWriteAPIKey = SECRET_WRITE_APIKEY;
int number = 0;
const int irPin=D5;
void setup() {
Serial.begin(115200); // Initialize serial
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo native USB port only
}
WiFi.mode(WIFI_STA);
ThingSpeak.begin(client); // Initialize ThingSpeak
}
void loop() {
// Connect or reconnect to WiFi
if(WiFi.status() != WL_CONNECTED){
Serial.print("Attempting to connect to SSID: ");
Serial.println(SECRET_SSID);
while(WiFi.status() != WL_CONNECTED){
WiFi.begin(ssid, pass); // Connect to WPA/WPA2 network. Change this line if using open or WEP network
Serial.print(".");
delay(5000);
}
Serial.println("nConnected.");
}
// Write to ThingSpeak. There are up to 8 fields in a channel, allowing you to store up to 8 different
// pieces of information in a channel. Here, we write to field 1.
int x = ThingSpeak.writeField(myChannelNumber, 1, number, myWriteAPIKey);
if(x == 200){
Serial.println("Channel update successful.");
}
else{
Serial.println("Problem updating channel. HTTP error code " + String(x));
}
number++;
if(number > 99){
number = 0;
}
delay(20000); // Wait 20 seconds to update the channel again
}
// Use this file to store all of the private credentials
// and connection details
#define SECRET_SSID "Redmi Note 11 Pro+ 5G" // replace MySSID with your WiFi network name
#define SECRET_PASS "mani@123" // replace MyPassword with your WiFi password
#define SECRET_CH_ID 2038959 // replace 0000000 with your channel number
#define SECRET_WRITE_APIKEY "7W61L6N4VY7ZFBZP" // replace XYZ with your channel write API Key
-----------------------------------------------------------------------------------------------------------
Set 7
#include <ESP8266WiFi.h>
#include "secrets.h"
#include "ThingSpeak.h"
#include "DHT.h"
#define DHTTYPE DHT11
#define DHTPIN D3
// always include thingspeak header file after other header files and custom macros
char ssid[] = SECRET_SSID; // your network SSID (name)
char pass[] = SECRET_PASS; // your network password
int keyIndex = 0;
DHT dht(DHTPIN, DHTTYPE);// your network key Index number (needed only for WEP)
WiFiClient client;
unsigned long myChannelNumber = SECRET_CH_ID;
const char * myWriteAPIKey = SECRET_WRITE_APIKEY;
// Initialize our values
int number1 = 0;
int number2 = random(0,100);
int number3 = random(0,100);
int number4 = random(0,100);
String myStatus = "";
void setup() {
dht.begin();
Serial.begin(115200); // Initialize serial
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo native USB port only
}
WiFi.mode(WIFI_STA);
ThingSpeak.begin(client); // Initialize ThingSpeak
}
void loop() {
// Connect or reconnect to WiFi
if(WiFi.status() != WL_CONNECTED){
Serial.print("Attempting to connect to SSID: ");
Serial.println(SECRET_SSID);
while(WiFi.status() != WL_CONNECTED){
WiFi.begin(ssid, pass); // Connect to WPA/WPA2 network. Change this line if using open or WEP network
Serial.print(".");
delay(5000);
}
Serial.println("nConnected.");
}
// set the fields with the values
ThingSpeak.setField(1, number1);
ThingSpeak.setField(2, number2);
ThingSpeak.setField(3, number3);
ThingSpeak.setField(4, number4);
// figure out the status message
if(number1 > number2){
myStatus = String("field1 is greater than field2");
}
else if(number1 < number2){
myStatus = String("field1 is less than field2");
}
else{
myStatus = String("field1 equals field2");
}
// set the status
ThingSpeak.setStatus(myStatus);
// write to the ThingSpeak channel
int x = ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);
if(x == 200){
Serial.println("Channel update successful.");
}
else{
Serial.println("Problem updating channel. HTTP error code " + String(x));
}
// change the values
number1++;
if(number1 > 99){
number1 = 0;
}
number2 = random(0,100);
number3 = random(0,100);
number4 = random(0,100);
delay(20000); // Wait 20 seconds to update the channel again
}
Secret.h
// Use this file to store all of the private credentials
// and connection details
#define SECRET_SSID "samsung on7 pro" // replace MySSID with your WiFi network name
#define SECRET_PASS "Venkata123#" // replace MyPassword with your WiFi password
#define SECRET_CH_ID 2040479 // replace 0000000 with your channel number
#define SECRET_WRITE_APIKEY "0RNY24517GJ9LRWD" // replace XYZ with your channel write API Key
-----------------------------------------------------------------------------------------------------------
Set 8
#include "ThingSpeak.h"
#include <ESP8266WiFi.h>
const char ssid[] = "Redmi Note 11 Pro+ 5G"; // your network SSID (name)
const char pass[] = "mani@123"; // your network password
int statusCode = 0;
WiFiClient client;
//---------Channel Details---------//
unsigned long counterChannelNumber = 2062499; // Channel ID
const char * myCounterReadAPIKey = "W5564YQ3MJPU0S7V"; // Read API Key
const int FieldNumber1 = 1; // The field you wish to read
const int FieldNumber2 = 2; // The field you wish to read
//-------------------------------//
void setup()
{
Serial.begin(115200);
WiFi.mode(WIFI_STA);
ThingSpeak.begin(client);
}
void loop()
{
//----------------- Network -----------------//
if (WiFi.status() != WL_CONNECTED)
{
Serial.print("Connecting to ");
Serial.print(ssid);
Serial.println(" ....");
while (WiFi.status() != WL_CONNECTED)
{
WiFi.begin(ssid, pass);
delay(5000);
}
Serial.println("Connected to Wi-Fi Succesfully.");
}
//--------- End of Network connection--------//
//---------------- Channel 1 ----------------//
long temp = ThingSpeak.readLongField(counterChannelNumber, FieldNumber1, myCounterReadAPIKey);
statusCode = ThingSpeak.getLastReadStatus();
if (statusCode == 200)
{
Serial.print("Temperature: ");
Serial.println(temp);
}
else
{
Serial.println("Unable to read channel / No internet connection");
}
delay(100);
//-------------- End of Channel 1 -------------//
//---------------- Channel 2 ----------------//
long humidity = ThingSpeak.readLongField(counterChannelNumber, FieldNumber2, myCounterReadAPIKey);
statusCode = ThingSpeak.getLastReadStatus();
if (statusCode == 200)
{
Serial.print("Humidity: ");
Serial.println(humidity);
}
else
{
Serial.println("Unable to read channel / No internet connection");
}
delay(100);
//-------------- End of Channel 2 -------------//
}
Output:
Connected to wifi Successfully
Humidity :63
Temperature : 9
-----------------------------------------------------------------------------------------------------------
Set 9
Pin connection :
DHT11 sensor
GND-GND
DATA PIN-D4
VCC-Vin
Source code:
#include "ESP8266WiFi.h"
#include "DHT.h"
#define DHTTYPE DHT11
const char* ssid = "Redmi Note 11 Pro+ 5G";
const char* password = "mani@123";
WiFiServer wifiServer(9000);
DHT dht(D4, DHT11);
void setup() {
Serial.begin(115200);
delay(1000);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting..");
}
Serial.print("Connected to WiFi. IP:");
Serial.println(WiFi.localIP());
wifiServer.begin();
dht.begin();
}
void loop() {
WiFiClient client = wifiServer.available();
if (client) {
while (client.connected()) {
while (client.available()>0) {
int h = dht.readHumidity();
client.print("humidity :");
client.println(h);
//Serial.println(sensor_value);
delay(2000);
}
}
client.stop();
Serial.println("Client disconnected");
}
}
Output:
Connected to wifi IP: 192.168.102.45
TCP Client Terminal
Port :9000
Humidity:49
Humidity:55
Humidity:56
Humidity : 58
-----------------------------------------------------------------------------------------------------------
Set 10
GND-GND
DATA- D5
VCC-VIN
#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
#include "DHT.h"
#define DHTTYPE DHT11
// Set WiFi credentials
#define WIFI_SSID "333-3"
#define WIFI_PASS "123456789"
#define UDP_PORT 4210
DHT dht(D5, DHT11);
// UDP
WiFiUDP UDP;
char packet[255];
char reply[] = "Packet received!";
void setup() {
// Setup serial port
Serial.begin(115200);
Serial.println();
Serial.println(F("DHTxx test!"));
dht.begin();
// Begin WiFi
WiFi.begin(WIFI_SSID, WIFI_PASS);
// Connecting to WiFi...
Serial.print("Connecting to ");
Serial.print(WIFI_SSID);
// Loop continuously while WiFi is not connected
while (WiFi.status() != WL_CONNECTED)
{
delay(2000);
Serial.print(".");
}
// Connected to WiFi
Serial.println();
Serial.print("Connected! IP address: ");
Serial.println(WiFi.localIP());
// Begin listening to UDP port
UDP.begin(UDP_PORT);
Serial.print("Listening on UDP port ");
Serial.println(UDP_PORT);
}
void loop() {
int h = dht.readHumidity();
//float h = dht.readHumidity();
delay(2000);
// Send return packet
UDP.beginPacket(UDP.remoteIP(), UDP.remotePort());
UDP.write(reply);
// client.print("humidity :");
// client.println(h);
UDP.println(h);
UDP.endPacket();
Serial.println(F("Humidity:n "));
Serial.println(h);
}
Output:
Connected IP Address :192.168.137.191
Listening on UDP port : 4210
Humidity : 32
Receive at 192.168.137.69 : 4210
[192.168.137.69 : 4210]:31
33
Packet received.
![]() |
Notes is a web-based application for online taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000+ notes created and continuing...
With notes.io;
- * You can take a note from anywhere and any device with internet connection.
- * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
- * You can quickly share your contents without website, blog and e-mail.
- * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
- * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.
Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.
Easy: Notes.io doesn’t require installation. Just write and share note!
Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )
Free: Notes.io works for 14 years and has been free since the day it was started.
You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;
Email: [email protected]
Twitter: http://twitter.com/notesio
Instagram: http://instagram.com/notes.io
Facebook: http://facebook.com/notesio
Regards;
Notes.io Team