XL MaxSonar EZL1MB1261 is a position a sensor The output vo
Solution
//Connect XL-Max Sonar - EZL1 / MB1261 position sensor and it gives voltage output according to position
//And we are connecting voltage pin of the sensor to the arduino analog pin - A1
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup()
{
Serial.begin(9600);
dht.begin();
lcd.begin(16,2);
lcd.clear();
}
void loop()
{
float Analog_Read = analogRead(A1);
float Analog_Voltage = Analog_Read*5.0/1023.0;
//Used Two point lineary equcation
// Given slope = Change in op/Change in ip = 2/(4.9*10^-3) = 408.163265306
// So y - y0 = slope * (x - x0)
// y - 2 = 408.163265306 * (Analog_Voltage - 0.0049)
float Sensor_Value = 2 + (408.163265306 * (Analog_Voltage - 0.0049));
lcd.setCursor(0,1);
lcd.print(\"PositionSensor\");
lcd.setCursor(1,1);
lcd.print(\"Position = \",);
lcd.setCursor(1,12);
lcd.print(Sensor_Value);
}
