Project with BMP180, DHT11 & ThingSpeak

Hello everyone! I'm new to the Arduino world and I have problems with the development of my project. I don't know if I posted topic in the good subforum, if I didn't, I'm sorry.

I could use some help with the programming, because I'm a complete newbie in Arduino and programming.

Components for the project:
Arduino Mega board
Arduino Ethernet shield
DHT11 humidity sensor
BMP180 temperature and air pressure sensor

The program should do next. The sensors have to measure the temperature, pressure and humidity of air in the room, and then send measured data to a ThingSpeak, so we can see measurement graphs. Also, Arduino would take information for outside temperature, pressure and humidity of air from some website with those data for a certain city (example London), and these data would alse be sent to ThingSpeak so we could see and compare graphs for indoor and outdoor data.

I hope someone of You will help me, because I don't know where to start. I've connected all the components (BMP180 to 3.3V, DHT11 to 5V), and now I have to develop a matching program. Thank you in advance!

Anybody? Any kind of hints would also be great.

A good start is doing the tutorials of each component on your project.

Do you maybe know where can I found any tutorials or sketches for sensors I am using?

I dont know one special example but there are many on google, just google arduino + dht11 and so on.

You might want to explain what a 'ThingSpeak' is, but you might structure your code a bit like this:

//include necessary libraries

int temp, hum, pres, tempLon, humLon, presLon;


void setup(){
  
  configureIOs();
}

void loop(){
  
  
  temp = readTemp();
  hum = readHum();
  pres = readPres();
  
  tempLon = londonTemp();
  humLon = londonHum();
  presLon = londonPres();
  
  
  do{
    boolean check = sendData();
  }while(!check);
}

int temp(){
  
  //code to read temperature sensor
}

int hum(){
  
  //code to read humidity sensor
}

int pres(){
  
  //code to read pressure sensor
}

int londonTemp(){
  
  //get London temperature via ethernet shield
}

int londonHum(){
  
  //get London temperature via ethernet shield
}
  
  
int londonPres();

  //get London temperature via ethernet shield
}


void sendData(){
  
  //code to send data to ThingSpeak
}

Here are some helpful libraries for the BMP180 and DHT11 sensors:

I hope this helps a little!

I will try with this, thank you.

Hi,
If you go to the sellers of these items you will probably find sample sketches.
OR GOOGLE the sensor name and arduino

You should find stacks of examples.
Also look under FILES, EXAMPLES in your IDE and see what is there, especially if you have no programming experience.

Tom.... :slight_smile:

Hi,
I have done bigger part of program, but it doesn't work. I found on one site similar code so I had to change few things. One of my questions is bolded in code.

Also, I would like to know if anybody knows how to write a function that will take information from one web page and then send it to ThingSpeak channel? I need to associate this with data that I will get through sensors.

#include <Ethernet.h>
#include <SPI.h>
#include <dht11.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BMP085.h>
#include <Wire.h>
Adafruit_BMP085 bmp;
dht11 DHT11;

// Local Network Settings
byte mac[] = { 0xD4, 0x28, 0xB2, 0xFF, 0xA0, 0xA1 }; ->what MAC address I need to write?
// ThingSpeak Settings
char thingSpeakAddress[] = "api.thingspeak.com";
String writeAPIKey = "QM6N1B8R1Y57YGRV";
const int updateThingSpeakInterval = 16 * 1000; 
// Variable Setup
long lastConnectionTime = 0;
boolean lastConnected = false;
int failedCounter = 0;
// Initialize Arduino Ethernet Client
EthernetClient client;

void setup() {
  // Start Serial for debugging on the Serial Monitor
Serial.begin(9600);
// Start Ethernet on Arduino
startEthernet();
}

void loop()
{
// Read value from Analog Input Pin 0
String analogPin0 = String(analogRead(A0), DEC);
// Print Update Response to Serial Monitor
if (client.available())
{
char c = client.read();
Serial.print(c);
}
//------DHT11--------
int chk = DHT11.read(DHT11PIN);
char h_buffer[10];
float h=(DHT11.humidity);
String humid=dtostrf(h,0,5,h_buffer);
//Serial.println(humid);

//-----BMP180-----------
bmp.begin();
            float p=(bmp.readPressure()/100.0);//pressure in hectoPascal
            float t=(bmp.readTemperature());
            char p_buffer[15];
            char t_buffer[10];
            String pres=dtostrf(p,0,5,p_buffer);
            String temp=dtostrf(t,0,5,t_buffer);
            Serial.println(pres);
 //         }
//----------------

// Disconnect from ThingSpeak
if (!client.connected() && lastConnected)
{
Serial.println("...disconnected");
Serial.println();
client.stop();
}
// Update ThingSpeak
if(!client.connected() && (millis() - lastConnectionTime > updateThingSpeakInterval))
{
updateThingSpeak("field1="+humid+"&field2="+pres+"&field3="+temp);
}
// Check if Arduino Ethernet needs to be restarted
if (failedCounter > 3 ) {startEthernet();}
lastConnected = client.connected();
}
void updateThingSpeak(String tsData)
{
if (client.connect(thingSpeakAddress, 80))
{
client.print("POST /update HTTP/1.1\n");
client.print("Host: api.thingspeak.com\n");
client.print("Connection: close\n");
client.print("X-THINGSPEAKAPIKEY: "+writeAPIKey+"\n");
client.print("Content-Type: application/x-www-form-urlencoded\n");
client.print("Content-Length: ");
client.print(tsData.length());
client.print("\n\n");
client.print(tsData);
lastConnectionTime = millis();
if (client.connected())
{
Serial.println("Connecting to ThingSpeak...");
Serial.println();
failedCounter = 0;
}
else
{
failedCounter++;
Serial.println("Connection to ThingSpeak failed ("+String(failedCounter, DEC)+")");
Serial.println();
}
}
else
{
failedCounter++;
Serial.println("Connection to ThingSpeak Failed ("+String(failedCounter, DEC)+")");
Serial.println();
lastConnectionTime = millis();
}
}
void startEthernet()
{
client.stop();
Serial.println("Connecting Arduino to network...");
Serial.println();
delay(1000);
// Connect to network amd obtain an IP address using DHCP
if (Ethernet.begin(mac) == 0)
{
Serial.println("DHCP Failed, reset Arduino to try again");
Serial.println();
}
else
{
Serial.println("Arduino connected to network using DHCP");
Serial.println();
}
delay(1000);
}

