I have read various articles for days in the forum and went through the documentation but have not been able to come up with a way to send data from Arduino to Cloud via Bolt.
I have downloaded the boltiot-arduino-helper and even put my credentials in the BoltDeviceCredentials.
I have a DHT11 and an LDR, I want to be able to read the data received in arduino from these two sensors regarding temperature, humidity and light, and send it to the cloud to make a graph out of it.
Please send me step-by-step instructions. I have even tried the DHT2Cloud but could not implement it. Please help me as I am using Bolt in my Final Year Project.
In the loop() function, read the data from your sensors and store it in variables. For example:
float temperature = dht.readTemperature(); // Read temperature from DHT11 sensor
float humidity = dht.readHumidity(); // Read humidity from DHT11 sensor
int light = analogRead(LDRPIN); // Read light intensity from LDR sensor
Use the BoltIoT-Arduino-Helper library to send the data to the Bolt Cloud. To do this, you’ll need to initialize the Bolt device, connect to the Bolt Cloud, and send the data using the Bolt Cloud API. Here’s an example code snippet:
#include <BoltIoT-Arduino-Helper.h>
// Define your Bolt device credentials
char deviceName[] = "BOLTXXXXXXX"; // Replace XXXXXXX with your device ID
char apiKey[] = "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"; // Replace X with your API key
void setup() {
// Initialize serial communication
Serial.begin(9600);
// Initialize Bolt device
boltiot.begin(deviceName, apiKey, &Serial);
// Connect to Bolt Cloud
boltiot.connectWiFi("YOUR_WIFI_SSID", "YOUR_WIFI_PASSWORD");
// Wait for Bolt Cloud connection
while (!boltiot.isWiFiConnected()) {
delay(100);
}
}
void loop() {
// Read sensor data
float temperature = dht.readTemperature(); // Read temperature from DHT11 sensor
float humidity = dht.readHumidity(); // Read humidity from DHT11 sensor
int light = analogRead(LDRPIN); // Read light intensity from LDR sensor
// Send data to Bolt Cloud
boltiot.setCommandString("{\"temperature\":" + String(temperature) +
",\"humidity\":" + String(humidity) +
",\"light\":" + String(light) + "}");
boltiot.triggerEvent("sensor_data");
// Wait for next reading
delay(10000); // 10 seconds
}
Replace the deviceName, apiKey, YOUR_WIFI_SSID, and YOUR_WIFI_PASSWORD placeholders in the code with your actual device ID, API key, Wi-Fi network SSID, and Wi-Fi network password, respectively.
Upload the sketch to your Arduino board.
Open the Bolt Cloud dashboard and create a new product with a device. Make sure to note down the API key and device ID.
In the Bolt Cloud dashboard, create a new event with the name “sensor_data”.
Wait for the data to be sent from the Arduino board to the Bolt Cloud.
In the Bolt Cloud dashboard, go to the “sensor_data” event and click on “View Data”. You should see a graph of the sensor data.
I hope these instructions help you send data from Arduino to Cloud via Bolt. Let me know
Final Code To Push the data to the Cloud with the help of Bolt Library which has to be typed in Arduino IDE:
// Include the Bolt Library:
#include <BoltDeviceCredentials.h>
#include <boltiot.h>
// Include DHT Library:
#include <DHT.h>
// Define the digital pin connected to the DHT sensor - DHT 11:
#define DHTTYPE DHT11
#define DHTPIN 2
DHT dht(DHTPIN, DHTTYPE);
// Initialize the Analog pin connected to the LDR sensor:
const int ldrPin = A0;
// Whenever we are using the Bolt Library, we have to use “boltiot.begin(Serial);” instead of “Serial.begin(9600);” :
void setup() {
boltiot.begin(Serial);
//Serial.begin(9600);
dht.begin();
}
// Read humidity and temperature from DHT, Read light intensity from LDR sensor and Send the Data to the cloud:
void loop() {
float humidity = dht.readHumidity();
float temperature = dht.readTemperature();
float lightIntensity = analogRead(ldrPin);
boltiot.processPushDataCommand(dht.readHumidity(),dht.readTemperature(),analogRead(ldrPin));
Serial.print("Humidity: ");
Serial.print(humidity);
Serial.print("%\t");
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.print("C\t");
Serial.print("Light Intensity: ");
Serial.print(lightIntensity);
Serial.println();
delay(2000);
}
This code should be compiled & uploaded.
The following steps are to be followed in the Bolt Cloud:
Go to Bolt Cloud Account and Login/Signup using your Credentials.
You will be able to View your device ID on the Dashboard.
Go to Products —> Click on Add Product —> Click on Create new Product —> Enter the Product name —> Mark as “Input Device”—> Mark as “UART”.
Go to Configure this product —> Go to Hardware —> Choose the Data field Positions as 3 —> On the right hand side, enter the variable names in lower cases (example: temp, humi, light).
Go to Code —> Give a file name —> Choose the extension as JS.
When you are having more than 2 variables to be printed in the cloud it is better to use a Table graph rather than Line graph, The code below is for a Table graph where the values of Temp, Humidity and Light Intensity are being printed in a table. Save the code once written.
var Graph1 = new boltGraph();
Graph1.setChartType("tableGraph");
Graph1.setAxisName('X-Axis Name','Y-axis Name');
Graph1.plotChart('time_stamp','temp','humi','light');
Click on Link device to this product —> Select your device to link it —> Click on Done.
Click on Deploy Configuration —> Click on View Device.
You will be able to view the Data in the table.
Click on Push Data to Cloud if your want to get the current values.
You are able to view the data in the serial Monitor ? YES or NO (attach a screenshot)
Could you please attach a picture of the hardware configuration and the code which you have written in the Bolt Cloud.