The array code is long gone. What I found with arrays was I could add a number to the value of the integer, as opposed to defining a separate integer. I will post below an array from a similar code. He appears to be using three sensors. He is writing the int VWC value to two separate pins. Its not clear to me if that is the same value or if it is from the two separate sensors. Also not sure why it would be written on two pins if their are three sensors. I am posting the parts of his code I believe are relevant.
from: SendUptime does not work (iOS 9.0.1) - #10 by kjeske - Blynk Community
const int sensorsConnected = 2; //number of sensors
// read three sensors and append to the string:
for (int analogPin = 0; analogPin < (sensorsConnected); analogPin++) {
float sensorValue = analogRead(analogPin);
float volt = (sensorValue / 1024.0) * 5.00 * 1.01 ; //Ref 5V
int VWC = 0;
//Volumetric Water Content is a piecewise function of the voltage from the sensor
if (volt < 0.00001 ) {
VWC = 0;
}
else if (volt < 1.1) {
VWC = (10 * volt) - 1;
}
else if (volt < 1.3) {
VWC = (25 * volt) - 17.5;
}
else if (volt < 1.82) {
VWC = (48.08 * volt) - 47.5;
}
else if (volt < 2.2) {
VWC = (26.32 * volt) - 7.89;
}
else {
VWC = (62.5 * volt) - 87.5;
}
dataString += String(VWC);
if (analogPin < (sensorsConnected - 1)) {
dataString += "%,";
}
else if (analogPin < (sensorsConnected)) {
dataString += "%";
}
Blynk.virtualWrite(1, VWC);
Blynk.virtualWrite(2, VWC);
Blynk.virtualWrite(3, volt);
Blynk.virtualWrite(7, millis() / 60000);
}
The code I am currently working on is below. As you can see I am also learning to use Blynk, but I am still setting up the core Arduino functionality for this project. Again, no arrays currently, but I wanted to post because I'll take any input I can get. I'm sure this isn't the most efficient code.
#include <Blynk.h>
#define BLYNK_PRINT Serial
#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "xxx";
#define W5100_CS 10
#define SDCARD_CS 4
int sensorData2(2);
int sensorData3(2);
int sensorData4(2);
int sensorData5(2);
int relay2 = 2;
int relay3 = 7;
int relay4 = 8;
int relay5 = 12;
int thres = 16;
int VWC2(2);
int VWC3(2);
int VWC4(2);
int VWC5(2);
BlynkTimer timer; // Announcing the timer
void myTimerEvent()
{
sensorData2 = analogRead(A2);
Blynk.virtualWrite(V2, sensorData2);
sensorData3 = analogRead(A3);
Blynk.virtualWrite(V3, sensorData3);
sensorData4 = analogRead(A4);
Blynk.virtualWrite(V4, sensorData4);
sensorData5 = analogRead(A5);
Blynk.virtualWrite(V5, sensorData5);
}
void vh400loop() {
float volt2 = (sensorData2 / 1024.0) * 5.00 * 1.01 ; //Ref 5V
//VWC Curve
if (volt2 < 0.00001 ) {
VWC2 = 0;
}
else if (volt2 < 1.1) {
VWC2 = (10 * volt2) - 1;
}
else if (volt2 < 1.3) {
VWC2 = (25 * volt2) - 17.5;
}
else if (volt2 < 1.82) {
VWC2 = (48.08 * volt2) - 47.5;
}
else if (volt2 < 2.2) {
VWC2 = (26.32 * volt2) - 7.89;
}
else {
VWC2 = (62.5 * volt2) - 87.5;
}
float volt3 = (sensorData3 / 1024.0) * 5.00 * 1.01 ; //Ref 5V
if (volt3 < 0.00001 ) {
VWC3 = 0;
}
else if (volt3 < 1.1) {
VWC3 = (10 * volt3) - 1;
}
else if (volt3 < 1.3) {
VWC3 = (25 * volt3) - 17.5;
}
else if (volt3 < 1.82) {
VWC3 = (48.08 * volt3) - 47.5;
}
else if (volt3 < 2.2) {
VWC3 = (26.32 * volt3) - 7.89;
}
else {
VWC3 = (62.5 * volt3) - 87.5;
}
float volt4 = (sensorData4 / 1024.0) * 5.00 * 1.01 ; //Ref 5V
if (volt4 < 0.00001 ) {
VWC4 = 0;
}
else if (volt4 < 1.1) {
VWC4 = (10 * volt4) - 1;
}
else if (volt4 < 1.3) {
VWC4 = (25 * volt4) - 17.5;
}
else if (volt4 < 1.82) {
VWC4 = (48.08 * volt4) - 47.5;
}
else if (volt4 < 2.2) {
VWC4 = (26.32 * volt4) - 7.89;
}
else {
VWC4 = (62.5 * volt4) - 87.5;
}
float volt5 = (sensorData3 / 1024.0) * 5.00 * 1.01 ; //Ref 5V
if (volt5 < 0.00001 ) {
VWC5 = 0;
}
else if (volt3 < 1.1) {
VWC5 = (10 * volt5) - 1;
}
else if (volt5 < 1.3) {
VWC5 = (25 * volt5) - 17.5;
}
else if (volt5 < 1.82) {
VWC5 = (48.08 * volt5) - 47.5;
}
else if (volt5 < 2.2) {
VWC5 = (26.32 * volt5) - 7.89;
}
else {
VWC5 = (62.5 * volt5) - 87.5;
}
Blynk.virtualWrite(V12, VWC2);
Blynk.virtualWrite(V13, VWC3);
Blynk.virtualWrite(V14, VWC4);
Blynk.virtualWrite(V15, VWC5);
}
void WaterRelayLoop()
{
if ( VWC2 < thres) {
digitalWrite(relay2, HIGH);
Blynk.virtualWrite(V22, 1);
} else if (VWC3 > thres) {
digitalWrite(relay2, LOW);
Blynk.virtualWrite(V22, 0);
} else {
;
}
if (VWC3 < thres) {
digitalWrite(relay3, HIGH);
Blynk.virtualWrite(V23, 1);
} else if (VWC3 > thres)
{ digitalWrite(relay3, LOW);
Blynk.virtualWrite(V23, 0);
}
else {
;
}
if (VWC4 < thres) {
digitalWrite(relay4, HIGH);
Blynk.virtualWrite(V24, 1);
} else if (VWC4 > thres) {
digitalWrite(relay4, LOW);
Blynk.virtualWrite(V24, 0);
} else {
;
}
if (VWC5 < thres) {
digitalWrite(relay5, HIGH);
Blynk.virtualWrite(V25, 1);
} else if (VWC5 > thres) {
digitalWrite(relay5, LOW);
Blynk.virtualWrite(V25, 0);
}
else {
;
}
}
void setup()
{
// Debug console
Serial.begin(9600);
pinMode(SDCARD_CS, OUTPUT);
digitalWrite(SDCARD_CS, HIGH); // Deselect the SD card
pinMode(relay2, OUTPUT);
pinMode(relay3, OUTPUT);
pinMode(relay4, OUTPUT);
pinMode(relay5, OUTPUT);
Blynk.begin(auth, IPAddress(192, 168, 1, 77), 8442);
// Setup a function to be called every second
timer.setInterval(1000L, myTimerEvent);
timer.setInterval(2000L, WaterRelayLoop);
timer.setInterval(2000L, vh400loop);
}
void loop()
{
Blynk.run();
timer.run(); // Initiates BlynkTimer
}
Thanks everyone!