Problem coding L2n8 with Arduino mega

hi there…!
i m trying to interface four dc motors with Aurdino Mega2560 using L298 motor driver and two dht11 sensors for bidirectional movements. i just need to know how to interface two L298 drivers with Ardiuno mega2560.

Here is my code for two motors with a single Dht11 and a single L298 driver Interfaced with Arduino Mega 2560.

const int hot = 25; //set hot parameter
const int cold = 26; //set cold parameter
#include <DHT.h> // including the library
#define DHTPIN 11 
#define DHTTYPE DHT11// defining the dht pin
  
// defining enable and input pins of L298 driver
#define enA 5
#define enB 6
#define in1 7
#define in2 8
#define in3 9
#define in4 10

DHT dht (DHTPIN, DHTTYPE);

 void setup ( ) {

  pinMode(enA, OUTPUT);
  pinMode(enB, OUTPUT);
  pinMode(in1, OUTPUT);
  pinMode(in2, OUTPUT);
  pinMode(in3, OUTPUT);
  pinMode(in4, OUTPUT);
                                     
  digitalWrite(in1, LOW);
  digitalWrite(in2, LOW);
  digitalWrite(in3, LOW);
  digitalWrite(in4, LOW);
  
   Serial.begin ( 9600 ) ;
   
   dht.begin (  ) ;
 }
 void loop ( ) { 

  float temp = dht.readTemperature ( ) ; 
  
     Serial.print ( " Temp is " ) ;  
     Serial.print ( temp ) ;         
     Serial.println ( " *C " ) ;
            
     if (temp < cold) {
                                      //i want to run both moters attached to a driver run in the same direction
    digitalWrite(enA,HIGH);
    digitalWrite(enB,HIGH);
    digitalWrite(in1, HIGH);
    digitalWrite(in2, LOW);
    digitalWrite(in3, HIGH);
    digitalWrite(in4, LOW);
    
    Serial.println(" It's Cold."); 
}
     else if (temp > hot) { //hot
      
    digitalWrite(enA,HIGH);
    digitalWrite(enB,HIGH);
    digitalWrite(in1, LOW);
    digitalWrite(in2, HIGH);
    digitalWrite(in3, LOW);
    digitalWrite(in4, HIGH);
    
    
    Serial.println(" It's Hot.");  
}

else { //fine

Serial.println(" It's Fine."); 
                                                           
 }
     Serial.print ( " Temp is " ) ;  
     Serial.print ( temp ) ;         
     Serial.println ( " *C " ) ;
            
 }

can any one please help me with coding two drivers in a same code of arduino?

DHT dht (DHTPIN, DHTTYPE);

Creates an instance of the DHT object named dht

DHT dht1 (DHTPIN1, DHTTYPE);
DHT dht2 (DHTPIN2, DHTTYPE);

would create 2 instances of the DHT object named dht1 and dht2. Note that you will need to #define both of the pin numbers before you can do this.

Later in the code use each of the two objects as you would use a single one. You could also create a two element array of DHT objects but I suggest that you do not do this initially

As to the motor drivers, simply add more #defines for the pin numbers and use them but please give them sensible names that indicate which motor driver they relate to.

Can you plz explain code for two l298 drivers with same arduino.

Mazhar535: Can you plz explain code for two l298 drivers with same arduino.

See reply #1

add more #defines for the pin numbers and use them but please give them sensible names that indicate which motor driver they relate to.

Something like

// defining enable and input pins of L298 driver
#define rightMotorenA 5
#define rightMotorenB 6
#define rightMotorin1 7
#define rightMotorin2 8
#define rightMotorin3 9
#define rightMotorin4 10

#define leftMotorenA 11
#define leftMotorrenB 12
#define leftMotorin1 13
#define leftMotorin2 A0
#define leftMotorin3 A1
#define leftMotorin4 A2

Make sure to choose pin numbers that are not used elsewhere in your program.

Hi, Welcome to the forum.

Please read the first post in any forum entitled how to use this forum. http://forum.arduino.cc/index.php/topic,148850.0.html

Can you tell us or post a picture of your motor driver please?

Can you please post a copy of your circuit as it is with one DHT and one motor driver, in CAD or a picture of a hand drawn circuit in jpg, png?

How are you powering your project?

What motors are you using?

Thanks.. Tom.. :)