0% found this document useful (0 votes)
33 views4 pages

Mikrokontroler

The document contains details of an assignment to create a program using an I2C flow sensor. The program is to display the measured liter amount from 0-50 liters, light different LED indicators based on the measured amount, and communicate the data over a serial connection. The code provided implements this by initializing pins and variables, measuring the pulse count from the sensor to calculate flow rate and amount, lighting the appropriate LED, and printing the output over serial.

Uploaded by

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

Mikrokontroler

The document contains details of an assignment to create a program using an I2C flow sensor. The program is to display the measured liter amount from 0-50 liters, light different LED indicators based on the measured amount, and communicate the data over a serial connection. The code provided implements this by initializing pins and variables, measuring the pulse count from the sensor to calculate flow rate and amount, lighting the appropriate LED, and printing the output over serial.

Uploaded by

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

Nama : Muhammad Rozaq Mukhtiar

NIM : 03041381621066

Jurusan : Teknik Elektro Universitas Sriwijaya Kampus Palembang

UAS MIKROKONTROLER
Soal:

11. Buatlah rangkaian program dan perhitungannya menggunakan sensor flow dengan komunikasi I2C.

 Tampilkan data jumlah liter > 0 kg sampai dengan 50 liter menggunakan Hyperterminal/
komputer
 Indicator LED 1 menyala dan LED yang lain padam jika liter dari > 0 liter sampai dengan 20 liter
 Indicator LED 2 menyalada dan LED yang lain padam jika liter dari > 21 liter sampai dengan 40
liter
 Indicator LED 3 menyala dan LED yang lain padam jika liter dari > 40 liter sampai dengan 50
liter

byte led1 = 11;

byte led2 = 12;

byte led3 = 13;


byte sensorInterrupt = 2;

byte sensorPin = 3;

float calibrationFactor = 4.5;

volatile byte pulseCount;

float flowRate;

unsigned int flowMilliLitres;

unsigned long totalMilliLitres;

unsigned long oldTime;

void setup()

Serial.begin(38400);

pinMode(led1, OUTPUT);

digitalWrite(led1, LOW);

pinMode(led2, OUTPUT);

digitalWrite(led2, LOW);

pinMode(led3, OUTPUT);

digitalWrite(led3, LOW);

pinMode(sensorPin, INPUT);

digitalWrite(sensorPin, HIGH);

pulseCount = 0;

flowRate = 0.0;

flowMilliLitres = 0;

totalMilliLitres = 0;

oldTime = 0;

attachInterrupt(sensorInterrupt, pulseCounter, FALLING);


}

void loop()

if((millis() - oldTime) > 1000)

detachInterrupt(sensorInterrupt);

flowRate = ((1000.0 / (millis() - oldTime)) * pulseCount) / calibrationFactor;

oldTime = millis();

flowMilliLitres = (flowRate / 60) * 1000;

totalMilliLitres += flowMilliLitres;

unsigned int frac;

frac = (flowRate - int(flowRate)) * 10;

if (frac < 50000){

Serial.print(frac, DEC) ;

Serial.print("L/min");

pulseCount = 0;

attachInterrupt(sensorInterrupt, pulseCounter, FALLING);

digitalWrite(led3, HIGH);

digitalWrite(led2, LOW);

digitalWrite(led1, LOW);}

else if (frac < 40000){

Serial.print(frac, DEC) ;

Serial.print("L/min");
pulseCount = 0;

attachInterrupt(sensorInterrupt, pulseCounter, FALLING);

digitalWrite(led3, LOW);

digitalWrite(led2, HIGH);

digitalWrite(led1, LOW);}

else if (frac < 20000){

Serial.print(frac, DEC) ;

Serial.print("L/min");

pulseCount = 0;

attachInterrupt(sensorInterrupt, pulseCounter, FALLING);

digitalWrite(led3, LOW);

digitalWrite(led2, LOW);

digitalWrite(led1, HIGH);}

void pulseCounter()

pulseCount++;

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy