Particle photon and Easy Module Shield examples

On to another Arduino shield and this is one of my favourites, its a low cost shield which contains a variety of resources on it making it ideal for beginners. We will again connect this to a Particle Photon fitted to a Shield Shield for Spark Core and the examples will be written in the web online IDE

here is a picture of the shield

Features

You can see most of the features but here is a quick summary of what is fitted to the shield

two LEDs
two switches
reset button
Measuring temperature and humidity with DHT11 temperature and humidity sensor
Using revolving potentiometer to do analog input
passive buzzer module
Full-color RGB LED
Utilizing photovaristor to detect the brightness of light
LM35D temperature sensor
infrared receiver
2-channel digital port(D7.D8)
1-channel analog port(A3)

 

Code Examples

None of these examples need any external libraries,

Buzzer

[codesyntax lang=”cpp”]

/*
Arduino - Shield shield
5	        D1
*/


int speakerPin = D1;

// Notes defined in microseconds (Period/2) 
// from note C to B, Octaves 3 through 7
int notes[] = 
{0,
/* C,  C#,   D,  D#,   E,   F,  F#,   G,  G#,   A,  A#,   B */
3817,3597,3401,3205,3030,2857,2703,2551,2404,2273,2146,2024,   // 3 (1-12)
1908,1805,1701,1608,1515,1433,1351,1276,1205,1136,1073,1012,   // 4 (13-24)
 956, 903, 852, 804, 759, 716, 676, 638, 602, 568, 536, 506,   // 5 (25-37)
 478, 451, 426, 402, 379, 358, 338, 319, 301, 284, 268, 253,   // 6 (38-50)
 239, 226, 213, 201, 190, 179, 169, 159, 151, 142, 134, 127 }; // 7 (51-62)

#define NOTE_G3  2551
#define NOTE_G4  1276
#define NOTE_C5  956
#define NOTE_E5  759
#define NOTE_G5  638
#define RELEASE  20
#define BPM      100

// notes in the melody:
int melody[] = {NOTE_E5,NOTE_E5,0,NOTE_E5,0,NOTE_C5,NOTE_E5,0,NOTE_G5,0,0,NOTE_G4};

// note durations: 4 = quarter note, 2 = half note, etc.:
int noteDurations[] = {4,4,4,4,4,4,4,4,4,2,4,4};

void setup() {
  // iterate over the notes of the melody:
  for (int thisNote = 0; thisNote < 12; thisNote++) {

    // to calculate the note duration, take one second
    // divided by the note type.
    // e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
    int noteDuration = 60*1000/BPM/noteDurations[thisNote];
    tone(speakerPin, (melody[thisNote]!=0)?(500000/melody[thisNote]):0,noteDuration-RELEASE);

    // blocking delay needed because tone() does not block
    delay(noteDuration);
  }
}

[/codesyntax]

 

LDR example

[codesyntax lang=”cpp”]

int ldrValue = 0;
char *message = "my name is particle";
String aString;

void setup()
{
  // variable name max length is 12 characters long
  Particle.variable("ldrValue", ldrValue);
  if (Particle.variable("mess", message)==false)
  {
      // variable not registered!
  }
  Particle.variable("mess2", aString);

  pinMode(A1, INPUT);
}

void loop()
{
  // Read the analog value of the sensor
  ldrValue = analogRead(A1);
  delay(200);
}

[/codesyntax]

 

LED example

[codesyntax lang=”cpp”]

/*
Arduino - Shield shield	
12	        A4	
13	        A3
*/

#define redLed A4
#define blueLed A3

void setup() 
{
  pinMode(redLed, OUTPUT);
  pinMode(blueLed, OUTPUT);
}
 
void loop() 
{
  digitalWrite(redLed, HIGH);   // turn the LED on (HIGH is the voltage level)
  digitalWrite(blueLed, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);
  digitalWrite(redLed, LOW);    // turn the LED off by making the voltage LOW
  digitalWrite(blueLed, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);
}

[/codesyntax]

 

POT example

[codesyntax lang=”cpp”]

int vrValue = 0;
char *message = "my name is particle";
String aString;

void setup()
{
  // variable name max length is 12 characters long
  Particle.variable("vrValue", vrValue);
  if (Particle.variable("mess", message)==false)
  {
      // variable not registered!
  }
  Particle.variable("mess2", aString);

  pinMode(A0, INPUT);
}

void loop()
{
  // Read the analog value of the sensor
  vrValue = analogRead(A0);
  delay(200);
}

[/codesyntax]

 

RGB led example

[codesyntax lang=”cpp”]

/*
Arduino - Shield shield
9	        D6	 
10      	A2	
11	        A5	
*/

#define redLed D6
#define greenLed A2
#define blueLed A5

void setup()
{

  pinMode(redLed, OUTPUT);
  pinMode(greenLed, OUTPUT);
  pinMode(blueLed, OUTPUT);  
}
 
void loop()
{
  //red on
  digitalWrite(redLed, HIGH);
  digitalWrite(greenLed, LOW);
  digitalWrite(blueLed, LOW);
  delay(1000);
  //green on
  digitalWrite(redLed, LOW);
  digitalWrite(greenLed, HIGH);
  digitalWrite(blueLed, LOW);
  delay(1000);
  //blue on
  digitalWrite(redLed, LOW);
  digitalWrite(greenLed, LOW);
  digitalWrite(blueLed, HIGH);
  delay(1000);
}

[/codesyntax]

 

Links

$10 for one of these shields

keyestudio Multi-purpose Shield V1 for arduino starter

This div height required for enabling the sticky sidebar
Ad Clicks : Ad Views : Ad Clicks : Ad Views : Ad Clicks : Ad Views :