02 Analog Control System Prototype
02 Analog Control System Prototype
Microcontroller ATmega328P
Clock Speed 16 MHz
Flash Memory 32 KB
SRAM 2 KB
EEPROM 1 KB
Digital I/O Pins 14 (of which 6 PWM)
PWM Digital I/O Pins 6
Analog Input Pins 6
Operating Voltage 5V
DC Current per I/O Pin 20 mA
Arduino Mega Board
Arduino Mega Board
Microcontroller ATmega2560
Clock Speed 16 MHz
Flash Memory 256 KB
SRAM 8 KB
EEPROM 4 KB
Digital I/O Pins 54 (of which 15 PWM)
PWM Digital I/O Pins 15
Analog Input Pins 16
Operating Voltage 5V
DC Current per I/O Pin 20 mA
Analog Inputs
0 0 0 0 0 0 0 0 0 0 0V
1 1 1 1 1 1 1 1 1 1 5V
Read Analog Voltage
We need
▪ Arduino
▪ Potentiometer
▪ Jumpers
Potentiometer as Analog Input: Steps
int value;
void setup()
{
Serial.begin(9600);
}
void loop()
{
value = analogRead(A0);
Serial.println(value);
delay(100);
}
Potentiometer as Analog Input: Code
int value;
float volt;
void setup()
{
Serial.begin(9600);
}
void loop()
{
value = analogRead(A0);
volt = value * (5.0 / 1023.0);
Serial.println(volt);
delay(100);
}
16×2 LCD
▪ Connect the VSS (GND) pin to the ground of the power supply.
16×2 LCD: VDD Pin
3. Connect the LCD VSS pin to ground, and LCD VCC pin to 5V.
16×2 LCD: Steps
4. LCD A pin to 5V, and LCD K pin to ground using a 330Ω resistor.
16×2 LCD: Steps
void setup() {
// Set up the LCD's number of columns and rows:
lcd.begin(16, 2);
void loop() {
// Set the cursor to column 0, line 1
lcd.setCursor(0, 1);
void setup() {
// Set up the LCD's number of columns and rows:
lcd.begin(16, 2);
void loop() {
}
16×2 LCD Counter: Circuit
16×2 LCD Counter: Code
#include <LiquidCrystal.h>
void setup() {
// Set up the LCD's number of columns and rows:
lcd.begin(16, 2);
}
void loop() {
for(int i = 1; i <= 100; i++){
lcd.clear(); // Clear the LCD
lcd.setCursor(7, 0); // Center text
lcd.print(i); // Print the number on the LCD
byte heart[8] = {
0b00000,
0b01010,
0b11111,
0b11111,
0b11111,
0b01110,
0b00100,
0b00000
};
16×2 LCD - Custom Characters
byte smiley[8] = {
0b00000,
0b00000,
0b01010,
0b00000,
0b00000,
0b10001,
0b01110,
0b00000
};
16×2 LCD - Custom Characters
byte home[8] = {
0b00000,
0b00100,
0b01010,
0b10001,
0b11111,
0b11111,
0b11111,
0b11111
};
16×2 LCD - Custom Characters
https://maxpromer.github.io/LCD-Character-Creator/
16×2 LCD - Custom Characters: Circuit
16×2 LCD - Custom Characters: Code
// Include the library code:
#include <LiquidCrystal.h>
// Print a message
lcd.setCursor(2, 0);
lcd.print("We ");
lcd.write(byte(0));
lcd.print(" BFCAI ");
lcd.write(byte(1));
}
void loop() {
}
Analog Control System Prototype
▪ Change the position of the cursor based on the value of the potentiometer.
Analog Control System Prototype: Connections
▪ We will use the same connections, except connecting the wiper of the POT
to the analog input A0, and connecting VO to GND with a fixed resistance.
Analog Control System Prototype: Code
// Include the library code:
#include <LiquidCrystal.h>
void setup() {
lcd.begin(16, 2); // LCD's number of columns and rows
lcd.createChar(0, heart); // Create a custom character
lcd.createChar(1, smiley); // Create a custom character
}
Analog Control System Prototype: Code
void loop() {
pot = analogRead(A0); // Read the value of the potentiometer
Function Description
Position the LCD cursor; that is, set the location
lcd.setCursor(col, row)
at which subsequent text written to the LCD.
lcd.print(data) Prints text to the LCD.
Clears the LCD screen and positions the cursor
lcd.clear()
in the upper-left corner.
lcd.createChar(num, data) Create a custom character for use on the LCD.
lcd.write(data) Write a character to the LCD.
lcd.blink() Display the blinking LCD cursor.
lcd.noBlink() Turns off the blinking LCD cursor.
Arduino Reference