Hello,
I just bought a Funduino Uno R3 board (the one on eBay for $9.30 or so). It is for an install alarm system, and I'd rather keep the real Arduino out of there, just in case. When I built the code, everything (keypad, LCD, buttons, motion detectors, and relay) work perfectly with my real Uno, but when I uploaded the same sketch to the Funduino, the LCD wouldn't initialize correctly (dark squares top row), and the entire thing just wouldn't function.
I uploaded my digital pin test sketch (attached, below) and it worked with both Ar- and Fun- duino. Specs: power to the board is via Vin pin, 5V reg. All digital pins are connected, even TX and RX, though no serial is used. All analog pins except A3 are connected. I tried to swap the chips (Atmega 328) on the two arduinos, and they both worked, but only on the real Arduino board. This means that the Funduino board itself is the problem.
What is wrong? is there something I needed to set up? Any answers will be greatly appreciated. Thanks!
Here is my alarm code: (use as you wish, it works really well)
#include <Keypad.h>
#include <LiquidCrystal.h>
int buzzer = A4;
int relay = 1; //I've got a normally-closed relay, so if something happens to the arduino or the cable, the bell will go on.
int bcklite = A5; //I wanted to control when the backlight of the LCD is on or off
int detector = A0; //PIR sensor
int button = A1; //This is the button outside that arms the system, and it's the only way the system can be armed
int motion = 0; //for storing motion. Either 1-yes, or 0-no.
int arm = 0; //Is the system armed?
int num = 0; //Variable about the digit displyed of the password on the LCD
int input = 0; //Composition of all password digits
int cntdn = -1; //Countdown timer
int code = 1234; //THIS IS YOUR PASSWORD
int led = 0; //Button on the outside showing if the system is armed or not
int buzlogic = LOW; //This stuff is for the buzzer-without-delay section of the sketch
long previousMillis = 0;
long interval = 500;
const byte ROWS = 3; //Keypad stuff
const byte COLS = 4;
char keys[ROWS][COLS] = {
{'9','8','7','#'},
{'6','5','4'},
{'3','2','1','*'},
};
byte rowPins[ROWS] = {5, 4, 3};
byte colPins[COLS] = {8, 7, 6, A2};
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
LiquidCrystal lcd(13, 2, 12, 11, 10, 9);
void setup(){
lcd.begin(16, 2);
pinMode(buzzer, OUTPUT);
pinMode(bcklite, OUTPUT);
pinMode(button, INPUT_PULLUP);
pinMode(relay, OUTPUT);
digitalWrite(relay, HIGH);
pinMode(led, OUTPUT);
digitalWrite(led, LOW);
}
void loop(){
if(arm == 0) {
digitalWrite(led, LOW);
}
else {
digitalWrite(led, HIGH);
}
if(analogRead(detector) < 25) {
motion = 1;
}
if(arm == 0) {
motion = 0;
lcd.setCursor(0, 0);
lcd.print(" DISARMED ");
lcd.setCursor(0, 1);
lcd.print(" ");
}
if(motion == 1) {
if(cntdn == -1) {
cntdn = 42;
}
if(cntdn > 39) {
lcd.setCursor(0, 0);
lcd.print(" ENTER PASSCODE ");
lcd.setCursor(0, 1);
lcd.print("you have");
lcd.setCursor(12, 1);
lcd.print("secs");
}
}
if(arm == 1) {
if(motion == 0) {
lcd.setCursor(0, 0);
lcd.print(" ARMED ");
lcd.setCursor(0, 1);
lcd.print(" ");
}
}
else{
lcd.setCursor(0, 0);
lcd.print(" DISARMED ");
lcd.setCursor(0, 1);
lcd.print(" ");
}
if(digitalRead(button) == LOW) {
arm = 1;
lcd.setCursor(0, 0);
lcd.print(" ARMED ");
lcd.setCursor(0, 1);
lcd.print(" ");
digitalWrite(bcklite, LOW);
}
if(arm == 1) {
if(motion == 1) {
if(cntdn > 0) {
digitalWrite(bcklite, HIGH);
unsigned long currentMillis = millis();
if(currentMillis - previousMillis > interval) {
previousMillis = currentMillis;
if (buzlogic == LOW) {
buzlogic = HIGH;
}
else {
buzlogic = LOW;
}
digitalWrite(buzzer, buzlogic);
cntdn = cntdn - 1;
lcd.setCursor(9, 1);
lcd.print(cntdn / 2);
lcd.print(" ");
}
}
else {
digitalWrite(relay, LOW);
}
char key = keypad.getKey();
if (key != NO_KEY){
switch (key){
case '#':
lcd.setCursor(0, 1);
lcd.print("you ");
num = 0;
input = 0;
break; //# means clear entered digits
case '*':
{ //* means check selected digits
if(input == code) { //comparing the entered password "input" to this number right here
cntdn = -1;
lcd.setCursor(0, 0);
lcd.print(" SUCCESS ");
lcd.setCursor(0, 1);
lcd.print(" ");
digitalWrite(buzzer, LOW);
digitalWrite(relay, HIGH);
delay(1000);
lcd.setCursor(0, 0);
lcd.print(" DISARMED ");
digitalWrite(bcklite, LOW);
num = 0;
input = 0;
arm = 0;
motion = 0;
}
if(input != code) {
if(arm == 1) {
lcd.setCursor(0, 0);
lcd.print("wrong, try again");
lcd.setCursor(0, 1);
lcd.print("you ");
num = 0;
input = 0;
}
}
break;
}
default:
{ //right here "input" displays value of combined digits
lcd.setCursor(num, 1);
lcd.print("*");
if(num == 0){
input = input + (key - '0') * 1000;
}
if(num == 1){
input = input + (key - '0') * 100;
}
if(num == 2){
input = input + (key - '0') * 10;
}
if(num == 3){
input = input + (key - '0');
}
num = num + 1;
}
}
}
if(num > 3){ //recycles digit of input to 0 after 4 have been pressed
num = 0;
}
}
}
}
And this is the digital-pin test code I mentioned...
void setup() {
pinMode(0, OUTPUT); // LEDs attached to all of these pins
pinMode(1, OUTPUT);
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
pinMode(12, OUTPUT);
pinMode(13, OUTPUT);
}
void loop() {
for(int num = 0; num < 14; num = num + 1) {
digitalWrite(0, LOW);
digitalWrite(1, LOW);
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
digitalWrite(6, LOW);
digitalWrite(7, LOW);
digitalWrite(8, LOW);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
digitalWrite(11, LOW);
digitalWrite(12, LOW);
digitalWrite(13, LOW);
digitalWrite(num, HIGH);
Serial.println(num);
delay(1000);
}
}
Thanks again for your help!