Hi, I am attempting to build a Monster in A Box project on a more simple scale than this one:
https://create.arduino.cc/projecthub/craig-jameson/monster-in-a-box-41cc38?f=1
My problem lies with the IOT Relay from Digital Loggers.IoT Relay – Digital Loggers Direct I can make the simple program from Digital Loggers work fine with my Arduino Uno:
int relay = 13; // Tells Arduino the relay is connected to pin 13
void setup()
{
pinMode(relay, OUTPUT); // Initialize the Atmel GPIO pin as an output
}
void loop() // Loops forever
{
digitalWrite(relay, HIGH); // Turn the relay on (HIGH is the voltage level = 1)
delay(5000); // Stay ON for 5 seconds
digitalWrite(relay, LOW); // Turn the relay off by making the voltage LOW = 0
delay(5000); // Stay OFF for 5 seconds
}
but when I attempt to use in it my program, I cannot get it to work. Unlike the project referenced above- my wiper motor, fog machine and lights will all go through the IOT Relay- all I have to do is trigger it with my pushbutton. However, the switch does work the Sparkfun MP3 board- but does nothing to trigger the IOT Relay. I THINK my problem lies with my use of the Delay function, but I am unsure how to remedy that. Thank you in advance, and I hope that it is something simple. Here is my program:
#include <SPI.h>
//Add the SdFat Libraries
#include <SdFat.h>
#include <SdFatUtil.h>
//and the MP3 Shield Library
#include <SFEMP3Shield.h>
SdFat sd;
SFEMP3Shield MP3player;
const int buttonPin = 4; // the number of the pushbutton pin
int relay= 13; // the number of the IOT Relay
int buttonState = 0; //variable for reading the pushbutton status
void setup() {
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT_PULLUP);
pinMode(relay, OUTPUT);
Serial.begin(9600);
//Initialize the MP3 Player Shield and SD card
sd.begin(SD_SEL, SPI_FULL_SPEED);
MP3player.begin();
//start playing track
MP3player.playTrack(1);
}
void loop() {
// put your main code here, to run repeatedly:
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) {
Serial.println("on");
// turn relay on:
digitalWrite(relay, HIGH);
//turn on MP3 player
MP3player.playTrack(1);
delay (9000);
}
if(buttonState==LOW) {
Serial.println("off");
digitalWrite(relay, LOW);
MP3player.stopTrack();
delay (500);
}