0% found this document useful (0 votes)
52 views8 pages

Colegio de San Juan de Letran - Calamba: Bo. Bucal Calamba City, Laguna

This document describes an Arduino project that controls a fan speed based on temperature readings from an LM34 temperature sensor. The project uses an LCD display to show the current temperature, fan speed, and status. It defines macros for pins, temperature ranges, and fan speeds. The source code initializes the LCD, takes temperature readings, determines the appropriate fan speed based on temperature ranges, displays the status, and fades the fan speed using PWM.

Uploaded by

ELLAINE DE CLARO
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)
52 views8 pages

Colegio de San Juan de Letran - Calamba: Bo. Bucal Calamba City, Laguna

This document describes an Arduino project that controls a fan speed based on temperature readings from an LM34 temperature sensor. The project uses an LCD display to show the current temperature, fan speed, and status. It defines macros for pins, temperature ranges, and fan speeds. The source code initializes the LCD, takes temperature readings, determines the appropriate fan speed based on temperature ranges, displays the status, and fades the fan speed using PWM.

Uploaded by

ELLAINE DE CLARO
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/ 8

Colegio De San Juan De Letran - Calamba

Bo. Bucal Calamba City, Laguna

School of Engineering and Architecture

MICRO131L: Microprocessor Systems Lab

Servo and Stepper Motor in Arduino Board


Assignment No. 2

Grade

Group Number : EE3 Signature


Group Leader : CUNANAN, Denier, J. ______________
Members : DACUBA, Mark Bryan, R. ______________
BAUTISTA, Jan Rettely, C. ______________

Date Performed: Dec. 5, 2019


Date Submitted: Dec. 7, 2019

Engr. Ricrey E. Marquez, CpE, MSCS


(Lab Instructor)
A.Header File – Assignment_2.h

#include <SoftPWM.h>
#include <SoftPWM_timer.h>

#define LM34_OUT (A0)


#define MAX_ADC (1024.0)
#define REF_VOLT (5000)
//5V = 5000mV
#define GET_MVOLT (raw_voltage / MAX_ADC) * REF_VOLT
//1mV/0.1 = 10
#define MVOLT_TO_FAHR milli_volts / 10
#define FAHR_TO_CELC (fahr_temp - 32) * (5.0 / 9.0)
#define BAUD_RATE (9600)
#define SHORT_DEL delay(500)
#define LONG_DEL delay(1000)
//macro for LCD module
#define ROWS (4)
#define COLS (20)
#define RS (12)
#define EN (11)
#define D4 (5)
#define D5 (4)
#define D6 (3)
#define D7 (2)
#define FAN (13)
//macro for LCD coordinates
#define ROW1 (0)
#define ROW2 (1)
#define ROW3 (2)
#define ROW4 (3)
#define COL0 (0)
#define COL1 (6)
#define COL2 (6)
#define COL3 (3)
#define COL4 (2)
#define COL3A (11)
//macro for speed of fan
#define MIN_FS (0)
#define MAX_FS (11)
#define FANSPEED0 (0)
#define FANSPEED1 (1)
#define FANSPEED2 (2)
#define FANSPEED3 (3)
#define FANSPEED4 (4)
#define FANSPEED5 (5)
#define FANSPEED6 (6)
#define FANSPEED7 (7)
#define FANSPEED8 (8)
#define FANSPEED9 (9)
#define FANSPEED10 (10)
//macro for temperature range
#define TEMPRA1_MIN (-4)
#define TEMPRA1_MAX (10)
#define TEMPRA2_MIN (11)
#define TEMPRA2_MAX (25)
#define TEMPRA3_MIN (26)
#define TEMPRA3_MAX (40)
#define TEMPRA4_MIN (41)
#define TEMPRA4_MAX (55)
#define TEMPRA5_MIN (56)
#define TEMPRA5_MAX (70)
#define TEMPRA6_MIN (71)
#define TEMPRA6_MAX (85)
#define TEMPRA7_MIN (86)
#define TEMPRA7_MAX (100)
#define TEMPRA8_MIN (101)
#define TEMPRA8_MAX (115)
#define TEMPRA9_MIN (116)
#define TEMPRA9_MAX (130)
//macro declaration for clone PWM pin
#define CLONE_SERVO_PIN (13)
#define FADEUP_TIME (100)
#define FADEDOWN_TIME (500)
#define PWM_EN (0)
//macro for PWM duty cycle value
#define MAX_SPEED (100)
#define MIN_SPEED (0)
#define SET_DELAY (100)
//initialize LCD library

B. Source file – ASSIGNMENT_FAN.ino

#include <LiquidCrystal.h>
#include “Assignment_2.h”

int fanspeed;
int fanLCD;

//instantiate LCD object


