31-01-2021, 18:02
Witam!
Odświeżę temat choć może trochę inny.
Do solar trackera chcę dobudować anemometr z przekaźnikiem , który po przekroczeniu ustawionego progu wiatru załączy wypłaszczenie baterii PV.
Użyłem gotowego kodu dla anemometru z czujnikiem Halla, dopisałem komendę dla załączenia przekaźnika ale nie potrafię wstawić czasu zwłoki wyłączenia przekaźnika po tym jak wiatr ustanie.
Proszę Was o pomoc.
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);
#define am 8 //anemometer is connected to pin 8 with pulldown resistor
int pinOut = 10;
int cnt = 0; //counter
int rot = 0; // number of rotations
boolean stan = 0; //state of anemometer -open or closed
float wind;
void setup() {
pinMode (am, INPUT);
pinMode(10, OUTPUT);
Serial.begin(9600);
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.clearDisplay();
}
void loop() {
cnt = cnt + 1;
if (digitalRead(am) == LOW) { //I've checked that on free position anemometer is always closed
delay(2);
stan = !stan;
while (digitalRead(am) == LOW) ;
rot = rot + 1 ;
}
if (cnt == 100) {
int czas1 = millis();
wind = rot * 2.40114; ///5; //equation calculating average speed of the wind in 3 sec intervals
Serial.println(rot);
Serial.print("WIATR = ");
Serial.print(wind, 2);
Serial.println(" km/h");
cnt = 0; //counter reset
rot = 0; //rotation number reset
display.clearDisplay();
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(30, 0);
display.println("WIATR");
display.setTextSize(2);
display.setCursor(2, 15);
display.print(wind, 2);
display.setTextSize(2);
display.println(" km/h");
display.display();
int czas2 = millis();
int czas = czas2 - czas1;
Serial.println(czas);
}
if (wind > 6) {
digitalWrite (10, HIGH); // załączenie przekaźnika po przekroczeniu progu nastawionego wiatru
}
else
{
digitalWrite (10, LOW); // wyłaczenie przekaźnika po spadku siły wiatru
}
delay(8);//elay is put here to extend time of whole loop to 10ms
}
Odświeżę temat choć może trochę inny.
Do solar trackera chcę dobudować anemometr z przekaźnikiem , który po przekroczeniu ustawionego progu wiatru załączy wypłaszczenie baterii PV.
Użyłem gotowego kodu dla anemometru z czujnikiem Halla, dopisałem komendę dla załączenia przekaźnika ale nie potrafię wstawić czasu zwłoki wyłączenia przekaźnika po tym jak wiatr ustanie.
Proszę Was o pomoc.
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);
#define am 8 //anemometer is connected to pin 8 with pulldown resistor
int pinOut = 10;
int cnt = 0; //counter
int rot = 0; // number of rotations
boolean stan = 0; //state of anemometer -open or closed
float wind;
void setup() {
pinMode (am, INPUT);
pinMode(10, OUTPUT);
Serial.begin(9600);
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.clearDisplay();
}
void loop() {
cnt = cnt + 1;
if (digitalRead(am) == LOW) { //I've checked that on free position anemometer is always closed
delay(2);
stan = !stan;
while (digitalRead(am) == LOW) ;
rot = rot + 1 ;
}
if (cnt == 100) {
int czas1 = millis();
wind = rot * 2.40114; ///5; //equation calculating average speed of the wind in 3 sec intervals
Serial.println(rot);
Serial.print("WIATR = ");
Serial.print(wind, 2);
Serial.println(" km/h");
cnt = 0; //counter reset
rot = 0; //rotation number reset
display.clearDisplay();
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(30, 0);
display.println("WIATR");
display.setTextSize(2);
display.setCursor(2, 15);
display.print(wind, 2);
display.setTextSize(2);
display.println(" km/h");
display.display();
int czas2 = millis();
int czas = czas2 - czas1;
Serial.println(czas);
}
if (wind > 6) {
digitalWrite (10, HIGH); // załączenie przekaźnika po przekroczeniu progu nastawionego wiatru
}
else
{
digitalWrite (10, LOW); // wyłaczenie przekaźnika po spadku siły wiatru
}
delay(8);//elay is put here to extend time of whole loop to 10ms
}