This sample code is for Controlling Arduino Using Voice Tutorial by Cytron Technologies Sdn. Bhd.
/* | |
This example code is for Controlling Arduino Using Voice Tutorial. | |
Product page: | |
Maker UNO: https://www.cytron.io/p-maker-uno | |
Created by: | |
16/07/18 Suad Anwar, Cytron Technologies | |
*/ | |
#include <SoftwareSerial.h> | |
SoftwareSerial HC06Serial(11, 10); // (RX,TX) | |
String value; | |
int yellow = 4; | |
int red = 5; | |
int green = 6; | |
void setup() { | |
pinMode(yellow, OUTPUT); | |
pinMode(red, OUTPUT); | |
pinMode(green, OUTPUT); | |
Serial.begin(9600); // start serial communication at 9600bps | |
HC06Serial.begin(9600); | |
} | |
void loop() { | |
Serial.println(value); | |
if (HC06Serial.available()) | |
{ | |
value = HC06Serial.readString(); | |
if (value == "on") { | |
digitalWrite(yellow, HIGH); | |
digitalWrite(red, HIGH); | |
digitalWrite(green, HIGH); | |
} | |
if (value == "off") { | |
digitalWrite(yellow, LOW); | |
digitalWrite(red, LOW); | |
digitalWrite(green, LOW); | |
} | |
if (value == "yellow on") { | |
digitalWrite(yellow, HIGH); | |
} | |
if (value == "red on") { | |
digitalWrite(red, HIGH); | |
} | |
if (value == "green on") { | |
digitalWrite(green, HIGH); | |
} | |
if (value == "yellow off") { | |
digitalWrite(yellow, LOW); | |
} | |
if (value == "red off") { | |
digitalWrite(red, LOW); | |
} | |
if (value == "green off") { | |
digitalWrite(green, LOW); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment