Difference between revisions of "An external pressure sensor"

From phyphox
Jump to navigation Jump to search
(Created page with "{{Infobox Experiment | Name = An external pressure sensor | Category = Arduino library experiments | Sensors = Magentic Field }} Text Sensor =...")
 
Line 19: Line 19:
 
<pre>
 
<pre>
  
#include <phyphoxBle.h>  
+
#include <Wire.h>
 
+
#include "Adafruit_MPRLS.h"
int AnalogPin=27;
+
#include <phyphoxBle.h>
 
float Messwert;
 
float Messwert;
float Offset;
+
#define RESET_PIN -1
float Magnetfeld;
+
#define EOC_PIN -1
 
+
Adafruit_MPRLS mpr = Adafruit_MPRLS(RESET_PIN, EOC_PIN);
 
void setup() {
 
void setup() {
    PhyphoxBLE::start("Magnetfeldsensor_01");               //Start the BLE server
+
PhyphoxBLE::start("Barometer_01");
 
 
 
//Experiment
 
//Experiment
    PhyphoxBleExperiment experiment;
+
PhyphoxBleExperiment experiment;
 
+
experiment.setTitle("Barometer_01");
    experiment.setTitle("Magnetfeld");
+
experiment.setCategory("Arduino Experiments");
    experiment.setCategory("Arduino Experiments");
+
experiment.setDescription("Plot the pressure over time.");
    experiment.setDescription("Plot the magnetic field of a Hall sensor over time.");
+
//View
 
+
PhyphoxBleExperiment::View view;
    //View
+
//Value
    PhyphoxBleExperiment::View view;
+
PhyphoxBleExperiment::Value Value1;
 
+
Value1.setLabel("p = ");
    //Value
+
Value1.setUnit("hPa");
//    PhyphoxBleExperiment::Value Value1;    
+
Value1.setChannel(1);
//    Value1.setLabel("B = ");                          
+
//Graph
//    Value1.setUnit("mT");                    
+
PhyphoxBleExperiment::Graph graph;
//    Value1.setChannel(1);
+
graph.setLabel("Druck");
 
+
graph.setUnitX("s");
    //Graph
+
graph.setUnitY("hPa");
    PhyphoxBleExperiment::Graph graph;
+
graph.setLabelX("time");
    graph.setLabel("B over time");
+
graph.setLabelY("p");
    graph.setUnitX("s");
+
view.addElement(graph);
    graph.setUnitY("mT");
+
view.addElement(Value1);
    graph.setLabelX("time");
+
experiment.addView(view);
    graph.setLabelY("B");
+
PhyphoxBLE::addExperiment(experiment);
+
Serial.begin(38400);
    view.addElement(graph);                 //Attach graph to view
+
mpr.begin();
 
 
//    view.addElement(Value1);
 
    experiment.addView(view);               //Attach view to experiment
 
    PhyphoxBLE::addExperiment(experiment); //Attach experiment to server
 
 
 
//Offsetkorrektur 
 
  Offset=0;
 
  for(int i=0;i<7;i++){
 
    Offset+=analogRead(AnalogPin);
 
    delay(10);
 
  }
 
  Offset=Offset/7;
 
 
 
 
}
 
}
 
 
void loop() {
 
void loop() {
 
+
Messwert=0;
  Messwert=0;
+
for(int i=0;i<37;i++){
  for(int i=0;i<37;i++){
+
Messwert+=mpr.readPressure();
    Messwert+=analogRead(AnalogPin);
+
delay(10);
 +
}
 +
Messwert=Messwert/37;
 +
PhyphoxBLE::write(Messwert);
 +
Serial.println(Messwert);
 
delay(10);
 
delay(10);
  }
 
  Messwert=Messwert/37;
 
 
Magnetfeld=(Messwert-Offset)*(-0.0492);
 
PhyphoxBLE::write(Magnetfeld);
 
// delay(50);
 
 
}
 
}
 +
  
 
</pre>
 
</pre>

Revision as of 09:12, 25 August 2023

An external pressure sensor
Experiment An external pressure sensor
Category Arduino library experiments
Used sensors Magentic Field


Text

Sensor


Setup

Programmierung

Der ESP32 wird über die Arduino IDE programmiert. Es müssen die Definitionen für den ESP32 und die phyphox-Bibliothek installiert sein. Siehe dazu das Video unter Category: Arduino library experiments.

Es ist darauf zu achten, dass jeder ESP32 eine eigene Kennung hat (diese wird in PhyphoxBLE::start("Magnetfeldsensor_01") festgelegt). Anschließend kann über das Plus-Symbol in phyphox ein Bluetooth-Experiment hinzugefügt werden, das Experiment wird dann automatisch geladen.


#include <Wire.h>
#include "Adafruit_MPRLS.h"
#include <phyphoxBle.h>
float Messwert;
#define RESET_PIN -1
#define EOC_PIN -1
Adafruit_MPRLS mpr = Adafruit_MPRLS(RESET_PIN, EOC_PIN);
void setup() {
PhyphoxBLE::start("Barometer_01");
//Experiment
PhyphoxBleExperiment experiment;
experiment.setTitle("Barometer_01");
experiment.setCategory("Arduino Experiments");
experiment.setDescription("Plot the pressure over time.");
//View
PhyphoxBleExperiment::View view;
//Value
PhyphoxBleExperiment::Value Value1;
Value1.setLabel("p = ");
Value1.setUnit("hPa");
Value1.setChannel(1);
//Graph
PhyphoxBleExperiment::Graph graph;
graph.setLabel("Druck");
graph.setUnitX("s");
graph.setUnitY("hPa");
graph.setLabelX("time");
graph.setLabelY("p");
view.addElement(graph);
view.addElement(Value1);
experiment.addView(view);
PhyphoxBLE::addExperiment(experiment);
Serial.begin(38400);
mpr.begin();
}
void loop() {
Messwert=0;
for(int i=0;i<37;i++){
Messwert+=mpr.readPressure();
delay(10);
}
Messwert=Messwert/37;
PhyphoxBLE::write(Messwert);
Serial.println(Messwert);
delay(10);
}


Arbeitsmaterialien

Ein mögliches Schülerarbeitsblatt (aktuelle Sicherheitsrichtlinien nach RISU beachten!): File:AB Magnetfeldsensor Spule.pdf