I have a UNO connected with a SainSmart LCD 1602 Keypaid Shield and have issues controlling my sensors and relays.
I soldered headers to the LCD board as it had available to do so, but since the LCD is using
LiquidCrystal lcd(8, 13, 9, 4, 5, 6, 7);
I cant control some of my sensors. I was debating on going to pick up a Mega to get more pins, but even right now with just simple sensors I cant control them, not sure what has happened that I cant trigger my relays and I need them to trigger in order to read the other data from the other sensors.
Here is a stripped down version of just 1 relay and 1 reflective sensor for RPM calculations.
I’m sure I’m overlooking something, but not sure…
Any help would be greatly appreciated.
#include <LiquidCrystal.h>
#include <DFR_Key.h>
LiquidCrystal lcd(8, 13, 9, 4, 5, 6, 7);
DFR_Key keypad;
int localKey = 0;
String keyString = "";
int RELAY1 = A1;
// RPM SENSOR
#include <TimerOne.h>
unsigned int counter=0;
String stat = "";
String tmp = "";
int b1a = 3; // L9110 B-1A
int b1b = 2; // L9110 B-1B
void docount() // counts from the speed sensor
{
counter++; // increase +1 the counter value
}
void timerIsr()
{
int rotation = (counter / 1)* 60; // divide by number of holes in Disc
Timer1.detachInterrupt(); //stop the timer
lcd.clear();
lcd.setCursor(8, 1);
lcd.print("RPM: ");
lcd.setCursor(12, 1);
lcd.print(rotation,DEC);
counter=0; // reset counter to zero
Timer1.attachInterrupt( timerIsr ); //enable the timer
lcd.setCursor(0,0);
lcd.print("Status:");
lcd.setCursor(7,0);
lcd.print(stat);
lcd.setCursor(0,1);
lcd.print("Temp:");
lcd.setCursor(5,1);
lcd.print(tmp);
}
// END
void setup() {
// put your setup code here, to run once:
//Serial.begin(9600);
lcd.begin(16, 2);
lcd.clear();
//Sets the sample rate at once every x milliseconds.
//Default: 10ms
keypad.setRate(10);
// RPM
pinMode(b1a, OUTPUT);
pinMode(b1b, OUTPUT);
Timer1.initialize(1000000); // set timer for 1sec
attachInterrupt(0, docount, RISING); // increase counter when speed sensor pin goes High
Timer1.attachInterrupt( timerIsr ); // enable the timer
// END
// CURRENT
pinMode(RELAY1, OUTPUT);
digitalWrite(RELAY1,LOW);
// END
}
void loop()
{
digitalWrite(RELAY1,HIGH); // Turns ON Relays 1
delay(10000);
digitalWrite(RELAY1,LOW); // Turns Relay Off
delay(20000);
int potvalue = analogRead(1); // Potentiometer connected to Pin A1
int motorspeed = map(potvalue, 0, 680, 255, 0);
analogWrite(b1a, motorspeed); // set speed of motor (0-255)
digitalWrite(b1b, 1); // set rotation of motor to Clockwise
}