0% found this document useful (0 votes)
174 views

Temperature Sensor Program Code

This document describes a simulation that uses an Arduino, temperature sensor, and RGB LED to detect and display extreme temperatures. It connects the temperature sensor to analog pin A0, and the RGB LED to pins 6, 5, and 3. The code reads the temperature sensor, and if the temperature is above 100°C, it lights the LED red. If above 50°C it is green, and if below 1°C it is blue.

Uploaded by

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

Temperature Sensor Program Code

This document describes a simulation that uses an Arduino, temperature sensor, and RGB LED to detect and display extreme temperatures. It connects the temperature sensor to analog pin A0, and the RGB LED to pins 6, 5, and 3. The code reads the temperature sensor, and if the temperature is above 100°C, it lights the LED red. If above 50°C it is green, and if below 1°C it is blue.

Uploaded by

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

// SALE, Jay Ann P.

BETMxT 3A
// ICE314: Microcontrollers & Microprocessors
// SIMULATION: Temperature Sensor for Extreme Temperature Alerts

// COMPONENTS
// Arduino Uno, Temperature Sensor, RGB LED, Resistors, Breadboard

//PINS
// Red Terminal= Pin6
// Blue Terminal= Pin5
// Green Terminal= Pin3

// C++ code
//
/*
Temperature Sensor
*/

int TempSensor = 0;

void setup()
{
pinMode(6, OUTPUT);
pinMode(5, OUTPUT);
pinMode(3, OUTPUT);
pinMode(A0, INPUT);
}

void loop()
{
// Temperature Sensor
analogWrite(6, 255);
analogWrite(5, 255);
analogWrite(3, 255);
TempSensor = -40 + 0.488155 * (analogRead(A0) - 20);

// if temp >= 100; red


if (TempSensor >= 100) {
analogWrite(6, 255);
analogWrite(5, 0);
analogWrite(3, 0);
}
// if temp >= 50; green
if (TempSensor >= 50) {
analogWrite(6, 255);
analogWrite(5, 255);
analogWrite(3, 0);
}
// if temp <= 1; blue
if (TempSensor <= 1) {
analogWrite(6, 51);
analogWrite(5, 255);
analogWrite(3, 255);
}
delay(10); // Delay a little bit to improve simulation performance
}

SIMULATION: DISPLAYING SCROLLING TEXT ON LCD WITH ARDUINO (LINE 1 STATIC,


LINE 2 SCROLLING)
Step 1: SOFTWARE
In performing the scrolling text, I opted to use TinkerCad. It is a free online website and
user-friendly for tinkering.
Step 2: COMPONENTS
The materials/components that I will be needing are: Arduino Uno, Resistor, Potentiometer,
LCD, breadboard (these are all readily available in tinkercad).
Step 3: PIN CONFIGURATIONS
For the circuit to work, I assigned LCD pin to be connected to Arduino output pins:
* LCD RS pin to digital pin 12
* LCD Enable pin to digital pin 11
* LCD D4 pin to digital pin 5
* LCD D5 pin to digital pin 4
* LCD D6 pin to digital pin 3
* LCD D7 pin to digital pin 2
* LCD R/W pin to ground
* Resistor:
* ends to +5V and ground
* wiper to LCD VO pin (pin 3)

Step 4: THE CODING


#include <LiquidCrystal.h>
//Define or name the pins
#define rs 12
#define en 11
#define d4 5
#define d5 4
#define d6 3
#define d7 2
// initialize the library with the numbers of the interface pins

LiquidCrystal lcd (rs, en, d4, d5, d6, d7);

char text[]="www.microcontroller-project.com";
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16,2);
}

void loop() {
unsigned int i=0;
// set the cursor to (0,0):
lcd.setCursor(0, 0);

while(text[i]!='\0'){
lcd.print(text[i]);

if(i>=14)
{
lcd.command(0x18); //Scrolling text to Right
}
delay(50);
i++;
}
// clear screen for the next loop:
lcd.clear();
}
#include <LiquidCrystal.h>
#define rs 12
#define en 11
#define d4 5
#define d5 4
#define d6 3
#define d7 2

LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

char * messagePadded = " Thank you for this experience, Sir! God Bless Always! ";

void setup()
{
lcd.begin (16, 2);
lcd.setCursor(0, 0);
lcd.print("Hello Sir Alvin!");
}

void loop()
{
for (int letter = 0; letter <= strlen(messagePadded) - 16; letter++)
{
showLetters(0, letter);
}
}

void showLetters(int printStart, int startLetter)


{
lcd.setCursor(printStart, 1);
for (int letter = startLetter; letter <= startLetter + 15; letter++)
{
lcd.print(messagePadded[letter]);
}
lcd.print(" ");
delay(500);
if(i>=14)

}
FINAL CODE
#include <LiquidCrystal.h>
#define rs 12
#define en 11
#define d4 5
#define d5 4
#define d6 3
#define d7 2

LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

char * messagePadded = " Thank you for this experience, Sir! God Bless Always! ";

void setup()
{
lcd.begin (16, 2);
lcd.setCursor(0, 0);
lcd.print("Hello Sir Alvin!");
}

void loop()
{
for (int letter = 0; letter <= strlen(messagePadded) - 16; letter++)
{
showLetters(0, letter);
}
}

void showLetters(int printStart, int startLetter)


{
lcd.setCursor(printStart, 1);
for (int letter = startLetter; letter <= startLetter + 15; letter++)
{
lcd.print(messagePadded[letter]);
}
lcd.print(" ");
delay(500);

{
lcd.command(0x1C); //Scrolling text to Right
}
delay(50);

You might also like