Hi i need my code to be re written but i need it to have the same functioanlity but in a difffernet format thanks (its A

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

Hi i need my code to be re written but i need it to have the same functioanlity but in a difffernet format thanks (its A

Post by answerhappygod »

Hi i need my code to be re written but i need it to have the same functioanlity but in a difffernet format thanks (its Auroino)




#include <Adafruit_Sensor.h>

#include <DHT.h>
#include <DHT_U.h>

bool on = false;
bool alarmLEDON = true;
unsigned long msec = millis();
unsigned long onSec = millis();
int pollRate = 1000;

const byte DATA_MAX_SIZE = 32;
char data[DATA_MAX_SIZE]; // an array to store the received data

#define DHTPIN 3
#define DHTTYPE DHT11

DHT dht(DHTPIN, DHTTYPE);

void setup() {
Serial.begin(9600);
pinMode(2,INPUT); // Button input
pinMode(3, INPUT); // humidity + temp
pinMode(4, OUTPUT); // Temperature LED

dht.begin();
}

void loop() {
//on-off physical button
if (digitalRead(2) == HIGH && millis() > msec + 250) {
msec = millis();
on = !on;
}

if (Serial.available() > 0) {
char character;
character = (char) Serial.read();

switch (character) {
case 'o': on = true; break;
case 'i': on = false; break;
case 'p': alarmLEDON = true; break;
case 'l': alarmLEDON = false; break;
}
}

if (!on) {
digitalWrite(4, LOW);
digitalWrite(5, LOW);
return;
}

//code here
if (alarmLEDON) {
digitalWrite(4, HIGH);
} else {
digitalWrite(4, LOW);
}

if (millis() < onSec + pollRate) { return; }

onSec = millis();

//Light Sensor
int sensorValueLDR = analogRead(A5);
String sensorLabelLDR = "light:";
String sensorResultLDR = sensorLabelLDR + sensorValueLDR + ";";
Serial.print(sensorResultLDR);

//Moisture Monitor
int sensorValueMM = analogRead(A4);
String sensorLabelMM = "moisture:";
String sensorResultMM = sensorLabelMM + sensorValueMM + ";";
Serial.print(sensorResultMM);

// Humidity / Temperature Sensor
float humidity = dht.readHumidity();
float temperatureC = dht.readTemperature();
float temperatureF = dht.readTemperature(true);
float feelsLikeF = dht.computeHeatIndex(temperatureF, humidity);
float feelsLikeC = dht.computeHeatIndex(temperatureC, humidity, false);

String outputDHT = "DHT:";
outputDHT.concat(humidity);
outputDHT.concat(",");
outputDHT.concat(temperatureC);
outputDHT.concat(",");
outputDHT.concat(temperatureF);
outputDHT.concat(",");
outputDHT.concat(feelsLikeF);
outputDHT.concat(",");
outputDHT.concat(feelsLikeC);

Serial.println(outputDHT);
}
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply