My project is based on a moving fan using dht11 sensors.I have used 2 void loops and the IDE is showing an error "exit status 1 redefinition of 'void loop()'"
One doubt:Can we use 2 void loops in the code.Please see and identify the errors.
#include <DHT.h>
#include <DHT_U.h>
#include <Adafruit_Sensor.h>
// Including library for dht
#include<LiquidCrystal.h>
LiquidCrystal lcd(2, 3, 4, 5, 6, 7);
#define dht_dpin 12
int DHT;
#define pwm 9
void setup() {
// put your setup code here, to run once:
}
void loop() {
// put your main code here, to run repeatedly:
// put your setup code here, to run once:
lcd.begin(16, 2);
lcd.clear();
lcd.print(" Fan Speed");
lcd.setCursor(0,1);
lcd.print(" Controlling");
delay(2000);
analogWrite(pwm, 255);
lcd.clear();
lcd.print("Circuit Digest ");
delay(2000);}
void loop(){
DHT.read11(dht_dpin);
int temp=DHT.temperature;
lcd.setCursor(0,0);
lcd.print("Temperature:");
lcd.print(temp); // Printing temperature on LCD
lcd.print("oC");
lcd.setCursor(0,1);
if(temp <26 )
{
analogWrite(9,0);
lcd.print("Fan OFF");
delay(100);
}
else if(temp==26)
{
analogWrite(pwm, 51);
lcd.print("Fan Speed: 20%");
delay(100);
}
else if(temp==27)
{
analogWrite(pwm, 102);
lcd.print("Fan Speed: 40%");
delay(100);
}
else if(temp==28)
{
analogWrite(pwm, 153);
lcd.print("Fan Speed: 60%");
delay(100);
}
else if(temp==29)
{
analogWrite(pwm, 204);
lcd.print("Fan Speed: 80%");
delay(100);
}
else if(temp>29)
{
analogWrite(pwm, 255);
lcd.print("Fan Speed: 100%");
delay(100);
}
delay(3000);
}
}