Benny Estes
Published © LGPL

Remote & Base Sensor Station - Now with IoT!

This is a project I put together that is basically two sensor stations: a base and a remote station.

BeginnerShowcase (no instructions)3 hours6,051
Remote & Base Sensor Station - Now with IoT!

Things used in this project

Story

Read more

Code

Code snippet #1

Arduino
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <CayenneESP8266Shield.h>
#include <DHT.h>
#include <SimpleTimer.h>

#define DHTPIN 7
#define DHTTYPE DHT22

DHT dht(DHTPIN, DHTTYPE);

SimpleTimer timer;

float dataInfo[6];
float far;

RF24 radio(9, 10);
const uint64_t pipe[2] = {0xE8E8F0F0E1LL, 0xE8E8F0F0E1LL};

float hum1;
float temp1;


char token[] = "your token";
char ssid[] = "your wifi";
char password[] = "password";

#define EspSerial Serial3
ESP8266 wifi(EspSerial);

void setup() {
	Serial.begin(9600);
	delay(10);

	EspSerial.begin(9600);
	delay(10);

	Cayenne.begin(token, wifi, ssid, password);


	radio.begin();
	radio.setDataRate(RF24_250KBPS);
	radio.openReadingPipe(1, pipe[1]);
	radio.openReadingPipe(2, pipe[2]);
	radio.startListening();


	dht.begin();

	timer.setInterval(15000, getTemp);

}




void loop()
{
	Cayenne.run();
	timer.run();

	if ( radio.available() )
		{
			Cayenne.virtualWrite(V0, 1);
			digitalWrite(12, HIGH);
			getData();
		}
}


void getData()
{
	radio.read(&dataInfo, sizeof(dataInfo));
	delay(200);

	digitalWrite(12, LOW);
	Cayenne.virtualWrite(V0, 0);

	far = ((dataInfo[0] * 1.8) + 32);

	Cayenne.virtualWrite(V1, dataInfo[0]);
	Cayenne.virtualWrite(V6, far);
	Cayenne.virtualWrite(V2, dataInfo[1]);
	Cayenne.virtualWrite(V3, dataInfo[2]);
	Cayenne.virtualWrite(V4, dataInfo[3]);
	Cayenne.virtualWrite(V5, dataInfo[4]);
	Cayenne.virtualWrite(V11, dataInfo[4]);
	Cayenne.virtualWrite(V10, dataInfo[2]);
	Cayenne.virtualWrite(V12, far);
}


void getTemp()
{
	temp1 = dht.readTemperature(true);
	delay(100);
	hum1 = dht.readHumidity();
}



CAYENNE_OUT(V13)
{
	Cayenne.virtualWrite(V13, temp1);
	Cayenne.virtualWrite(V15, temp1);
}

CAYENNE_OUT(V14)
{

	Cayenne.virtualWrite(V14, hum1);
	Cayenne.virtualWrite(V16, hum1);
}

Code snippet #2

Arduino
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <SimpleTimer.h>
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BMP280.h>
#include <DHT.h>

#define DHTPIN 2
#define DHTTYPE DHT22

SimpleTimer timer;
Adafruit_BMP280 bmp;
DHT dht(DHTPIN, DHTTYPE);

RF24 radio(9, 10);
const uint64_t pipe = 0xE8E8F0F0E1LL;

float pressurePa;
float pressureIn;
float temperature; 
int altimeter;
float volts;
float dataInfo[6];
int motion;
int hum;


void setup() {
  Serial.begin(9600);

  bmp.begin();
  dht.begin();
  
  radio.begin();
  radio.setDataRate(RF24_250KBPS);
  radio.openWritingPipe(pipe);
  
  timer.setInterval(300000, getReadings);
}


void loop()
{
   timer.run();

}

void getReadings()
{
//   radio.powerUp();

   pressurePa = bmp.readPressure();
   temperature = bmp.readTemperature();
   altimeter = bmp.readAltitude (1050.35);
   delay(250);
   pressureIn = pressurePa * 0.000295;

   hum = dht.readHumidity();
   delay(250);
   volts = ((analogRead(A2) * (5.0 / 1023.0)) / 0.08933);

  dataInfo[0] = temperature;
  dataInfo[1] = hum;
  dataInfo[2] = pressureIn;
  dataInfo[3] = altimeter;
  dataInfo[4] = volts;
  dataInfo[5] = motion;
  
  radio.write(dataInfo, sizeof(dataInfo));
//  Serial.println(temperature);
//  Serial.println(hum);
//  radio.powerDown();
}

Credits

vapor83

Posted by Benny Estes

Comments