Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
1.4 kB
3
Indexable
Never
#include <SoftwareSerial.h>
SoftwareSerial bluetooth(6, 7); //RX, TX
//Zolty 7
//Zielony 6

int sensorPin=A0;
int sensorData;
const int diodaZielona = 3;
const int diodaZolta = 4;
const int diodaCzerwona = 5;
const int wentylator = 9;

//300 sredni
//700 wysoki

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600); 
  bluetooth.begin(9600); 
  pinMode(sensorPin, INPUT);
  pinMode(diodaZielona, OUTPUT);
  pinMode(diodaZolta, OUTPUT);
  pinMode(diodaCzerwona, OUTPUT);
  pinMode(wentylator, OUTPUT);
  analogWrite(wentylator, 0);
  delay(6000);
}

void loop() {
  // put your main code here, to run repeatedly:
  sensorData = analogRead(sensorPin);
  Serial.println(sensorData);
  bluetooth.println(sensorData);
  if (sensorData <= 300) {
    digitalWrite(diodaZielona, HIGH);
    digitalWrite(diodaZolta, LOW);
    digitalWrite(diodaCzerwona, LOW);
    analogWrite(wentylator, 0);
  }
  else if (sensorData > 300 && sensorData <= 700) {
    digitalWrite(diodaZielona, LOW);
    digitalWrite(diodaZolta, HIGH);
    digitalWrite(diodaCzerwona, LOW);
    analogWrite(wentylator, 0);
  }
  else if (sensorData > 700) {
    digitalWrite(diodaZielona, LOW);
    digitalWrite(diodaZolta, LOW);
    digitalWrite(diodaCzerwona, HIGH);
    analogWrite(wentylator, 255);
  }

  delay(2000);
}
Leave a Comment