This is my first project and I’ve been reading for 2 days before replying. I’m a beginner at programming & appreciate the patients. However I am unable to see/understand how to get the Photon to do multiple things. I’m trying to open/close/(Status) of the garage door while also integrating a DHT11 sensor reporting in Farenheit. Any assistance & expertise would be greatly appreciated & hope a chuckle is had at my nievetie…
Found this link/code as well for the Temp Sensors (no Blynk)
//GARAGE DOOR
#include "blynk/blynk.h"
#include "blynk/BlynkSimpleParticle.h"
#include "SparkCorePolledTimer/SparkCorePolledTimer.h"
#include "Adafruit_DHT/Adafruit_DHT.h"
#define DHTPIN 2 // what pin we're connected to
#define DHTTYPE DHT11 // DHT 22 (AM2302)
#define BLYNK_PRINT Serial
char auth[] = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
const int reedSwitch = D2;
const int relaySwitch1 = D0;
const int relaySwitch2 = D3;
int reedStatus = 0;
int ledStatus = 0;
void setup()
{
Serial.begin(9600);
Blynk.begin(auth);
pinMode(relaySwitch1, OUTPUT);
pinMode(relaySwitch2, OUTPUT);
pinMode(reedSwitch, INPUT);
pinMode(D3, OUTPUT);
}
//add button in Blynk app corresponding to V0
BLYNK_WRITE (0){ //close garage
if (reedStatus == HIGH) {
digitalWrite(relaySwitch1, HIGH);
delay(1000);
digitalWrite(relaySwitch1, LOW);
}
}
//add button in Blynk app corresponding to V1
BLYNK_WRITE (1){ //open garage
if (reedStatus == LOW) {
digitalWrite(relaySwitch1, HIGH);
delay(1000);
digitalWrite(relaySwitch1, LOW);
}
}
//add LED in Blynk app corresponding to V3
BLYNK_READ(3) //report garage status
{
Blynk.virtualWrite(3, ledStatus);
}
void loop()
{
Blynk.run();
//constantly monitor the reed switch status (garage open or closed)
reedStatus = digitalRead(reedSwitch);
if (reedStatus == HIGH) {
ledStatus = 1023;
}
else {
ledStatus = 0;
}
}
//#include "blynk/blynk.h"
//#include "blynk/BlynkSimpleSparkCore.h"
//#include "SparkCorePolledTimer/SparkCorePolledTimer.h"
//#include "Adafruit_DHT/Adafruit_DHT.h"
//#define DHTPIN 2 // what pin we're connected to
//#define DHTTYPE DHT11 // DHT 22 (AM2302)
//#define BLYNK_PRINT Serial
SparkCorePolledTimer updateTimer(5000); //Create a timer object and set it's timeout in milliseconds
void OnTimer(void); //Prototype for timer callback method
DHT dht(DHTPIN, DHTTYPE);
float h, t, f, c,
int m, mRaw, l, lRaw;
//char auth[] = "MY_AUTH_TOKEN";
void setup() {
Serial.begin(9600);
updateTimer.SetCallback(OnTimer);
Serial.println("DHTxx test!");
dht.begin();
delay(5000); // Allow board to settle
pinMode(A4, OUTPUT);
pinMode(A5, OUTPUT);
Blynk.begin(auth);
}
void loop() {
Blynk.run();
updateTimer.Update();
h = dht.getHumidity();
--t = dht.getTempFarenheit();
t = dht.getTempCelcius();
mRaw = analogRead(A4);
lRaw = analogRead(A5);
m = map(mRaw, 400, 3200, 0, 100);
l = map(lRaw, 400, 3200, 0, 100);
// Check if any reads failed and exit early (to try again).
if (isnan(h) || isnan(t) || isnan(f)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
}
void OnTimer(void) { //Handler for the timer, will be called automatically
t = ((int) (t * 10) / 10.0);
h = ((int) (h * 10) / 10.0);
Blynk.virtualWrite(21, t);
Blynk.virtualWrite(22, h);
Blynk.virtualWrite(23, m);
Blynk.virtualWrite(24, l);
}
*ERRORS
In file included from blynk/BlynkParticle.h:16:0,
from blynk/BlynkSimpleParticle.h:14,
from blynk/blynk.h:2,
from blynkapiparticle.cpp:5:
blynk/BlynkApiParticle.h:78:6: warning: #warning "analogInputToDigitalPin not defined => Named analog pins will not work" [-Wcpp]
#warning "analogInputToDigitalPin not defined => Named analog pins will not work"
^
blynkapiparticle.cpp:128:1: error: expected unqualified-id before 'int'
//#define BLYNK_PRINT Serial
^
blynkapiparticle.cpp: In function 'void setup()':
blynkapiparticle.cpp:132:6: error: redefinition of 'void setup()'
^
blynkapiparticle.cpp:25:6: error: 'void setup()' previously defined here
^
blynkapiparticle.cpp: In function 'void loop()':
blynkapiparticle.cpp:143:6: error: redefinition of 'void loop()'
dht.begin();
^
blynkapiparticle.cpp:85:6: error: 'void loop()' previously defined here
^
blynkapiparticle.cpp:151:5: error: 'mRaw' was not declared in this scope
^
blynkapiparticle.cpp:152:5: error: 'lRaw' was not declared in this scope
Blynk.run();
^
blynkapiparticle.cpp:153:5: error: 'm' was not declared in this scope
updateTimer.Update();
^
blynkapiparticle.cpp:154:5: error: 'l' was not declared in this scope
^
blynkapiparticle.cpp: In function 'void OnTimer()':
blynkapiparticle.cpp:170:26: error: 'm' was not declared in this scope
void OnTimer(void) { //Handler for the timer, will be called automatically
^
blynkapiparticle.cpp:171:26: error: 'l' was not declared in this scope
^
make[1]: *** [../build/target/user/platform-6blynkapiparticle.o] Error 1
make: *** [user] Error 2
Error: Could not compile. Please review your code.