if my circuit has mistake please refer me the proper image.
#define pwm 6
void setup() {
// initialize serial communication at 9600 bits per second:
pinMode(6,OUTPUT);
Serial.begin(9600);
}
// the loop routine runs over and over again forever:
void loop() {
// read the input on analog pin 0:
int sensorValue = analogRead(A0);
//Serial.println(sensorValue);
// Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
float voltage = sensorValue * (5.0 / 1023.0);
//Serial.println(voltage);
float vol1=voltage*11;
Serial.print("convertd voltageg ");
Serial.println(vol1);
int s=0;
if (vol1>24){
float duty=(24)/(vol1);
Serial.print("Duty cycle ");
duty=duty*100;
Serial.println(duty);
s=map(duty,0,100,0,255);
Serial.print("maped values");
Serial.println(s);
analogWrite(6,s);}
else if(vol1>18 && vol1<25){
s=255;
analogWrite(6,s);
Serial.println(s);
}
//Serial.println(x);
}