Lecture 9
Lecture 9
Expose the module to flame or strong light and turn the knob of the
potentiometer gently till the D0 indicator light is on
Flame with Arduino (Wiring)
Code of flame sensor
void loop()
#define flame 3
{
#define buzzer 5
Val = digitalRead(flame);
int Val = 0;
Serial.print(“value of flame:");
void setup() Serial.println(Val);
{
if (Val == LOW) {
Serial.begin(9600);
digitalWrite(buzzer, HIGH);
pinMode(flame , INPUT);
}
pinMode(buzzer,OUTPUT);
else {
} digitalWrite(buzzer, LOW);
}
}
Smoke sensor
To calibrate the gas sensor you can hold the gas sensor near smoke/gas you want to detect and
keep turning the potentiometer until the Red LED on the module starts glowing. Turn the screw
clockwise to increase sensitivity or anticlockwise to decrease sensitivity.
Gas with Arduino (Wiring)
Code of smoke detector
#define MQ2pin A5 void loop()
#define buzzer 10 {
int sensorValue; sensorValue = analogRead(MQ2pin);
void setup() Serial.print("Sensor Value: ");
{ Serial.println(sensorValue);
Serial.begin(9600); if(sensorValue > 300)
pinMode(buzzer,OUTPUT); {
Serial.println("Gas sensor warming up!"); Serial.print(" | Smoke detected!");
delay(20000); // allow the MQ-2 to warm up digitalWrite(buzzer,HIGH);
} }
else
{
digitalWrite(buzzer,LOW);
}
delay(2000); // wait 2s for next reading
}
LCD Display
Terminal Functions
Pin Number Name Function
1 VSS Ground Voltage
2 VCC Power 5V
3 VO Contrast Voltage
Register Select
4 RS 1=transferring display data
0=transferring instruction data
Read/Write control bus
5 R/W 1=Read Mode
0=Write Mode
Enable
6 EN 0=Enable
1=Disable
7~10 D0~D3 Bi-directional data bus
11~14 D4~D7 Bi-directional data bus
15 BLA Backlight positive supply
16 BLK Backlight negative supply
LCD with Arduino (Wiring)
Code of LCD display without I2C
#include <LiquidCrystal.h>
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
void setup() {
lcd.begin(16, 2);
lcd.print(“ST SMART");
lcd.setCursor(7,1);
lcd.print(“2020");
}
void loop() {
for(int i=0;i<15;i++){
lcd.scrollDisplayRight();
delay(200);
}
for(int i=0;i<15;i++){
lcd.scrollDisplayLeft();
delay(200);
}
}
I2C protocol
• The two wires, or lines are called Serial Clock (or
SCL) and Serial Data (or SDA). The SCL line is
the clock signal which synchronize the data
transfer between the devices on the I2C bus and
it’s generated by the master device. The other line
is the SDA line which carries the data.
➢ Supply voltage: 5V
A0 A1 A2 Address
Open Open Open 0X27
Jumper Open Open 0X26
Open Jumper Open 0X25
Jumper Jumper Open 0X24
Open Open Jumper 0X23
Jumper Open Jumper 0X22
Open Jumper Jumper 0X21
Jumper Jumper Jumper 0X20
Soldering I2C module with lcd
LCD-I2C with Arduino (Wiring)
Code of LCD display with I2C
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
void setup() {
lcd.begin(); // or some librarys are lcd.init();
lcd.backlight();
lcd.print(“ST SMART");
lcd.setCursor(7,1);
lcd.print(“2020");
}
void loop() {
for(int i=0;i<15;i++){
lcd.scrollDisplayRight();
delay(200);
}
for(int i=0;i<15;i++){
lcd.scrollDisplayLeft();
delay(200);
}
}
Keypad
Keypad
keypad with Arduino (Wiring)
#include <Keypad.h>
const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
char keys[ROWS][COLS] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};
byte rowPins[ROWS] = {2, 3, 4, 5};
byte colPins[COLS] = {6, 7, 8};
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup(){
Serial.begin(9600);
}
void loop(){
char key = keypad.getKey();
if (key){
Serial.println(key);
}
}
Thanks for coming ☺