#include "DHT.h" #define DHTPIN 2 #define DHTTYPE DHT22 DHT dht(DHTPIN, DHTTYPE); #include #include LiquidCrystal_I2C lcd(0x27, 16, 2); #include Servo servo; #define servo1 3 int buzzer = 4; float h,t,f; float inductiveVal; float thickVal; const int analogPin = A0; const int samples = 8; // moving average samples (power of two) int buffer[samples]; int idx = 0; float calib_a = 0.005; // slope (mm per ADC unit) -- example placeholder float calib_b = -2.0; // intercept (mm) #define trig 8 #define echo 9 long duration, distance; float layo,thickness; void setup() { Serial.begin(9600); dht.begin(); servo.attach(servo1); servo.write(0); Serial.println("DHT22 Reading..."); lcd.init(); // Initialize LCD lcd.backlight(); // Turn on backlight lcd.setCursor(0, 0); lcd.print(" Welcome To"); lcd.setCursor(0, 1); lcd.print("AutomaticWelding"); delay(5000); pinMode(buzzer, OUTPUT); buzzMe(2); Serial.println("DHT22 Reading..."); pinMode(trig, OUTPUT); pinMode(echo, INPUT); } void loop() { //testDevice(); getTemp(); detectThickness(); //Conditions if (thickVal <=0 ) { servo.write(0); } else if (thickVal >= 1 && thickVal <= 3) { servo.write(120); }else if (thickVal >= 4 && thickVal <= 5) { servo.write(140); }else if (thickVal >= 6 && thickVal <= 8) { servo.write(160); }else if (thickVal >= 9 && thickVal <= 10) { servo.write(180); }else { servo.write(0); } displayLCD(); } void detectThickness(){ digitalWrite(trig, LOW); delayMicroseconds(2); digitalWrite(trig, HIGH); delayMicroseconds(10); digitalWrite(trig, LOW); // read echo duration = pulseIn(echo, HIGH); // convert to distance (cm) distance = duration * 0.034 / 2; Serial.print("Distance: "); Serial.print(distance); Serial.println(" cm"); thickVal = 10 - distance ; if(thickVal >= 50 || thickVal <=0 ){ thickVal = 0; } delay(200); } /// ========================================================= void buzzMe(int x){ for (int i = 1; i <= x; i++) { digitalWrite(buzzer, HIGH); // turn ON delay(500); digitalWrite(buzzer, LOW); // turn OFF delay(500); } } void getTemp(){ h = dht.readHumidity(); t = dht.readTemperature(); // Celsius f = dht.readTemperature(true); // Fahrenheit // Check if readings are valid if (isnan(h) || isnan(t)) { Serial.println("Failed to read from DHT22!"); return; } Serial.print("Humidity: "); Serial.print(h); Serial.print(" % | "); Serial.print("Temperature: "); Serial.print(t); Serial.print(" °C | "); Serial.print(f); Serial.println(" °F"); delay(1000); // DHT22 reads every 2 seconds } void displayLCD(){ lcd.clear(); lcd.setCursor(0, 0); lcd.print(t); lcd.print("C "); lcd.print(f); lcd.setCursor(0, 1); lcd.print("Thickness:"); lcd.print(thickVal); } void testDevice(){ servo.write(0); delay(3000); servo.write(180); delay(3000); //buzzMe(3); // inductiveVal = analogRead(analogPin); // Serial.println(inductiveVal); //if(thickness >= 10 && ) { // //} }