Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
18 views5 pages

Final Code Maybe

Uploaded by

Surbhi Ambade
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views5 pages

Final Code Maybe

Uploaded by

Surbhi Ambade
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 5

Header Files

#include Wire.h
#include Adafruit_GFX.h
#include Adafruit_SSD1306.h
#include ESP8266WiFi.h
#include Adafruit_MLX90614.h
#include HX711.h

Variable Declaration
Temperature
Adafruit_MLX90614 mlx = Adafruit_MLX90614();
float maxf, maxc, tafa[15], taca[15],tafo[15],taco[15];

OLED
#define SCREEN_WIDTH 128 OLED display width, in pixels
#define SCREEN_HEIGHT 64 OLED display height, in pixels
#define OLED_RESET -1 Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
int ledPin=12;
int inputPin=2;

Weight
float calibration_factor = -4160; -7050 worked for my 440lb max scale setup
float wt;
#define LOADCELL_DOUT_PIN 15 d8
#define LOADCELL_SCK_PIN 0 d3
HX711 scale;

IR Sensor
int val=0;

US Sensor
const int trigP1 = 16; D0 Or GPIO-16 of nodemcu
const int echoP1= 14; D5 Or GPIO-14 of nodemcu
const int trigP2 = 13 ; D7
const int echoP2 = 12 ; D6
long duration;
float distance1, distance2, d[3][15], max1, max2, maxfo, maxco, maxca,
maxfa,finaldist[4];
int i=0, j,k=0,m,z=1; For Loops
int count=0;

void setup()
{

Serial.begin(9600);
delay(1000); wait a second
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); initialize with the I2C addr 0x3C
(128x64)
delay(2000);
pinMode(ledPin, OUTPUT);
pinMode(inputPin, INPUT);
Serial.println(Temperature sensor MLX90614);
pinMode(trigP1, OUTPUT); Sets the trigPin as an Output
pinMode(echoP1, INPUT); Sets the echoPin as an Input
pinMode(trigP2, OUTPUT); Sets the trigPin as an Output
pinMode(echoP2, INPUT); Sets the echoPin as an Input
mlx.begin();
Wire.begin(4,5);
scale.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN);
scale.set_scale();
scale.tare(); Reset the scale to 0
long zero_factor = scale.read_average(); Get a baseline reading
}

void loop()
{
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(15, 10);

val=digitalRead(inputPin);Reading IR Sensor Value

if(val==LOW) If Object Detected


{
if(z==1)
{
Serial.print(Vehicle Status);
display.clearDisplay();
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(0, 15);
display.println(VS Yes );
display.setCursor(5, 40);
Serial.println(Vehicle No MH 320870);
Serial.println(nDr. Jayesh Ruikar);
display.display();
z=0;
}

Reading Ultra Sonic Sensor

digitalWrite(trigP1, LOW); Makes trigPin low


delayMicroseconds(2); 2 micro second delay

digitalWrite(trigP1, HIGH); tigPin high


delayMicroseconds(10); trigPin high for 10 micro seconds
digitalWrite(trigP1, LOW); trigPin low

duration = pulseIn(echoP1, HIGH); Read echo pin, time in microseconds


distance1= duration0.0342; Calculating actualreal distance

digitalWrite(trigP2, LOW); Makes trigPin low


delayMicroseconds(2); 2 micro second delay

digitalWrite(trigP2, HIGH); tigPin high


delayMicroseconds(10); trigPin high for 10 micro seconds
digitalWrite(trigP2, LOW); trigPin low

duration = pulseIn(echoP2, HIGH); Read echo pin, time in microseconds


distance2= duration0.0342; Calculating actualreal distance

while(distance14 && distance24 && i10) Repeat the operation if distance is


less than 4
{
digitalWrite(trigP1, LOW); Makes trigPin low
delayMicroseconds(2); 2 micro second delay

digitalWrite(trigP1, HIGH); tigPin high


delayMicroseconds(10); trigPin high for 10 micro seconds
digitalWrite(trigP1, LOW); trigPin low

duration = pulseIn(echoP1, HIGH); Read echo pin, time in microseconds


d[1][i]= duration0.0342; Calculating actualreal distance

digitalWrite(trigP2, LOW); Makes trigPin low


delayMicroseconds(2); 2 micro second delay

digitalWrite(trigP2, HIGH); tigPin high


delayMicroseconds(10); trigPin high for 10 micro seconds
digitalWrite(trigP2, LOW); trigPin low

duration = pulseIn(echoP2, HIGH); Read echo pin, time in microseconds


d[2][i]= duration0.0342; Calculating actualreal distance
tafa[i]= mlx.readAmbientTempF();
tafo[i]= mlx.readObjectTempF();
taca[i]= mlx.readAmbientTempC();
taco[i]= mlx.readObjectTempC();
i++;
delay(500);
}
while(distance14 && distance24 && i==10)
{

if(count==0)
{
max1=d[1][0];
for(j=1;j10;j++)
{
if(max1d[1][j])
max1=d[1][j];
}

Serial.print(Distance1 = );
Serial.println(max1);

max2=d[2][0];
for(j=1;j10;j++)
{
if(max2d[2][j])
max2=d[2][j];
}
Serial.print(Distance2 = );
Serial.println(max2);

if(max1max2)
{
finaldist[k]=max1;
}
else
{
finaldist[k]=max2;
}

Serial.print(Distance Tyre= );
m=k;
Serial.print(m+1);
Serial.print( );
Serial.println(finaldist[k]);

k++;
Temperature
maxfo=tafo[0];
for(j=1;j10;j++)
{
if(maxfotafo[j])
maxfo=tafo[j];
}
maxfa=tafa[0];
for(j=1;j10;j++)
{
if(maxfatafa[j])
maxfa=tafa[j];
}
Serial.print(Ambient = );
Serial.print(maxfa);
Serial.print(FtObject = );
Serial.print(maxfo);
Serial.println(F);

maxca=taca[0];
for(j=1;j10;j++)
{
if(maxcataca[j])
maxca=taca[j];
}
maxco=taco[0];
for(j=1;j10;j++)
{
if(maxcotaco[j])
maxco=taco[j];
}

Serial.print(Ambient = );
Serial.print(maxca);
Serial.print(Tyre Temperature = );
Serial.print(k);
Serial.print( );
Serial.print(maxco);
Serial.println(C);
count=1;
i=i+1;

Weight Calculation
scale.set_scale(calibration_factor); Adjust to this calibration factor
Serial.print(Weight1 );
wt=scale.get_units();
Serial.println(wt);

Serial.print( kg); Change this to kg and re-adjust the calibration factor


if you follow SI units like a sane person
}

}
if(distance1 6 && distance26)
{
i=0;
count=0;
}
}
else
{
digitalWrite(ledPin, HIGH);
if(z==0)
{
display.clearDisplay();
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(0, 15);
display.print(VS No);
display.setCursor(5, 40);
Serial.println(VS No);
k=0;
z=1;
}
delay(1000);

}
delay(1000);
}

You might also like