Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
35 views

Code

This document defines variables and functions to control a liquid crystal display (LCD), read sensor values for temperature, voltage, current and speed, and control a fan and LED based on the sensor readings. It initializes the LCD, sets up pins for sensors and outputs, takes continuous sensor readings in a loop, displays the values on the LCD and controls the fan and LED based on temperature thresholds.

Uploaded by

Soresa Jemal
Copyright
© © All Rights Reserved
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views

Code

This document defines variables and functions to control a liquid crystal display (LCD), read sensor values for temperature, voltage, current and speed, and control a fan and LED based on the sensor readings. It initializes the LCD, sets up pins for sensors and outputs, takes continuous sensor readings in a loop, displays the values on the LCD and controls the fan and LED based on temperature thresholds.

Uploaded by

Soresa Jemal
Copyright
© © All Rights Reserved
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 5

#include <LiquidCrystal.

h>

#include <SoftwareSerial.h>

// initialize the library with the numbers of the interface pins

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

//declare

variables float

VoltOut; float

SD; float I; float

tempC; float volt;

float curt; int

voltOut; float

speed; float D;

float current; float

T; float V; int

speedlPin; int

tempPin=4; int

fanSpeed; int

voltPin=1; int

temp; int

fanLCD;

int fan = 13; // the pin where fan is

int led = 8; // led pin

int curtPin=0; int

speed1Pin=2;

int tempMin = 20; // the temperature to start the fan


int tempMax = 35;// the maximum temperature when fan is at

100% int voltMax=250; int voltMin=100; float treshold=5; void

setup(){

// set up the LCD's number of columns and rows:

pinMode(fan, OUTPUT);

pinMode(led, OUTPUT);

lcd.begin(16, 4);

lcd.print("T=");

lcd.setCursor(0, 1);

lcd.print("V=");

lcd.setCursor(9, 0);

lcd.print("I=");

lcd.setCursor(9, 1);

lcd.print("S=");

Serial.begin(9600);

void loop()

{ int mytemp [5]; float

avrtemp=0; for (int

i=0; i<= 4; i++)

mytemp [i]=analogRead(tempPin);

delay(10);

avrtemp=(mytemp [0]+mytemp [1]+mytemp [2]+mytemp [3]+mytemp [4])/5;


tempC = (5*avrtemp*100)/1023;

T = analogRead(tempPin); //read the value from the sensor

V=

analogRead(voltPin); I=

analogRead(curtPin); int

myVolt [5]; float

avrVolt=0;

for (int i=0; i<= 4; i++)

myVolt [i]=analogRead(voltPin);

delay(10);

avrVolt=(myVolt [0]+myVolt [1]+myVolt [2]+myVolt [3]+myVolt [4])/5;

SD = analogRead(speedlPin);

VoltOut = (5*avrVolt*46)/1023;

curt= (5*I)/1023;

current=(5*I*4)/1023;

speed=(5*SD*15)/1023;

D=(5*SD)/1023;

// print result to lcd display

lcd.setCursor(2, 0);

lcd.print(tempC,1);lcd.print("C"); lcd.setCursor(11,

0); lcd.print(current,1);

lcd.print("A");

lcd.setCursor(2, 1); lcd.print(VoltOut,1);


lcd.print("V");

lcd.setCursor(11, 1);

lcd.print(speed,1);

lcd.print("rpm"); if(VoltOut>

230){ lcd.print("OVER

VOLTAGE "); delay(5);

if(current >16)

delay(5);

lcd.print(" OVER CURRENT "); delay(5);

if(tempC>tempMax)

delay(5);

lcd.print(" HIGH TEMPRATURE "); delay(5);

if(tempC < tempMin) { // if temp is lower than minimum temp

fanSpeed = 0; // fan is not spinning

digitalWrite(fan, LOW);

if((tempC >= tempMin) && (tempC <= tempMax)) { // if temperature is higher than

minimum temp

fanSpeed = map(tempC, tempMin, tempMax, 32, 255); // the actual speed of fan
fanLCD = map(tempC, tempMin, tempMax, 0, 100); // speed of fan to display on LCD

analogWrite(fan, fanSpeed); // spin the fan at the fanSpeed speed

if(tempC > tempMax) { // if temp is lower than minimum temp

fanSpeed = 0; // fan is not spinning

digitalWrite(fan, LOW);

}if(tempC > tempMax) { // if temp is higher than tempMax

digitalWrite(led, HIGH); // turn on led

} else { // else turn of led

digitalWrite(led, LOW);

if(speed >60){ lcd.print("the

speed over"); delay(5);

You might also like