Hackster is hosting Hackster Holidays, Ep. 6: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Monday!Stream Hackster Holidays, Ep. 6 on Monday!
zhaoshentech
Published © GPL3+

Add Remote Control to Your Lamp

Use an Arduino UNO, a Bluetooth chip and a high power relay to upgrade your lamp to be remotely controllable.

BeginnerFull instructions provided2 hours4,073
Add Remote Control to Your Lamp

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
IoT Power Relay
×1
HC-08 Bluetooth to URAT
×1

Software apps and online services

Arduino IDE
Arduino IDE
Elegoo BLE Tool

Story

Read more

Code

Add Remote Control to Your Lamp

C/C++
This program receives the message from the app through Bluetooth, and then turn on or turn off the relay switch accordingly.
/* Add Remote Control to Your Lamp
 *  This is the program to controll a lamp using an IoT relay and HC-08 BLuetooth chip.
 *  Author: littlelab
 *  Last update: 2018-07-08
 *  
*/

char getstr; // to store the message from Bluetooth
bool state = LOW;  // Status of the switch

void setup() {
  // put your setup code here, to run once:
  pinMode(LED_BUILTIN, OUTPUT);// in Arduino UNO, LED_BUILTIN = pin 13
  Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
  getstr = Serial.read();
  // if received message is to turn on the switch
  if (getstr == 'k'){
    turnON();  
  }
  // if received message is to turn off the switch
  else if (getstr == 'g'){
    turnOff();  
  }

}

void turnOff(){
  state = LOW;
  digitalWrite(LED_BUILTIN, state);  
}

void turnON(){
  state = HIGH;
  digitalWrite(LED_BUILTIN, state);  
}

Credits

zhaoshentech

zhaoshentech

6 projects • 81 followers
An enthusiastic for startups!

Comments