sc30:
Hi,
I have done bigger part of program, but it doesn't work. I found on one site similar code so I had to change few things. One of my questions is bolded in code.

Also, I would like to know if anybody knows how to write a function that will take information from one web page and then send it to ThingSpeak channel? I need to associate this with data that I will get through sensors.

#include <Ethernet.h>

#include <SPI.h>
#include <dht11.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BMP085.h>
#include <Wire.h>
Adafruit_BMP085 bmp;
dht11 DHT11;

// Local Network Settings
byte mac[] = { 0xD4, 0x28, 0xB2, 0xFF, 0xA0, 0xA1 }; ->what MAC address I need to write?
// ThingSpeak Settings
char thingSpeakAddress[] = "api.thingspeak.com";
String writeAPIKey = "QM6N1B8R1Y57YGRV";
const int updateThingSpeakInterval = 16 * 1000;
// Variable Setup
long lastConnectionTime = 0;
boolean lastConnected = false;
int failedCounter = 0;
// Initialize Arduino Ethernet Client
EthernetClient client;

void setup() {
  // Start Serial for debugging on the Serial Monitor
Serial.begin(9600);
// Start Ethernet on Arduino
startEthernet();
}

void loop()
{
// Read value from Analog Input Pin 0
String analogPin0 = String(analogRead(A0), DEC);
// Print Update Response to Serial Monitor
if (client.available())
{
char c = client.read();
Serial.print(c);
}
//------DHT11--------
int chk = DHT11.read(DHT11PIN);
char h_buffer[10];
float h=(DHT11.humidity);
String humid=dtostrf(h,0,5,h_buffer);
//Serial.println(humid);

//-----BMP180-----------
bmp.begin();
            float p=(bmp.readPressure()/100.0);//pressure in hectoPascal
            float t=(bmp.readTemperature());
            char p_buffer[15];
            char t_buffer[10];
            String pres=dtostrf(p,0,5,p_buffer);
            String temp=dtostrf(t,0,5,t_buffer);
            Serial.println(pres);
//        }
//----------------

// Disconnect from ThingSpeak
if (!client.connected() && lastConnected)
{
Serial.println("...disconnected");
Serial.println();
client.stop();
}
// Update ThingSpeak
if(!client.connected() && (millis() - lastConnectionTime > updateThingSpeakInterval))
{
updateThingSpeak("field1="+humid+"&field2="+pres+"&field3="+temp);
}
// Check if Arduino Ethernet needs to be restarted
if (failedCounter > 3 ) {startEthernet();}
lastConnected = client.connected();
}
void updateThingSpeak(String tsData)
{
if (client.connect(thingSpeakAddress, 80))
{
client.print("POST /update HTTP/1.1\n");
client.print("Host: api.thingspeak.com\n");
client.print("Connection: close\n");
client.print("X-THINGSPEAKAPIKEY: "+writeAPIKey+"\n");
client.print("Content-Type: application/x-www-form-urlencoded\n");
client.print("Content-Length: ");
client.print(tsData.length());
client.print("\n\n");
client.print(tsData);
lastConnectionTime = millis();
if (client.connected())
{
Serial.println("Connecting to ThingSpeak...");
Serial.println();
failedCounter = 0;
}
else
{
failedCounter++;
Serial.println("Connection to ThingSpeak failed ("+String(failedCounter, DEC)+")");
Serial.println();
}
}
else
{
failedCounter++;
Serial.println("Connection to ThingSpeak Failed ("+String(failedCounter, DEC)+")");
Serial.println();
lastConnectionTime = millis();
}
}
void startEthernet()
{
client.stop();
Serial.println("Connecting Arduino to network...");
Serial.println();
delay(1000);
// Connect to network amd obtain an IP address using DHCP
if (Ethernet.begin(mac) == 0)
{
Serial.println("DHCP Failed, reset Arduino to try again");
Serial.println();
}
else
{
Serial.println("Arduino connected to network using DHCP");
Serial.println();
}
delay(1000);
}

Anyone?