https://www.instructables.com/How-to-Make-an-Arduino-Weather-Station-With-DHT11-/
https://hackaday.io/project/191652-long-range-weather-station-65
https://randomnerdtutorials.com/esp32-dht11-dht22-temperature-humidity-sensor-arduino-ide/
https://randomnerdtutorials.com/dht11-vs-dht22-vs-lm35-vs-ds18b20-vs-bme280-vs-bmp180/
Thingspeak
https://thingspeak.com/channels/227870
Tachometer Code for Wind Speed indicator
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#define SENSOR_PIN 2 // Interrupt pin
#define SLOTS_PER_REV 24 // Number of slots (or interruptions) per revolution
volatile unsigned long pulseCount = 0;
unsigned long lastMillis = 0;
float rpm = 0;
// Set the LCD address to 0x27 or 0x3F depending on your module
LiquidCrystal_I2C lcd(0x27, 16, 2);
void setup() {
pinMode(SENSOR_PIN, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(SENSOR_PIN), countPulse, FALLING);
lcd.begin();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("Measuring RPM...");
}
void loop() {
unsigned long currentMillis = millis();
if (currentMillis - lastMillis >= 1000) { // Update every 1 second
noInterrupts(); // Temporarily disable interrupts while reading pulseCount
unsigned long count = pulseCount;
pulseCount = 0;
interrupts(); // Re-enable interrupts
// Calculate RPM: (counts / slots) * (60 seconds / 1 minute)
rpm = ((float)count / SLOTS_PER_REV) * 60.0;
//display rpm on LCD screen
lcd.setCursor(0, 1);
lcd.print("Speed: ");
lcd.print(rpm);
lcd.print(" RPM "); // Extra spaces to overwrite old chars
lastMillis = currentMillis;
}
}
void countPulse() {
pulseCount++;
}
/*Notes
SLOTS_PER_REV: Set this based on how many interruptions happen per full rotation of your disk.
I2C address (0x27) may vary. If nothing appears on your screen, try 0x3F or scan with an I2C scanner script.
*/
Thingspeak Sample Code
***************************************************************************
This is a library for the BME280 humidity, temperature & pressure sensor
Designed specifically to work with the Adafruit BME280 Breakout
----> http://www.adafruit.com/products/2650
These sensors use I2C or SPI to communicate, 2 or 4 pins are required
to interface. The device's I2C address is either 0x76 or 0x77.
Adafruit invests time and resources providing this open source code,
please support Adafruit andopen-source hardware by purchasing products
from Adafruit!
Written by Limor Fried & Kevin Townsend for Adafruit Industries.
BSD license, all text above must be included in any redistribution
See the LICENSE file for details.
***************************************************************************/
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <WiFi.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;
float temperature;
float pressure;
float humidity;
int light;
//
unsigned long myChannelNumber = SECRET_CH_ID;
const char* myWriteAPIKey = SECRET_WRITE_APIKEY;
#define BME_SCK 13
#define BME_MISO 12
#define BME_MOSI 11
#define BME_CS 10
#define SEALEVELPRESSURE_HPA (1013.25)
Adafruit_BME280 bme; // I2C
//Adafruit_BME280 bme(BME_CS); // hardware SPI
//Adafruit_BME280 bme(BME_CS, BME_MOSI, BME_MISO, BME_SCK); // software SPI
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 32 // OLED display height, in pixels
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
// The pins for I2C are defined by the Wire-library.
// On an arduino UNO: A4(SDA), A5(SCL)
// On an arduino MEGA 2560: 20(SDA), 21(SCL)
// On an arduino LEONARDO: 2(SDA), 3(SCL), ...
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
unsigned long delayTime;
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
Serial.begin(9600);
while (!Serial)
; // time to get serial running
Serial.println(F("BME280 test"));
unsigned status;
// default settings
status = bme.begin(0x76); //status = bme.begin();
// You can also pass in a Wire library object like &Wire2
// status = bme.begin(0x76, &Wire2)
if (!status) {
Serial.println("Could not find a valid BME280 sensor, check wiring, address, sensor ID!");
Serial.print("SensorID was: 0x");
Serial.println(bme.sensorID(), 16);
Serial.print(" ID of 0xFF probably means a bad address, a BMP 180 or BMP 085\n");
Serial.print(" ID of 0x56-0x58 represents a BMP 280,\n");
Serial.print(" ID of 0x60 represents a BME 280.\n");
Serial.print(" ID of 0x61 represents a BME 680.\n");
while (1) delay(10);
}
Serial.println("-- Default Test --");
delayTime = 1000;
Serial.println();
Serial.begin(9600);
// SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
if (!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
Serial.println(F("SSD1306 allocation failed"));
for (;;)
; // Don't proceed, loop forever
}
// Show initial display buffer contents on the screen --
// the library initializes this with an Adafruit splash screen.
display.display();
delay(2000); // Pause for 2 seconds
display.clearDisplay();// Clear the buffer
}
void loop() {
printValues();
delay(1000);
lcdscreen();
temperature = bme.readTemperature();
pressure = bme.readPressure()/100;
humidity = bme.readHumidity();
light = analogRead(A0);
ThingSpeak.setField(1, temperature);
ThingSpeak.setField(2, pressure);
ThingSpeak.setField(3, humidity);
ThingSpeak.setField(4, light);
// 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));
}
// 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
}
void lcdscreen() {
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(0, 10);
display.print("P= ");
display.print(bme.readPressure() / 100.0F);
display.display();
delay(2000);
display.clearDisplay();
display.setCursor(0, 10);
display.print("T= ");
display.print(bme.readTemperature());
display.print(" C");
display.display();
delay(2000);
display.clearDisplay();
display.setCursor(0, 10);
display.print("H= ");
display.print(bme.readHumidity());
display.display();
delay(2000);
display.clearDisplay();
}
void printValues() {
Serial.print("Temperature = ");
Serial.print(bme.readTemperature());
Serial.println(" *C");
Serial.print("Pressure = ");
Serial.print(bme.readPressure() / 100.0F);
Serial.println(" hPa");
Serial.print("Approx. Altitude = ");
Serial.print(bme.readAltitude(SEALEVELPRESSURE_HPA));
Serial.println(" m");
Serial.print("Humidity = ");
Serial.print(bme.readHumidity());
Serial.println(" %");
Serial.println();
display.clearDisplay();
delay(2000);
}
secrets.h tab:
// Use this file to store all of the private credentials
// and connection details
#define SECRET_SSID "AceraStudent" // replace MySSID with your WiFi network name
#define SECRET_PASS "daisyJet91" // replace MyPassword with your WiFi password
#define SECRET_CH_ID 2286715 // replace 0000000 with your channel number
#define SECRET_WRITE_APIKEY "5P6THTN21SUI7XXG" // replace with your channel write API Key
Wiring: Vcc------3.3V ,GND----GND, SDA----SDA(A4) SCL--- SCL (A5)
Libraries: Adafruit_Sensor.h
Adafruit_BME280.h
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
Adafruit_BME280 bme; // I2C
void setup() {
Serial.begin(9600);
if (!bme.begin(0x76)) { // Try 0x76 or 0x77 depending on your sensor
Serial.println("Could not find a valid BME280 sensor, check wiring!");
while (1);
}
}
void loop() {
Serial.print("Temperature = ");
Serial.print(bme.readTemperature());
Serial.println(" °C");
Serial.print("Pressure = ");
Serial.print(bme.readPressure() / 100.0F);
Serial.println(" hPa");
Serial.print("Humidity = ");
Serial.print(bme.readHumidity());
Serial.println(" %");
Serial.println();
delay(2000);
}