CesareBrizio
Published © GPL3+

Bluetooth Dialogue with Arduino via HC-05 Module

Arduino is controlled by Bluetooth dialogue - an LED is remotely turned up or down, a photoresistor value is remotely read.

IntermediateFull instructions provided1,009
Bluetooth Dialogue with Arduino via HC-05 Module

Things used in this project

Hardware components

Solderless Breadboard Full Size
Solderless Breadboard Full Size
×1
HC-05 Bluetooth Module
HC-05 Bluetooth Module
×1
Photo resistor
Photo resistor
×1
LED (generic)
LED (generic)
×1
Resistor 1k ohm
Resistor 1k ohm
×1
resistor 2k ohm
×1
Resistor 10k ohm
Resistor 10k ohm
×1
resistor 200 ohm
×1
Arduino UNO & Genuino UNO
Arduino UNO & Genuino UNO
×1

Story

Read more

Schematics

Fritzing schematics

Fritzing schematics including one photoresistor and one LED that can be activated remotely

Code

Full Arduino sketch

Arduino
Controls a photoresistor and a LED via HC-05 bluetooth dialogue
//////////////////////////////////////////////////////////////////////////////////
// REMIXED BY: CESARE BRIZIO FROM AN ORIGINAL BY TECHBITAR (HAZIM BITAR)
// LICENSE: PUBLIC DOMAIN
// DATE: 21/12/2017

char inByte;
int ledPin = 9; // LED on pin 9
int sensorPin = A0;    // input pin for the photoresistor
float sensorValue = 0;  // variable to store the value coming from the sensor

void setup() {
  Serial.begin(9600);
  pinMode(ledPin, OUTPUT);
  Serial.println("Type 1 to turn the LED on, 0 to turn it off");
}

void loop() {

  // send data only when you receive data:
  if (Serial.available() > 0) {
    // read the incoming byte:
    inByte = Serial.read();
    // say what you got:
    Serial.print("RECEIVED: ");
    Serial.println(inByte);
    if ( inByte == '0' ) digitalWrite(ledPin, LOW); // if it's a 0 (zero) turn LED off
    if ( inByte == '1' ) digitalWrite(ledPin, HIGH); // if it's a 1 (one) turn LED on
    // read the value from the sensor:
    sensorValue = analogRead(sensorPin);
    Serial.print("Photoresistor reading: ");
    Serial.print(sensorValue);
    Serial.print(" equal to ");
    Serial.print((sensorValue * 5) / 1024);
    Serial.println(" V");
  Serial.println("Type 1 to turn the LED on, 0 to turn it off");
}
}

Credits

CesareBrizio

CesareBrizio

0 projects • 4 followers

Comments