Hi!!
I am very new in arduino and in programming (I started 4 days ago ). And now I am trying to display the data from my thermistor (from sunfounder) and from my barometer (also from sunfounder BMP280) in the same way that a lot of people are doing: Easy Arduino Data Logging and Telemetry - YouTube . I manage to get the right codes for my thermistor and barometer separately but when I connect the two sensors in my arduino and try to do the same thing that is in the youtube video, It doesnt work entirely. I manege to get the temperature well, in celsius, but the pressure values are not shown in Pa. I cant understand why... Can someone help me with this, please?
Here are the individual codes for the thermistor and barometer:
Thermistor:
#include <Wire.h>
#define analogPin A0 //the thermistor attach to
#define beta 3950 //the beta of the thermistor
#define resistance 10 //the value of the pull-up resistor
void setup()
{
Serial.begin(9600);
}
void loop()
{
long a =1023 - analogRead(analogPin); //read thermistor value
//the calculating formula of temperature
float tempC = beta /(log((1025.0 * 10 / a - 10) / 10) + beta / 298.0) - 273.0;
Serial.println(tempC);
delay(1000); //wait for 100 milliseconds
}
Barometer:
/*
- bmp280_example.ino
- Example sketch for BMP280
- Copyright (c) 2016 seeed technology inc.
- Website : www.seeedstudio.com
- Author : Lambor, CHN
- Create Time:
- Change Log :
- The MIT License (MIT)
- Permission is hereby granted, free of charge, to any person obtaining a copy
- of this software and associated documentation files (the "Software"), to deal
- in the Software without restriction, including without limitation the rights
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- copies of the Software, and to permit persons to whom the Software is
- furnished to do so, subject to the following conditions:
- The above copyright notice and this permission notice shall be included in
- all copies or substantial portions of the Software.
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- THE SOFTWARE.
*/
#include "Seeed_BMP280.h"
#include <Wire.h>
BMP280 bmp280;
void setup()
{
Serial.begin(9600);
if(!bmp280.init()){
Serial.println("Device error!");
}
}
void loop()
{
float pressure;
//get and print atmospheric pressure data
Serial.print(bmp280.getPressure());
Serial.println("\n");//add a line between output of different times.
delay(1000);
}
My code following the youtube template to show the two graphs in java:
#include <Wire.h>
#include "Seeed_BMP280.h"
BMP280 bmp280;
#define analogPin A0 //the thermistor attach to
#define beta 3950 //the beta of the thermistor
#define resistance 10 //the value of the pull-up resistor
void setup() {
Serial.begin(9600);
if(!bmp280.init())
Serial.println("Device error!");
}
void loop() {
long a =1023 - analogRead(analogPin);
int sensor1 = beta /(log((1025.0 * 10 / a - 10) / 10) + beta / 298.0) - 273.0;
float c = (bmp280.getPressure());
int sensor2 = c;
char text [40];
sprintf (text, "%d, %d\n", sensor1, sensor2);
Serial.println (text);
delay(1000); //wait for 100 milliseconds
}
With that coding I get this:
25, -28643 (as an example)
Again, the temperature is fine, but I cant understand why the pressure isnt in the correct units...
Can someone help me?
Cheers!!