My LED won't turn on

Hello! I'm trying to build an automated irrigation system and I'm starting it as simple as possible. I'd like a scheduler to turn it on for a period of time.

#include "arduino_secrets.h"
/*
  Sketch generated by the Arduino IoT Cloud Thing "Untitled 2"
  https://create.arduino.cc/cloud/things/75dbf6fd-a50a-44cf-a191-3fde8785ccc1

  Arduino IoT Cloud Variables description

  The following variables are automatically generated and updated when changes are made to the Thing

  CloudSchedule ferti;
  CloudSchedule schedule;
  bool pump_status;
  bool pump_status2;

  Variables which are marked as READ/WRITE in the Cloud Thing will also have functions
  which are called when their values are changed from the Dashboard.
  These functions are generated with the Thing and added at the end of this sketch.
*/
int pump = 7;
int pump2 = 8;
#include "thingProperties.h"

void setup() {
  // Initialize serial and wait for port to open:
  Serial.begin(9600);
  // This delay gives the chance to wait for a Serial Monitor without blocking if none is found
  delay(1500);

  // Defined in thingProperties.h
  initProperties();

  // Connect to Arduino IoT Cloud
  ArduinoCloud.begin(ArduinoIoTPreferredConnection);

  /*
     The following function allows you to obtain more information
     related to the state of network and IoT Cloud connection and errors
     the higher number the more granular information you’ll get.
     The default is 0 (only errors).
     Maximum is 4
  */
  setDebugMessageLevel(2);
  ArduinoCloud.printDebugInfo();
}

void loop() {
  ArduinoCloud.update();
  // Your code here
  if (schedule.isActive()) {
    digitalWrite(pump,HIGH);
    pump_status = true;
    digitalWrite(LED_BUILTIN,HIGH);
  }
  else {
    digitalWrite(pump,LOW);
    pump_status = false;
    digitalWrite(LED_BUILTIN,LOW);
  }
  
  if (ferti.isActive()) {
    digitalWrite(pump2,HIGH);
    pump_status2 = true;
  }
  else {
    digitalWrite(pump2,LOW);
    pump_status2 = false;
  }

}



/*
  Since PumpStatus is READ_WRITE variable, onPumpStatusChange() is
  executed every time a new value is received from IoT Cloud.
*/
void onPumpStatusChange()  {
  // Add your code here to act upon PumpStatus change
}

/*
  Since Schedule is READ_WRITE variable, onScheduleChange() is
  executed every time a new value is received from IoT Cloud.
*/
void onScheduleChange()  {
  // Add your code here to act upon Schedule change
}

/*
  Since Ferti is READ_WRITE variable, onFertiChange() is
  executed every time a new value is received from IoT Cloud.
*/
void onFertiChange()  {
  // Add your code here to act upon Ferti change
}

/*
  Since PumpStatus2 is READ_WRITE variable, onPumpStatus2Change() is
  executed every time a new value is received from IoT Cloud.
*/
void onPumpStatus2Change()  {
  // Add your code here to act upon PumpStatus2 change
}

The builtin LED works fine the the voltage on my 7 and 8 pins are zero.

I tried running another very simple program:

digitalWrite(led1,HIGH);
  digitalWrite(led2,LOW);
  digitalWrite(LED_BUILTIN,LOW);
  delay(1000);
  digitalWrite(led2,HIGH);
  digitalWrite(led1,LOW);
  digitalWrite(LED_BUILTIN,HIGH);
  delay(1000);

and on this blink exercise, the LEDs work fine.

Can anybody explain why my pins 7 and 8 are not giving me 5V when the scheduler hits the programmed time?

Thanks!!!

pinMode(pump, OUTPUT);
pinMode(pump2, OUTPUT);

I'm not seeing a pinMode call anywhere in your code. Without that, the pins default to being inputs. Maybe it's different for Cloud Thing code but it seems odd all the same.

2 Likes

Thank you!!! Now it's working.

Hello , I have a similar problem with the simple LED .
The dashboard doesn't seem to control the LED. Here's my code

/* 
  Sketch generated by the Arduino IoT Cloud Thing "Untitled"
  https://create.arduino.cc/cloud/things/7f4a3800-ba37-4b11-8e77-9e3aed3c1a00 

  Arduino IoT Cloud Variables description

  The following variables are automatically generated and updated when changes are made to the Thing

  CloudLight ledcontrol;

  Variables which are marked as READ/WRITE in the Cloud Thing will also have functions
  which are called when their values are changed from the Dashboard.
  These functions are generated with the Thing and added at the end of this sketch.
*/

#include "thingProperties.h"
int ledpin =4;
void setup() {
  // Initialize serial and wait for port to open:
  Serial.begin(9600);
  // This delay gives the chance to wait for a Serial Monitor without blocking if none is found
  delay(1500);
  ledcontrol = false;
pinMode(ledpin, OUTPUT);
  pinMode(2, OUTPUT);
  // Defined in thingProperties.h
  initProperties();

  // Connect to Arduino IoT Cloud
  ArduinoCloud.begin(ArduinoIoTPreferredConnection);
  
  /*
     The following function allows you to obtain more information
     related to the state of network and IoT Cloud connection and errors
     the higher number the more granular information you’ll get.
     The default is 0 (only errors).
     Maximum is 4
 */
  setDebugMessageLevel(2);
  ArduinoCloud.printDebugInfo();
}

void loop() {
  ArduinoCloud.update();
  // Your code here 
 digitalWrite(ledpin, HIGH);
delay(1000);

 digitalWrite(ledpin, LOW);
 delay(1000); 

}

/*
  Since Ledcontrol is READ_WRITE variable, onLedcontrolChange() is
  executed every time a new value is received from IoT Cloud.
*/
void onLedcontrolChange()  {
  // Add your code here to act upon Ledcontrol change
 if (ledcontrol == 1) { 

  digitalWrite(2, HIGH);
delay(1000);

}
  else {

    Serial.println("OFF");
  digitalWrite(2, LOW);
delay(1000);
  }
}

Hello, @sodiqa - Please, start a topic of your own to ask your question so you will get answers for your project. (what you have done is called "hijacking a topic")

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.