Terminal to Graph

Hello! I am working on a sun-tracking solar panel. I’ve gotten the sun tracking portion to work, but I’m having trouble getting data to appear in the app. I’m connecting to the Arduino Uno via bluetooth. I have been trying to use the terminal to ask the user if it is sunny or cloudy out, and based on their answer, store the light flux value to the corresponding data set (to be displayed on the graph). I have been trying to do this with digital pins, but I don’t think I know enough about coding to recognize what I am doing incorrectly. I would appreciate any help/suggestions! Below is my current code:

#define BLYNK_PRINT Serial
#include <SoftwareSerial.h>
SoftwareSerial SwSerial(10, 11); // RX, TX  
#include <BlynkSimpleSerialBLE.h>
#include <SoftwareSerial.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "Auth Token : e2bc64ad889b46b091f58415da3b050b";
SoftwareSerial SerialBLE(10, 11); // RX, TX

#include <Servo.h> //includes servo
#include <stdlib.h> //includes standard library
Servo myservo; // create servo object to control a servo
int sensorOne=2; //digital pin 2 has connected to the resistor of first sensor
int inputOne=0; //variable to store the values from the analog pin 0
int servoAngle=0; // variable to store the servo position, initial angle set to zero

WidgetTerminal terminal(V1);

  if (String("sunny") == param.asStr()); {
    terminal.println("It is currently sunny.");
    Blynk.virtualWrite(V2, analogRead(inputOne)); //sends data to sunny data set (virtual pin V2)
  if (String("cloudy") == param.asStr()) {
    Blynk.virtualWrite(V3, analogRead(inputOne)); //sends data to cloudy data set (virtual pin v3)
    terminal.println("It is currently cloudy.");
  terminal.flush(); //Ensure everything is sent.

void setup()
 Blynk.begin(SerialBLE, auth);
 //Serial.println("Waiting for connections...");
pinMode(sensorOne,OUTPUT); //initialize the digital pin as output
digitalWrite(sensorOne,HIGH); //voltage set to corresponding value of 5V
myservo.attach(9); // attaches the servo on pin 9 to the servo object
myservo.write(servoAngle); // tell servo to go to position in variable 'servoAngle'
terminal.println(F("Blynk v" BLYNK_VERSION ": Device started"));
terminal.println(F("Is it sunny or cloudy today?"));

void loop()
  float flux[179];
  for (servoAngle=0; servoAngle<180; servoAngle++) {
    flux[servoAngle]= analogRead(inputOne); //creates an array of values read from the LDR
    myservo.write(servoAngle); //moves servo from 0 to 180 degrees
    Serial.println(flux[servoAngle]); //writes values in flux array to graph
  int servoAngle2 = findMax(flux); //tells it to find max loctaion, see max function below
  myservo.write(servoAngle2); //tells servo to go to angle at which voltage is max, found in previous line
  delay(9000000); //delays for 15 min before checking again

int findMax(float* flux){ //function to find the location at which the voltage is maxiumum
 int maximum = 0;
  for (int c = 0; c < 180; c++)
    if (flux[c] > flux[maximum])
       maximum  = c;
  return maximum;

Might be easier to do so with the (currently undocumented) Segmented Switch…

EDIT - Fixed, tested and and reposted this example:

BLYNK_WRITE(V18) {  // Segmented Switch set to 3 buttons
  switch (param.asInt())  {
    case 1:  // Full Sun
      Blynk.virtualWrite(V19, "Full Sun");
    case 2:  // Partial sun & cloud
      Blynk.virtualWrite(V19, "Sun & Cloud");
    case 3:  // Overcast
      Blynk.virtualWrite(V19, "Overcast");

You will need to reevaluate your coding methods when using an IoT based system like Blynk…


Okay, thank you so much. I’ll try that!

I’m sorry if this is a dumb question, but how do I indicate the different options on the segmented switch? It doesn’t like the case 1, case 2 thing. Here is what I have:

  switch (param.asInt())
  int sensorvalue= analogRead(A0);
    case 1: // if it is sunny
      Blynk.virtualWrite(V2, analogRead(sensorvalue));
    {case 2: // if it is cloudy
      Blynk.virtualWrite(V3, analogRead(sensorvalue));

Here is the error:

exit status 1
case label '1' not within a switch statement

Perhaps having this interjected withing the switch...case() logic is causing the issue?? (EDIT - or more likely the syntax issue mentioned below).

If you need to read analog then do so in the chosen action…

case 1: { // Full Sun
        Blynk.virtualWrite(V2, analogRead(A0));

What is with the double {{

If I’m not mistaken the correct syntax for a switch…case is:

switch (var) {
  case label1:
    // statements
  case label2:
    // statements
    // statements

@ibk You are correct… serves me right for not testing the code before posting :blush: I would say that my memory isn’t what it used to be… but I can’t remember if that is true :stuck_out_tongue:

I will test and fix my post above.

… I’ve seen it all, I’ve done it all, but I don’t remember … :laughing::laughing:

1 Like