Hi I need some help please,
I cannot get my boron to read on analog pin A1, tried different pins but still no reading. I have tested the pin with multimeter and there is voltage.
Context: Code written in Arduino IDE, then copied in the particle console Web IDE, am using Blynk library to control via blynk app.
Your help would be greatly appreciated - tried everything I can think of and I’ve run out of ideas.
Please see code below:
// This #include statement was automatically added by the Particle IDE.
#include <Adafruit_DHT.h>
// This #include statement was automatically added by the Particle IDE.
#include <blynk.h>
/*************************************************************
Blynk is a platform with iOS and Android apps to control
Arduino, Raspberry Pi and the likes over the Internet.
You can easily build graphic interfaces for all your
projects by simply dragging and dropping widgets.
Downloads, docs, tutorials: http://www.blynk.cc
Sketch generator: http://examples.blynk.cc
Blynk community: http://community.blynk.cc
Follow us: http://www.fb.com/blynkapp
http://twitter.com/blynk_app
Blynk library is licensed under MIT license
This example code is in public domain.
*************************************************************
No coding required for direct digital/analog pin operations!
*************************************************************/
#define BLYNK_PRINT Serial // Set serial output for debug prints
//#define BLYNK_DEBUG // Uncomment this to see detailed prints
/* Fill-in your Template ID (only if using Blynk.Cloud) */
//#define BLYNK_TEMPLATE_ID "YourTemplateID"
// Uncomment this, if you want to set network credentials
//#include "cellular_hal.h"
//STARTUP(cellular_credentials_set("broadband", "", "", NULL));
// Run "ping blynk-cloud.com", and set Blynk IP to the shown address
#define BLYNK_IP IPAddress(45,55,130,102)
// Set Blynk hertbeat interval.
// Each heartbeat uses ~90 bytes of data.
#define BLYNK_HEARTBEAT 60
// Set Particle keep-alive ping interval.
// Each ping uses 121 bytes of data.
#define PARTICLE_KEEPALIVE 20
// This #include statement was automatically added by the Particle IDE.
#include <blynk.h>
// This #include statement was automatically added by the Particle IDE.
#include "Adafruit_DHT.h"
//DHT 11 CONFIGURATION
// Example testing sketch for various DHT humidity/temperature sensors
// Written by ladyada, public domain
#define DHTPIN D1 // what pin we're connected to
//#define DHTTYPE DHT11 // DHT 11
#define DHTTYPE DHT22 // DHT 22 (AM2302)
//#define DHTTYPE DHT21 // DHT 21 (AM2301)
// Connect pin 1 (on the left) of the sensor to +5V
// Connect pin 2 of the sensor to whatever your DHTPIN is
// Connect pin 4 (on the right) of the sensor to GROUND
// Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor
DHT dht(DHTPIN, DHTTYPE);
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
BlynkTimer timer;
//PINS
int Relay1_Pin = D9;
int Relay2_Pin = D2;
int Relay3_Pin = D3;
int Relay4_Pin = D4;
int Relay5_Pin = D5;
int Relay6_Pin = D6;
int Relay7_Pin = D7;
int Relay8_Pin = D8;
int Voltage_Battery_1_Pin = A1;
int Voltage_Battery_2_Pin = A5;
int Voltage_Battery_1_RAW = 0;
int Voltage_Battery_2_RAW = 0;
float Voltage_Battery_1 = 0;
float Voltage_Battery_2 = 0;
float DHT11_Temperature = 0;
void setup() {
Serial.begin(115200);
Serial.println("Particle Boron Step UP Stage");
//pinMode(Voltage_Battery_1_Pin , INPUT);
// pinMode(Voltage_Battery_2_Pin , INPUT);
pinMode(Relay1_Pin, OUTPUT);
pinMode(Relay2_Pin, OUTPUT);
pinMode(Relay3_Pin, OUTPUT);
pinMode(Relay4_Pin, OUTPUT);
pinMode(Relay5_Pin, OUTPUT);
pinMode(Relay6_Pin, OUTPUT);
pinMode(Relay7_Pin, OUTPUT);
pinMode(Relay8_Pin, OUTPUT);
Particle.keepAlive(PARTICLE_KEEPALIVE);
Blynk.begin(auth, BLYNK_IP);
DHT11_Setup_Stage();
timer.setInterval(2000L, DHT11_Loop_Stage);
timer.setInterval(2000L, Read_Battery_Voltages);
timer.setInterval(5000L, UploadToCloud);
}
void loop() {
Blynk.run();
timer.run();
}
void UploadToCloud() {
Blynk.virtualWrite(V5, Voltage_Battery_1);
Blynk.virtualWrite(V6, Voltage_Battery_2);
Blynk.virtualWrite(V7, DHT11_Temperature);
//cont char * pointer from Int
String Temperature = String(DHT11_Temperature);
String Battery1 = String(Voltage_Battery_1_RAW);
String Battery2 = String(Voltage_Battery_2_RAW);
Particle.publish("temperatureStatus",Temperature,60,PRIVATE);
Particle.publish("Battery1Status",Battery1,60,PRIVATE);
Particle.publish("Battery2Status",Battery2,60,PRIVATE);
delay(3000);
// Particle.publish("battery1Status",Voltage_Battery_1,60,PRIVATE);
// Particle.publish("battery2Status",Voltage_Battery_2,60,PRIVATE);
}
void Read_Battery_Voltages(){
Voltage_Battery_1_RAW - digitalRead(Voltage_Battery_1_Pin);
Voltage_Battery_2_RAW - digitalRead(Voltage_Battery_2_Pin);
Serial.print("Voltage_Battery_1_RAW = ");
Serial.println(Voltage_Battery_1_RAW);
Serial.print("Voltage_Battery_2_RAW = ");
Serial.println(Voltage_Battery_2_RAW);
Voltage_Battery_1 = map(Voltage_Battery_1_RAW, 0, 1024, 0 , 12);
Voltage_Battery_2 = map(Voltage_Battery_1_RAW, 0, 1024, 0 , 12);
Serial.print("Voltage_Battery_1 = ");
Serial.println(Voltage_Battery_1);
Serial.print("Voltage_Battery_2 = ");
Serial.println(Voltage_Battery_2);
}
void DHT11_Setup_Stage(){
Serial.println("DHT11 test!");
dht.begin();
}
void DHT11_Loop_Stage(){
// Wait a few seconds between measurements.
delay(1000);
// 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.getHumidity();
// Read temperature as Celsius
float t = dht.getTempCelcius();
DHT11_Temperature = t;
// Read temperature as Farenheit
float f = dht.getTempFarenheit();
// 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;
}
// Compute heat index
// Must send in temp in Fahrenheit!
float hi = dht.getHeatIndex();
float dp = dht.getDewPoint();
float k = dht.getTempKelvin();
Serial.print("Humid: ");
Serial.print(h);
Serial.print("% - ");
Serial.print("Temp: ");
Serial.print(t);
Serial.print("*C ");
Serial.print(f);
Serial.print("*F ");
Serial.print(k);
Serial.print("*K - ");
Serial.print("DewP: ");
Serial.print(dp);
Serial.print("*C - ");
Serial.print("HeatI: ");
Serial.print(hi);
Serial.println("*C");
Serial.println(Time.timeStr());
}
BLYNK_WRITE(V1)
{
int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
// You can also use:
// String i = param.asStr();
// double d = param.asDouble();
Serial.print("Relay 1 value is: ");
Serial.println(pinValue);
if (pinValue == 1){
digitalWrite(Relay1_Pin, LOW);
} else if(pinValue == 0){
digitalWrite(Relay1_Pin, HIGH);
}
}
BLYNK_WRITE(V2)
{
int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
// You can also use:
// String i = param.asStr();
// double d = param.asDouble();
Serial.print("Relay 2 value is: ");
Serial.println(pinValue);
if (pinValue == 1){
digitalWrite(Relay2_Pin, LOW);
} else if(pinValue == 0){
digitalWrite(Relay2_Pin, HIGH);
}
}
BLYNK_WRITE(V3)
{
int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
// You can also use:
// String i = param.asStr();
// double d = param.asDouble();
Serial.print("Relay 3 value is: ");
Serial.println(pinValue);
if (pinValue == 1){
digitalWrite(Relay3_Pin, LOW);
} else if(pinValue == 0){
digitalWrite(Relay3_Pin, HIGH);
}
}
BLYNK_WRITE(V4)
{
int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
// You can also use:
// String i = param.asStr();
// double d = param.asDouble();
Serial.print("Relay 4 value is: ");
Serial.println(pinValue);
if (pinValue == 1){
digitalWrite(Relay4_Pin, LOW);
} else if(pinValue == 0){
digitalWrite(Relay4_Pin, HIGH);
}
}