Input from dht11: pin8 #define dhtpin 8


Download 0.51 Mb.
Sana28.12.2022
Hajmi0.51 Mb.
#1010712
Bog'liq
code


[code]
// used libraries:
#include
#include "DHT.h"
#include
// input from DHT11: PIN8
#define DHTPIN 8
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
// initialize the buzzer: PIN10
int speakerPin = 10;
int length = 1;
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
dht.begin();
// Print a message to the LCD. Luft-F is german for humidity.
lcd.print("Temp: Luft-F:");
}
void loop() {
pinMode(speakerPin, OUTPUT);
delay(500);
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.setCursor(0, 1);
// read humidity
float h = dht.readHumidity();
//read temperature in Celsius
float c = dht.readTemperature();
if (isnan(h) || isnan(c)) {
lcd.print("ERROR");
return;
}
lcd.print(c);
lcd.setCursor(7,1);
lcd.print(h);
// i set the desired temp for testing purposes to 20-25
if (c<= 20) {
digitalWrite(speakerPin, HIGH);
delay (1000);
digitalWrite(speakerPin, LOW);
}
if (c>= 25) {
digitalWrite(speakerPin, HIGH);
delay (1000);
digitalWrite(speakerPin, LOW);
}
}
[/code]


2CHI KOD


// Include Libraries
#include "Arduino.h"
#include "DCMotor.h"
// Pin Definitions
#define DCMOTOR_PIN_COIL1 3


// Global variables and defines


// object initialization
DCMotor dcMotor(DCMOTOR_PIN_COIL1);
// define vars for testing menu
const int timeout = 10000; //define timeout of 10 sec
char menuOption = 0;
long time0;


// Setup the essentials for your circuit to work. It runs first every time your circuit is powered with electricity.
void setup()
{
// Setup Serial which is useful for debugging
// Use the Serial Monitor to view printed messages
Serial.begin(9600);
while (!Serial) ; // wait for serial port to connect. Needed for native USB
Serial.println("start");


menuOption = menu();

}


// Main logic of your circuit. It defines the interaction between the components you selected. After setup, it runs over and over again, in an eternal loop.
void loop()
{


if(menuOption == '1') {
// DC Motor - Hobby Motor Gear - Test Code
// The DC motor will turn on and off for 4000ms (4 sec)
dcMotor.on(200); // 1. turns on
delay(4000); // 2. waits 4000 milliseconds (4 sec). change the value in the brackets (4000) for a longer or shorter delay.
dcMotor.off(); // 3. turns off
delay(4000); // 4. waits 4000 milliseconds (4 sec). change the value in the brackets (4000) for a longer or shorter delay.


}

if (millis() - time0 > timeout)
{
menuOption = menu();
}

}


// Menu function for selecting the components to be tested
// Follow serial monitor for instrcutions
char menu()
{


Serial.println(F("\nWhich component would you like to test?"));
Serial.println(F("(1) DC Motor - Hobby Motor Gear"));
Serial.println(F("(menu) send anything else or press on board reset button\n"));
while (!Serial.available());


// Read data from serial monitor if received
while (Serial.available())
{
char c = Serial.read();
if (isAlphaNumeric(c))
{

if(c == '1')
Serial.println(F("Now Testing DC Motor - Hobby Motor Gear"));
else
{
Serial.println(F("illegal input!"));
return 0;
}
time0 = millis();
return c;
}
}
}

Download 0.51 Mb.

Do'stlaringiz bilan baham:




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling