Josh From BreakoutBros.com
Published © CC BY-NC

Control Arduino over Wifi using IoT Device

We looked into using the Particle Photon to connect to our RFID badge and LCD system using an Arduino to control an IoT device.

BeginnerProtip30 minutes9,100
Control Arduino over Wifi using IoT Device

Things used in this project

Story

Read more

Schematics

Schematic

Code

Arduino Code

C/C++
//BreakoutBros tutorial
//Visit www.breakoutbros.com for more information
//ControlArduinoWifi_Arduino
 
//This tutorial will pull for the Serial Data from the Photon
//Depending on the data it recieves it will turn on or off it's LED
 
void setup() {
  pinMode(13, OUTPUT); //Set the LED pin as an output
  pinMode(0,INPUT); //Set the RX pin of the arduino as an input
  pinMode(1,OUTPUT); //Set the TX pin of the arduino as an output
  Serial.begin(9600); //Start the UART Serial communication
  delay(2000); // Wait 2 seconds - this allows the photon to power up as well before the Arduino trying to take commands
}
void loop() {
  while(Serial.available()>0) // if anything is in the Serial Buffer, run this code
  {
  Data = Serial.read(); // Read whats in the Serial buffer and store to DATA
  }
  if(Data == 0) // If the Data  is 0, turn off the LED
  {
    digitalWrite(13,LOW);
  }
  else if(Data == 1) // If the Data is 1 turn on the LED
  {
    digitalWrite(13,HIGH);
  }
}

Photon Code

C/C++
//BreakoutBros tutorial
//Visit www.breakoutbros.com for more information
//ControlArduinoWifi_Arduino
 
//This tutorial will transmit Serial Data read from the Arduino
//It will flash the LED once at 1 second and 2 times at 1/4 a second
 
int led1 = D7; 
 
void setup() {
 
  pinMode(led1, OUTPUT);
  pinMode(0, INPUT);
  pinMode(1, OUTPUT);
  digitalWrite(led1, LOW);
  Serial1.begin(9600);
 
}
//To communicate to the Arduino we will use the Serial1.write command
//The data will be sent over the UART to the arduino
//This will be a simple demo with the data being used to either
//turn on or turn off the Arduino LED. We will also turn on the 
//photon LED to mimick this
void loop() {
 
  digitalWrite(led1, LOW);
  Serial1.write(0);
  delay(1000);
  digitalWrite(led1, HIGH);
  Serial1.write(1);
  delay(250);
  digitalWrite(led1, LOW);
  Serial1.write(0);
  delay(250);
  digitalWrite(led1, HIGH);
  Serial1.write(1);
  delay(200);
  digitalWrite(led1, LOW);
  Serial1.write(0);
  delay(1000);
  digitalWrite(led1, HIGH);
  Serial1.write(1);
  delay(1000);
 
}

Credits

Josh From BreakoutBros.com

Josh From BreakoutBros.com

14 projects • 89 followers
At BreakoutBros we try to be a link between electronics designers and hobbyists. We make electronics tinkering easy for everyone but teach professional methods.

Comments