Sending DHT22 data from Arduino to Blynk and Thingspeak over Bluetooth | ThingSpeak Projects | Forum

Avatar

Please consider registering
Guest

sp_LogInOut Log In sp_Registration Register

Register | Lost password?
Advanced Search

— Forum Scope —






— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

sp_Feed sp_TopicIcon
Sending DHT22 data from Arduino to Blynk and Thingspeak over Bluetooth
No permission to create posts
February 14, 2019
7:50 am
Avatar
Sandy
New Member
Members
Forum Posts: 4
Member Since:
February 14, 2019
sp_UserOfflineSmall Offline

Hi,
I'm working on a project that requires me to send sensor readings to Blynk and ThingSpeak over Bluetooth. I am able to send the readings to Blynk and using Blynks webhook widget I am trying to send the data to my ThingSpeak channel.

I haven't been able to get the data displayed on the graphs, even though the number of entries increases. The graphs I have sent up are displaying straight lines at 0. I'm wondering if it is possible to send the sensor data to ThingSpeak by using the webhook widget.

I don't have any sort of WiFi module in this project, all I am working with is the DHT22 sensor, an Arduino Uno and an Open-Smart Bluetooth module.

February 14, 2019
4:13 pm
Avatar
cstapels
Moderator
Members


Moderators
Forum Posts: 861
Member Since:
March 7, 2017
sp_UserOfflineSmall Offline

Using bluetooth to update ThingSpeak sounds like an interesting project. Can you tell us more about your project?

It is possible that you are sending extra characters in your data that ThingSpeak is interpreting as strings, or the data is not going into the field you expect it is.
Try looking at the export recent data button on your channel view.
You can post the data here is if is not clear why it is not plotting, or you can share your channel number if it is public and I will have a look.

February 15, 2019
7:29 am
Avatar
Sandy
New Member
Members
Forum Posts: 4
Member Since:
February 14, 2019
sp_UserOfflineSmall Offline

I have written code that will send the sensor data to Blynk over Bluetooth. Using a webhook widget in Blynk I am trying to send the data to ThingSpeak.

In the Blynk webhook I have the URL: http://api.thingspeak.com/update?api_key=XXXXXXX&field1=t&field2=h&field3=ldr
I have noticed that if I put field1= 20, the value will be updated on the graph.

This is the code I have:

```

#define BLYNK_PRINT Serial

#include
#include
#include
#include
#include

// Auth Token recieved in the Blynk App.
char auth[] = "7c5d501236d44df3838c01cffc2f086e";
char thingspeak = "1CO81IDJXVZVGRDV" ;

// create ble serial instance
SoftwareSerial SerialBLE(10, 11); // Rx, Tx

#define DHTPIN 13 // Pin DHT22 is connected to
#define ldrPIN A0 // Pin LDR is connected to

#define DHTTYPE DHT22 // DHT 22

float t;
float h;
float ldr;

DHT dht(DHTPIN, DHTTYPE);
BlynkTimer timer;

void setup()
{
// Debug console
Serial.begin(9600);
SerialBLE.begin(9600);

Blynk.begin(SerialBLE, auth);

Serial.println("Waiting for connections...");

dht.begin();

// Setup a function to be called every 5 second
timer.setInterval(10000, sendSensor);
timer.setInterval(10000, sendLDR);
timer.setInterval(30000, SendtoThingspeak);

}

void loop()
{
Blynk.run();
timer.run();
}
void sendSensor()
{
float h = dht.readHumidity();
// String hString = String(h);

float t = dht.readTemperature();
// String tString = String(t);

// Write DHT22 values to Blynk
Blynk.virtualWrite(V4, h);
Blynk.virtualWrite(V5, t);
}

void sendLDR()
{
float ldr = analogRead(ldr);

// Write LDR values to Blynkd
Blynk.virtualWrite(V6, ldr);
}

void SendtoThingspeak()
{
Blynk.virtualWrite(V3, t, h, ldr);
}

```

Sorry if the code is difficult to follow, I don't know how to format it on here. I've been using trial and error for a while now trying to figure it out and am out of ideas as to how to get it working.

February 15, 2019
5:39 pm
Avatar
cstapels
Moderator
Members


Moderators
Forum Posts: 861
Member Since:
March 7, 2017
sp_UserOfflineSmall Offline

Formatting code can be rough here.

Is it possible that blynk does not know you are inserting a variable into your webhook url?
http://api.thingspeak.com/update?api_key=XXXXXXX&field1=t&field2=h&field3=ldr

If you scroll down about 1000 pages in their doc
https://docs.blynk.cc/
(I searched 'webhooks") They mention you can escape pin values.

It looks like you can assign a pin value to the webhooks widget, and they talk about using an array to send multiple values.
Let us know if you get it working. I might try Blynk out myself now...

February 18, 2019
7:24 am
Avatar
Sandy
New Member
Members
Forum Posts: 4
Member Since:
February 14, 2019
sp_UserOfflineSmall Offline

I have tried changing the URL to http://api.thingspeak.com/update?api_key=XXXXXXX&field1=/pin%5B0%5D/&field2=/pin%5B1%5D/&field3/pin%5B2%5D/
I'm still getting 0 as the output.

I looked at the document and I don't fully understand how to put the data as an array. I added this to my code:

BLYNK_WRITE(V0){
String webhookdata = param.asStr();

}

But I had no luck.

I have noticed that if I put field1 = 50, 50 will be displayed on the graph. So I think this means that the Bluetooth link between Blynk and Thingspeak works, and I just need to figure out how to get real-time sensor readings to sent and displayed on Thingspeak.

This is my channel id: 639757, I have made it public if you don't mind having a look at it and seeing if I've it sent up correctly.

February 18, 2019
8:08 am
Avatar
Sandy
New Member
Members
Forum Posts: 4
Member Since:
February 14, 2019
sp_UserOfflineSmall Offline

I got it working!! I added the line:

String temp = String(dht.readTemperature());
Blynk.virtualWrite(V3, temp);

And Thingspeak started to display the correct temperature values.

My final question is how do I change the x-axis to display the time instead of the date?

February 19, 2019
9:08 am
Avatar
cstapels
Moderator
Members


Moderators
Forum Posts: 861
Member Since:
March 7, 2017
sp_UserOfflineSmall Offline

I noticed that you are trying to write multiple fields. If you try to do this too frequently, ThingSpeak may reject some data. If you do an update to multiple fields in the same post, you will be way less likely to hit the limit. That is why I suggested using the array. Just something to watch out for.

When I went to your channel page, the x-axis seems to be in time not date.

You can edit the number of results or number of days using the pencil icon, but if you want more direct control of the x-axis, I suggest using a MATLAB visualization to make a custom plot.
https://www.mathworks.com/help/thingspeak/Plot-Temperature-and-Wind-Speed-on-Two-Different-Axes.html

You can also use the charts control to specify a specific date range with start and end.
https://www.mathworks.com/help/thingspeak/createchart.html

Forum Timezone: America/New_York

Most Users Ever Online: 166

Currently Online:
9 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

rw950431: 272

Vinod: 240

piajola: 95

turgo: 70

vespapierre: 63

Adarsh_Murthy: 62

Member Stats:

Guest Posters: 1

Members: 8665

Moderators: 1

Admins: 2

Forum Stats:

Groups: 3

Forums: 14

Topics: 1600

Posts: 5760

Newest Members:

khanhNguyen_CT, susyburr, quijano__, meosuckhoe, briskpanda, Dejw0089

Moderators: cstapels: 460

Administrators: Hans: 405, lee: 457