02_HC05 LM35
02_HC05 LM35
Hardware Required
Arduino or Genuino Board
Module Bluetooth
Temperature sensor
LED
Mobile Phone
Circuit
1
5V VCC Pin 1 (Vcc)
GND GND Pin 3 (G) Cathode Cathode Cathode
A1 Pin 2 (Out)
Notes:
D: digital
A: analog
GND at the power side
Code
#include <SoftwareSerial.h>
SoftwareSerial bluetooth(2, 3); // RX, TX pins for Bluetooth module
#define RED_LED_PIN 13
#define YELLOW_LED_PIN 12
#define GREEN_LED_PIN 11
#define TEMP_SENSOR_PIN A1
void setup() {
pinMode(RED_LED_PIN, OUTPUT);
pinMode(GREEN_LED_PIN, OUTPUT);
pinMode(YELLOW_LED_PIN, OUTPUT);
Serial.begin(9600);
bluetooth.begin(9600);
}
void loop() {
if (bluetooth.available()) {
char command = bluetooth.read();
if (command == 'R') { // turn on the red LED
digitalWrite(RED_LED_PIN, HIGH);
bluetooth.write("Red LED turned on\n");
} else if (command == 'r') { // turn off the red LED
digitalWrite(RED_LED_PIN, LOW);
bluetooth.write("Red LED turned off\n");
} else if (command == 'Y') { // turn on the yellow LED
digitalWrite(YELLOW_LED_PIN, HIGH);
bluetooth.write(" Yellow LED turned on\n");
} else if (command == 'y') { // turn off the yellow LED
digitalWrite(YELLOW_LED_PIN, LOW);
bluetooth.write("Yellow LED turned off\n");
} else if (command == 'G') { // turn on the green LED
digitalWrite(GREEN_LED_PIN, HIGH);
bluetooth.write("Green LED turned on\n");
} else if (command == 'g') { // turn off the green LED
digitalWrite(GREEN_LED_PIN, LOW);
2
bluetooth.write("Green LED turned off\n");
}
}
bluetooth.print("TEMPRATURE = ");
bluetooth.print(cel);
bluetooth.print("*C");
// debug for checking the temperature sensor
// Serial.println(cel);
bluetooth.println();
delay(1000);
}
Demonstrations
1. Install the Arduino Bluetooth Controller at Google Play