//includere predirective
#include <AFMotor.h>
#include "DHT.h"
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <IRremote.h>
#include <NewTone.h>
//definire iR buttons
#define btnZero 39015
#define btnUnu 41565
#define btnDoi 25245
#define btnTrei 57885
#define btnPatru 8925
#define btnCinci 765
#define btnSase 49725
#define btnSapte 57375
#define btnOpt 43095
#define btnNoua 36975
#define btnUp 6375
#define btnDown 19125
#define btnLeft 4335
#define btnRight 23205
#define btnOk 14535
#define btnStea 26775
#define btnHash 45135
// sfarsit iRbuttons
int IR_PIN = A1;
#define DHTPIN 2
#define DHTTYPE DHT11
AF_DCMotor rightR_motor(4, MOTOR12_8KHZ);
AF_DCMotor leftF_motor(2, MOTOR12_8KHZ);
AF_DCMotor leftR_motor(3, MOTOR12_8KHZ);
AF_DCMotor rightF_motor(1, MOTOR12_8KHZ);
IRrecv irDetect(IR_PIN);
decode_results rezultat;
LiquidCrystal_I2C lcd = LiquidCrystal_I2C(0x3F, 16, 2);
DHT dht(DHTPIN, DHTTYPE);
int buzzer = 13;
int gaz = A0;
float slope = -0.318;
float y_intercept = 1.133;
float R0 = 11.820;
String readString;
void setup() {
rightR_motor.setSpeed(1000);
leftR_motor.setSpeed(1000);
rightF_motor.setSpeed(1000);
leftF_motor.setSpeed(1000);
lcd.init();
lcd.backlight();
dht.begin();
irDetect.enableIRIn();
pinMode(buzzer, OUTPUT);
pinMode(gaz, INPUT);
Serial.begin(9600);
}
void loop() {
while (Serial.available()) {
delay(5);
char c = Serial.read();
readString += c;
if (readString.length() > 0) {
Serial.println(readString);
if (readString == "F") {
rightF_motor.run (BACKWARD);
rightR_motor.run (BACKWARD);
leftF_motor.run (FORWARD);
leftR_motor.run (FORWARD);
}
if (readString == "B") {
rightF_motor.run (FORWARD);
rightR_motor.run (FORWARD);
leftF_motor.run (BACKWARD);
leftR_motor.run (BACKWARD);
}
if (readString == "R") {
rightF_motor.run (RELEASE);
rightR_motor.run (RELEASE);
leftF_motor.run (FORWARD);
leftR_motor.run (FORWARD);
}
if (readString == "L") {
rightF_motor.run (BACKWARD);
rightR_motor.run (BACKWARD);
leftF_motor.run (RELEASE);
leftR_motor.run (RELEASE);
}
if (readString == "S") {
rightF_motor.run (RELEASE);
rightR_motor.run (RELEASE);
leftF_motor.run (RELEASE);
leftR_motor.run (RELEASE);
}
if (readString == "V") {
NewTone(buzzer, 1000);
delay(500);
}
if (readString == "v") {
noNewTone(buzzer);
}
}
readString = "";
}
gasDetection();
int h = dht.readHumidity();
int t = dht.readTemperature() ;
int f = dht.readTemperature(true);
lcd.setCursor(0, 0); // Set the cursor on the first column and first row.
lcd.print("Temp: "); // Print the string "Hello World!"
lcd.print(t);
lcd.print(char(223));
lcd.print("C");
lcd.setCursor(0, 1); //Set the cursor on the third column and the second row (counting starts at 0!).
lcd.print("Umid: ");
lcd.print(h);
lcd.print("%");
} //end loop
void gasDetection() {
float sensor_voltage;
float RS_gas_resistance;
float ratio;
float sensorValue = analogRead(gaz);
sensor_voltage = sensorValue * (5.0 / 1023.0);
RS_gas_resistance = ((5.0 * 10.0) / sensor_voltage) - 10.0;
ratio = RS_gas_resistance / R0;
double ppm_log = (log10(ratio) - y_intercept) / slope;
double ppm = pow(10, ppm_log);
double percentage = ppm / 10000;
Serial.println(ppm);
if (ppm > 10) {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Detectie gaz! ");
lcd.setCursor(7, 1);
lcd.print("Con : ");
lcd.print(percentage);
lcd.print("%");
NewTone(buzzer, 500);
delay(1000);
}
else {
noNewTone();
}
}//end gasDetection
Using the code posted above, i encounter a strange problem.More exactly, one of the motors won;t run.
3 motors are running but the motor 1 does not spin . So.. my question is... does anyone know why(looking at the code- is there something that i don't observe>?
Thanks in advance