LiquidCrystal MyTemp_LCD(RS, EN, D4, D5, D6, D7);
void setup()
{
// initialize/create clone PWM pin
SoftPWMBegin();
//create and set pin 13 to 0 (off digital IO and enable PWM)
SoftPWMSet(CLONE_SERVO_PIN, PWM_EN); //(13, 0)
500 ms fade-
//Set fade time for pin 13 to 100 ms fade-up time, and
down time
SoftPWMSetFadeTime(CLONE_SERVO_PIN, FADEUP_TIME,
FADEDOWN_TIME);
//initialize LCD rows and cols
MyTemp_LCD.begin(COLS, ROWS);
//clear LCD text display
MyTemp_LCD.clear();
initial_device();
pinMode(LM34_OUT, INPUT);
pinMode(CLONE_SERVO_PIN, OUTPUT);
}
void loop()
{
//declare a static int variable for motor_speed
static int motor_speed, fan_speed_status;

int raw_voltage= analogRead(LM34_OUT);

float milli_volts = GET_MVOLT;


float fahr_temp = MVOLT_TO_FAHR;
float cel_temp = FAHR_TO_CELC;
display_temp(fahr_temp, cel_temp);
if ( cel_temp <= TEMPRA1_MIN )
{
motor_speed = cel_temp;
motor_speed = constrain(motor_speed, MIN_SPEED,
MAX_SPEED);
fanLCD = FANSPEED0;
analogWrite(FAN, motor_speed);
}

else if ( cel_temp >= TEMPRA1_MIN && cel_temp <=


TEMPRA1_MAX)
{
motor_speed = cel_temp;
motor_speed = constrain(motor_speed, MIN_SPEED,
MAX_SPEED);
fanLCD = FANSPEED1;
analogWrite(FAN, motor_speed);
}

else if ( cel_temp >= TEMPRA2_MIN && cel_temp <=


TEMPRA2_MAX)
{
motor_speed = cel_temp;
motor_speed = constrain(motor_speed, MIN_SPEED,
MAX_SPEED);
fanLCD = FANSPEED2;
analogWrite(FAN, motor_speed);
}

else if ( cel_temp >= TEMPRA3_MIN && cel_temp <=


TEMPRA3_MAX)
{
motor_speed = motor_speed;
motor_speed = constrain(motor_speed, MIN_SPEED,
MAX_SPEED);
fanLCD = FANSPEED3;
analogWrite(FAN, motor_speed);
}

else if ( cel_temp >= TEMPRA4_MIN && cel_temp <=


TEMPRA4_MAX)
{
motor_speed = cel_temp;
motor_speed = constrain(motor_speed, MIN_SPEED,
MAX_SPEED);
fanLCD = FANSPEED4;
analogWrite(FAN, motor_speed);
}

else if ( cel_temp >= TEMPRA5_MIN && cel_temp <=


TEMPRA5_MAX)
{
motor_speed = cel_temp;
motor_speed = constrain(motor_speed, MIN_SPEED,
MAX_SPEED);
fanLCD = FANSPEED5;
analogWrite(FAN, motor_speed);
}

else if ( cel_temp >= TEMPRA6_MIN && cel_temp <=


TEMPRA6_MAX)
{
motor_speed = cel_temp;
motor_speed = constrain(motor_speed, MIN_SPEED,
MAX_SPEED);
fanLCD = FANSPEED6;
analogWrite(FAN, motor_speed);
}
else if ( cel_temp >= TEMPRA7_MIN && cel_temp <=
TEMPRA7_MAX)
{
motor_speed = cel_temp;
motor_speed = constrain(motor_speed, MIN_SPEED,
MAX_SPEED);
fanLCD = FANSPEED7;
analogWrite(FAN, motor_speed);
}
else if ( cel_temp >= TEMPRA8_MIN && cel_temp <=
TEMPRA8_MAX )
{
motor_speed = cel_temp;
motor_speed = constrain(motor_speed, MIN_SPEED,
MAX_SPEED);
fanLCD = FANSPEED8;
analogWrite(FAN, motor_speed);
}
else if ( cel_temp >= TEMPRA9_MIN && cel_temp <=
TEMPRA9_MAX)
{
motor_speed = cel_temp;
motor_speed = constrain(motor_speed, MIN_SPEED,
MAX_SPEED);
fanLCD = FANSPEED9;
analogWrite(FAN, motor_speed);
}
else if ( cel_temp >= TEMPRA4_MAX)
{
motor_speed = cel_temp;
motor_speed = constrain(motor_speed, MIN_SPEED,
MAX_SPEED);
fanLCD = FANSPEED10;
analogWrite(FAN, motor_speed);
}
SoftPWMSetPercent(CLONE_SERVO_PIN, motor_speed);
//set delay for motor speed
SET_DELAY;
}

void initial_device()
{
//initialize LCD size
//display "MCU-based" at 6,0
MyTemp_LCD.setCursor(COL1, ROW1);
MyTemp_LCD.print("MCU-based");
//display "Fan Speed" at 6,1
MyTemp_LCD.setCursor(COL2, ROW2);
MyTemp_LCD.print("Fan Speed");
//display "Control System" at 3,2
MyTemp_LCD.setCursor(COL3, ROW3);
MyTemp_LCD.print("Control System");
//display "with LCD Display" at 2,3
MyTemp_LCD.setCursor(COL4, ROW4);
MyTemp_LCD.print("with LCD Display");
LONG_DEL;
//clear LCD text display
MyTemp_LCD.clear();

void display_temp(float fahr_temp, float cel_temp)

{
MyTemp_LCD.clear();
//display "<< CURRENT STATUS >>" at 0,0
MyTemp_LCD.setCursor(COL0, ROW1);
MyTemp_LCD.print("<< CURRENT STATUS >>");
//display "Fan Speed: " at 0,1
MyTemp_LCD.setCursor(COL0, ROW2);
MyTemp_LCD.print("Fan Speed: ");
MyTemp_LCD.setCursor(COL3A, ROW2);
MyTemp_LCD.print(fanLCD);
//display "Temp. in C: " at 0,2
MyTemp_LCD.setCursor(COL0, ROW3);
MyTemp_LCD.print("Temp. in C: ");
MyTemp_LCD.setCursor(COL3A, ROW3);
MyTemp_LCD.print(cel_temp);
//display "Temp. in C: " at 0,3
MyTemp_LCD.setCursor(COL0, ROW4);
MyTemp_LCD.print("Temp. in F: ");
MyTemp_LCD.setCursor(COL3A, ROW4);
MyTemp_LCD.print(fahr_temp);
LONG_DEL;

}
Schematic Diagram:

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