I have a UNO Q with Grove sensors for Temperature, Luminance and PIR Motion. I have an app in App Lab which reads the values from the sensors. This works!
Now, I want to send the values to the Arduino Cloud. I created a device, thing with variables. Created a dashboard in Arduino Cloud to show the values. Now I want to extend the app to send the values to Arduino Cloud. I can add the brick for Arduino Cloud.
But now I am stuck on how I can send the values to the Cloud. The example given is the Blinking Led, but this is receiving data from Arduino Cloud and sending it to the device sensor. But I want it the other way around. The examples I find on internet are not yet with App Lab. The API documentation is very limited. Can anyone help me?
how can I send a boolean called “motionDetected” to the Arduino Cloud?
App Lab can’t send data directly to Arduino Cloud. Only the device (your UNO Q) can publish variable updates. So you need to assign motionDetected inside your sketch and call ArduinoCloud.update(). App Lab can read from the Cloud dashboard, but it can’t push values into Cloud variables.
ok, but how does the code look like for this? Anyone got some example code?
Here’s a minimal example.
The device itself updates the Cloud variable App Lab doesn’t send it.
You just set the variable and call ArduinoCloud.update():
#include "ArduinoCloud.h"
#include "CloudDevice.h"
bool motionDetected;
// this function is optional
void onMotionDetectedChange() {
// callback when the variable changes in cloud
}
void setup() {
pinMode(2, INPUT); // PIR sensor
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
}
void loop() {
int pir = digitalRead(2);
motionDetected = (pir == HIGH); // update cloud variable
ArduinoCloud.update(); // send values to Arduino Cloud
delay(200);
}
This is all you need the Cloud variable gets updated every time ArduinoCloud.update() runs.
Is this using the Brick in App Lab? Because this should work with the Bridge I think.
No, the Cloud update doesn’t go through the Brick.
The Brick/Bridge is only for App Lab ↔ device communication.
Cloud variables can only be updated from the device itself, so the sketch does the update directly with ArduinoCloud.update().
App Lab can read those values, but it doesn’t push them to the Cloud.
Alright.. not to be a smart-ass, just trying to understand. But what does this mean then?
https://docs.arduino.cc/tutorials/uno-q/arduino-cloud/
I read this (as the picture shows) that the communication with Arduino Cloud runs via the Brick, so via Python. (that is also how the Led Blink example works). Your code is all in the sketch, but that is the “old” Arduino approach. Am I correct?
Good question the diagram in that page shows both data paths at once, and it’s easy to mix them up.
The important thing is that there are two separate connections happening on the UNO Q:
- Brick/Bridge (Python) → connects App Lab ↔ device
- This is how App Lab reads your sensor values
- This is not connected to Arduino Cloud at all
- Arduino IoT connection → connects device ↔ Arduino Cloud
- This part is initialized inside the sketch with
ArduinoCloud.begin()
- Only the device can push variable updates to the Cloud
- This happens inside the MCU, not through the Brick
The Blink example works because the template sets up both things:
- It starts the Bridge for App Lab
- And it also starts the Cloud connection in the sketch
So yes: the picture shows both channels, but the Cloud updates don’t flow through Python or the Brick they’re sent directly from the MCU.
When I use the Brick, and I also add the Library in the sketch for ArduinoCloud, it gives an error on compliing. I would assume the ArduinoCloud is already in the Brick (which is also stated in the Python) but can’t get it working out of the sketch.
Anyone else any suggestions?
The Brick doesn’t include the ArduinoCloud code it only handles the Python ↔ device communication.
The IoT/Cloud connection still has to be set up inside the sketch, with the correct headers and the device’s credentials.
If the sketch fails to compile when you add the Cloud library, it usually means the Cloud headers or the Thing configuration aren’t added correctly.
The Blink example works because its template already includes all the Cloud setup behind the scenes.
In my python file, the connection is set up. I see the board also online in the cloud.
from arduino.app_bricks.arduino_cloud import ArduinoCloud
from arduino.app_utils import App, Bridge
# If secrets are not provided in the class initialization, they will be read from environment variables
iot_cloud = ArduinoCloud()
App.run()
The Brick handles all the communication (as said by Arduino). Now, I only have to update the variable in the dashboard.
Even if the Brick brings your board online and you see it in the Cloud, the variable updates still have to be pushed from the sketch. The Python Brick can’t update IoT Cloud variables by itself it only tunnels data for App Lab.
So the board may appear online, but unless your sketch includes the ArduinoCloud library, the Thing credentials, and the calls to ArduinoCloud.update(), the dashboard variables will never change. The Cloud backend only accepts updates from the MCU, not from Python or the Brick
I’m sorry, but I think what you say is not correct. The architecture states that the Bricks run on Python. The Brick for Arduino Cloud handles all the Arduino Cloud stuff. In the documentation, it also states “Enables data exchange between devices and the cloud“.
Even in the example for the the blinking led, the communication with Arduino Cloud is done within the Python, nothing regarding Arduino cloud is done in the sketch. In the Python, the registration of the LED is done and on_write, the method in the sketch is called using the Bridge to activate the LED on the hardware side. This seems also logic looking at the architecture => sketch for hardware, python for software.
It’s working!!
So first I had to figure out how to call a method from the sketch to Python. That works using Bridge. You first have to define the function in Python, then also provide them to the bridge.
And then the Python. It’s actualy quit simple! Nice work Arduino!
from arduino.app_bricks.arduino_cloud import ArduinoCloud
from arduino.app_utils import App, Bridge
# If secrets are not provided in the class initialization, they will be read from environment variables
iot_cloud = ArduinoCloud()
iot_cloud.register("temperature")
iot_cloud.register("motionDetected")
def update_motiondetected_cloud(value: bool):
iot_cloud.motionDetected = value
def update_temperature_cloud(value: float):
iot_cloud.temperature = value
Bridge.provide("update_motiondetected_cloud", update_motiondetected_cloud)
Bridge.provide("update_temperature_cloud", update_temperature_cloud)
App.run()
So when you register the variables, they are know to ArduinoCloud. So you can set the value like a parameter! Nice!