GMU:Designing Utopias: Theory and Practice/Mavie Beisheim

From Medien Wiki
< GMU:Designing Utopias: Theory and Practice
Revision as of 16:43, 29 November 2022 by Mavie (talk | contribs) (Created page with " == '''Flammensensor mit Arduino UNO benutzen''' == '''Was wird benötigt?''' 400px '''Anschlüsse:''' Arduino UNO - Flammensensor G...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Flammensensor mit Arduino UNO benutzen

Was wird benötigt?


Zubehör.png



Anschlüsse:

Arduino UNO - Flammensensor

GND - GND
5V - VCC
A0 - A0



Code:


Code komplett.png



// lowest and highest sensor readings:
const int sensorMin = 0;     // sensor minimum
const int sensorMax = 1024;  // sensor maximum
void setup() {
 // initialize serial communication @ 9600 baud:
 Serial.begin(9600);  
 // initialize digital pin LED_BUILTIN as an output.
 pinMode(LED_BUILTIN, OUTPUT);
 }

void loop()
 // read the sensor on analog A0:
 {int sensorReading = analogRead(A0);
 // map the sensor range (four options):
 // ex: 'long int map(long int, long int, long int, long int, long int)'
 int range = map(sensorReading, sensorMin, sensorMax, 0, 3);
 
 
 // range value:
 switch (range) {
 case 1:    // A fire closer than 5cm away.
   Serial.println("Close Fire");
   digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
   delay(1000); // wait for a second
   break;
 case 2:    // No fire detected.
   Serial.println("No Fire");
   digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
   delay(1000); // wait for a second
   break;
 }
}




Ergebnis:


LED ist aus, wenn keine Flamme in der Nähe ist und man sieht "No Fire" auf dem Bildschirm.


Ohne Flamme.png


No Fire.png



LED ist an, wenn eine Flamme in der Nähe ist und auf dem Bildschirm erscheint "Close Fire".


Mit Flamme.png


Close Fire.png