How To DHT11 With DC Motor

Required Hardware

For users who do not have Hackerspace Karachi Arduino Kit v1.0

  • Arduino Board
  • Breadboard
  • L293D IC
  • DC motors
  • DHT11
  • Hook-up Wires

Circuit

For users who do not have Hackerspace Karachi Arduino Kit v1.0

Schematic

Code

                    

1. /*
2. DHT11 with DC motors
3.
4. This example shows how to use DHT11 with DC motors.
5.
6. The circuit:
7. – Motor 1 and 2
8. connected to output pins of driver IC
9.
10. -Driver IC
11. input and enable pins connected to digital pins of Arduino
12. – DHT11
13. connected to digital pin of Arduino
14.
15. http://hackerspacekarachi.org/
16. */
17. #include <dht11.h>
18. #define DHT11PIN 7 //connected to digital pin 7
19.
20. dht11 DHT11; //define type
21.
22. int motor1pin1 = 8; //input pin of Driver ic for 1st motor connected to digital pin 8
23. int motor1pin2 = 9; //input pin of Driver ic for 1st motor connected to digital pin 9
24. int enA = 5; //enable pin of Driver ic for 1st motor connected to digital pin 5
25.
26.
27. int motor2pin1 = 10; //input pin of Driver ic for 2nd motor connected to digital pin 10
28. int motor2pin2 = 11;//input pin of Driver ic for 2nd motor connected to digital pin 11
29. int enB = 6; //enable pin of Driver ic for 2nd motor connected to digital pin 6
30.
31.
32. void setup() {
33. Serial.begin(9600);// initializing serial
34. pinMode(motor1pin1, OUTPUT); //setting prins to be used as output
35. pinMode(motor1pin2, OUTPUT);
36. pinMode(motor2pin1, OUTPUT);
37. pinMode(motor2pin2, OUTPUT);
38. pinMode(enA, OUTPUT);
39. pinMode(enB, OUTPUT);
40. }
41.
42. void loop() {
43.
44. int chk = DHT11.read(DHT11PIN); //reading from the sensor
45. Serial.print(“Humidity (%): “); //printing results
46. Serial.print((float)DHT11.humidity, 2);
47. Serial.print(“Temperature (C): “);
48. Serial.println((float)DHT11.temperature, 2);
49.
50. delay(2000);
51. if (DHT11.temperature > 29)
52. {
53. digitalWrite(motor1pin1, HIGH); //for motor 1 to move in one direction
54. digitalWrite(motor1pin2, LOW);
55. digitalWrite(enA, HIGH);
56.
57. digitalWrite(motor2pin1, HIGH); //for motor 2 to move in one direction
58. digitalWrite(motor2pin2, LOW);
59. digitalWrite(enB, HIGH);
60. delay(1000);
61. }
62. }

1. /*