Hey everyone
In preparation for this year's Independence Day, I was planning on making some sort of remote fireworks ignition system. Unfortunately, I am not very experienced with Arduinos and I am not sure if this is a feasible project and am looking for some help, specifically for the receiver Arduino code. So far, I was planning on having a master key switch for arming/disarming the entire system, some status LEDs, a sparkfun LCD screen, push button switches, an xbee and Arduino on the sender side. The receiver side would consist of another arduino, another xbee, 4 relays attached to 4 separate fuse activation devices. The idea was that if the master key switched was closed, and one of the push buttons was pressed, the sender Arduino would send some sort of serial information that the receiver Arduino would decode and activate the corresponding relay.
I wrote and tested the sender code first, which seems to work fine. If the key is turned (switch closed), and I press one of the push buttons, I could actually see the second Xbee recieving the sent data on a connected computer's serial terminal. I don't know what to do from here, any help on the receiver code would be greatly appreciated
Thanks!
I got the code for the sparkfun LCD screen from somewhere on the arduino playground and it works fine
//Sender Arduino Code
//LCD screen definition and setup code ---------------
#include <SoftwareSerial.h>
#define txPin 2
SoftwareSerial LCD = SoftwareSerial(0, txPin);
// since the LCD does not send data back to the Arduino, we should only define the txPin
const int LCDdelay=10; // conservative, 2 actually works
// wbp: goto with row & column
void goTo(int row, int col) {
LCD.print(0xFE, BYTE); //command flag
LCD.print((col + row*64 + 128), BYTE); //position
delay(LCDdelay);
}
void clearLCD(){
LCD.print(0xFE, BYTE); //command flag
LCD.print(0x01, BYTE); //clear command.
delay(LCDdelay);
}
void backlightOn() { //turns on the backlight
LCD.print(0x7C, BYTE); //command flag for backlight stuff
LCD.print(157, BYTE); //light level.
delay(LCDdelay);
}
void backlightOff(){ //turns off the backlight
LCD.print(0x7C, BYTE); //command flag for backlight stuff
LCD.print(128, BYTE); //light level for off.
delay(LCDdelay);
}
void serCommand(){ //a general function to call the command flag for issuing all other commands
LCD.print(0xFE, BYTE);
}
// END Serial LCD Setup code
//------------------------------------------------------------------------------------------------
#define KeyArmLED 13 //Armed status LED
#define KeyArmLED2 12 //Disarmed status LED
#define KeyArm 7 //Key Switch for Arming
#define FireButton1 3 //Button 1 for activating relay 1 on the reciever side
#define FireButton2 4 //Button 2 for activating relay 2 on the reciever side
#define FireButton3 5 //Button 3 for activating relay 3 on the reciever side
#define FireButton4 6 //Button 4 for activating relay 4 on the reciever side
#define FireLED1 8 //Status LED indicating Button 1 has been pressed and Master Key switch is armed
#define FireLED2 9 //Status LED indicating Button 2 has been pressed and Master Key switch is armed
#define FireLED3 10 //Status LED indicating Button 3 has been pressed and Master Key switch is armed
#define FireLED4 11 //Status LED indicating Button 4 has been pressed and Master Key switch is armed
int val = 0;
int old_val = 0;
int val2 = 0;
int val3 = 0;
int val4 = 0;
int val5 = 0;
void setup () {
Serial.begin(9600);
pinMode(FireButton1, INPUT);
pinMode(FireButton2, INPUT);
pinMode(FireButton3, INPUT);
pinMode(FireButton4, INPUT);
pinMode(KeyArm, INPUT);
pinMode(KeyArmLED, OUTPUT);
pinMode(KeyArmLED2, OUTPUT);
pinMode(FireLED1, OUTPUT);
pinMode(FireLED2, OUTPUT);
pinMode(FireLED3, OUTPUT);
pinMode(FireLED4, OUTPUT);
//Serial LCD setup ------------->
pinMode(txPin, OUTPUT);
LCD.begin(9600);
clearLCD();
goTo(0,0);
LCD.print("System Powered Successfully!");
delay(5000);
clearLCD();
goTo(0,0);
LCD.print("System Disarmed!-Safe to handle-");
digitalWrite(KeyArmLED2, HIGH);
}
//Begin Loop Code Here -------------------------------------------------------
void loop () {
// The following checks to see if the master key switch is closed(armed) and displays appropriate LCD message and turns on the appropriate LED
val = digitalRead(KeyArm);
if ((val == HIGH) && (old_val == LOW))
{
digitalWrite(KeyArmLED, HIGH);
digitalWrite(KeyArmLED2, LOW);
clearLCD();
goTo(0,0);
LCD.print("--System Armed--Ready to Fire!!!");
}
delay(50);
if ((val == HIGH) && (old_val == HIGH))
{
digitalWrite(KeyArmLED, HIGH);
}
delay(50);
if ((val == LOW) && (old_val == HIGH))
{
digitalWrite(KeyArmLED, LOW);
digitalWrite(KeyArmLED2, HIGH);
clearLCD();
goTo(0,0);
LCD.print("System Disarmed!-Safe to handle-");
}
delay(10);
old_val = val;
//End Master Key Switch Arm Code
//---------------------------------------------
//Start Xbee transmission Code
//Relay 1
val2 = digitalRead(FireButton1);
if ((val2 == HIGH) && (val == HIGH))
{
digitalWrite(FireLED1, HIGH);
Serial.println("A");
} else {
digitalWrite(FireLED1, LOW);
}
//Relay 2
val3 = digitalRead(FireButton2);
if ((val3 == HIGH) && (val == HIGH))
{
digitalWrite(FireLED2, HIGH);
Serial.println("B");
} else {
digitalWrite(FireLED2, LOW);
}
//Relay 3
val4 = digitalRead(FireButton3);
if ((val4 == HIGH) && (val == HIGH))
{
digitalWrite(FireLED3, HIGH);
Serial.println("C");
} else {
digitalWrite(FireLED3, LOW);
}
//Relay 4
val5 = digitalRead(FireButton4);
if ((val5 == HIGH) && (val == HIGH))
{
digitalWrite(FireLED4, HIGH);
Serial.println("D");
} else {
digitalWrite(FireLED4, LOW);
}
} //end entire code