Hello all,
New to programming and Arduino so please bear with me. I have been working on a project to get a motorized lazy Susan with speed controlled by an IR remote, it also has an LCD display that will display the ambient temp, humidity and a third temperature of a liquid with a separate waterproof temp sensor. I have gotten all of the other components to work together by piecing code parts from different projects and doing edits and a lot of trial and error.
The part that is tripping me up is how to add in the code to get the IR remote to not only control the direction of the stepper motor but also speed it up. I have been able to get it to work independently of all of the other components very basic turn one direction then the other way but cant get it to work with everything else and I have not been able to find clear code for the A4988 driver and a speed controlled by IR remote.
This is as far as I've gotten with the code and it works but it is still without the IR Code, any insights would be greatly appreciated. Also please forgive the rudimentary code.
#include <LiquidCrystal.h>
#include <SimpleDHT.h>
LiquidCrystal lcd(8, 9, 10, 11, 12, 13);
int pinDHT11 = 6;
SimpleDHT11 dht11;
const int stepPin = 3;
const int dirPin = 4;
int customDelay, customDelayMapped;
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 2
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
float Celcius = 0;
float Fahrenheit = 0;
void setup() {
pinMode(stepPin, OUTPUT);
pinMode(dirPin, OUTPUT);
digitalWrite(dirPin, HIGH);
Serial.begin(9600);
sensors.begin();
lcd.begin(16, 2);
lcd.print(" Vienne ");
lcd.setCursor(0, 1);
}
void loop() {
Serial.println("=================================");
Serial.println("Sample DHT11...");
byte temperature = 0;
byte humidity = 0;
byte data[40] = {0};
if (dht11.read(pinDHT11, &temperature, &humidity, data)) {
Serial.print("Read DHT11 failed");
return;
}
Serial.print("Sample RAW Bits: ");
for (int i = 0; i < 40; i++) {
Serial.print((int)data[i]);
if (i > 0 && ((i + 1) % 4) == 0) {
Serial.print(' ');
}
}
Serial.println("");
Serial.print("Sample OK: ");
Serial.print((int)round(1.8 * +32));
Serial.println(" *F");
Serial.print((int)humidity); Serial.println(" %");
delay(500);
sensors.requestTemperatures();
Celcius = sensors.getTempCByIndex(0);
Fahrenheit = sensors.toFahrenheit(Celcius);
Serial.print(" C ");
Serial.print(Celcius);
Serial.print(" F ");
Serial.println(Fahrenheit);
delay(500);
lcd.setCursor(0, 1);
lcd.print((int)round(1.8 * +32));
lcd.setCursor(3, 1);
lcd.print((char)223);
lcd.setCursor(4, 1);
lcd.print("F");
lcd.setCursor(6, 1);
lcd.print((int)humidity);
lcd.setCursor(8, 1);
lcd.print("%H");
lcd.setCursor(11, 1);
lcd.print((int)Fahrenheit);
lcd.setCursor(15, 1);
lcd.print("F");
lcd.setCursor(14, 1);
lcd.print((char)223);
delay(500);
digitalWrite(dirPin, HIGH);
for (int x = 0; x < 4000; x++) {
digitalWrite(stepPin, HIGH);
delayMicroseconds(500);
digitalWrite(stepPin, LOW);
delayMicroseconds(500);
}
delay(1000);
digitalWrite(dirPin, LOW);
for (int x = 0; x < 4000; x++) {
digitalWrite(stepPin, HIGH);
delayMicroseconds(500);
digitalWrite(stepPin, LOW);
delayMicroseconds(500);
}
delay(1000);
}
This is the code I was trying to integrate for the IR remote and was able to get it to work by itself but I could not find how to control the speed and direction with the A4988 driver. The input signal pins were changed to accommodate the other components I had but this is the basic code for reference.
#include "Stepper.h"
#include "IRremote.h"
/*----- Variables, Pins -----*/
#define STEPS 32 // Number of steps per revolution of Internal shaft
int Steps2Take; // 2048 = 1 Revolution
int receiver = 12; // Signal Pin of IR receiver to Arduino Digital Pin 6
/*-----( Declare objects )-----*/
// Setup of proper sequencing for Motor Driver Pins
// In1, In2, In3, In4 in the sequence 1-3-2-4
Stepper small_stepper(STEPS, 8, 10, 9, 11);
IRrecv irrecv(receiver); // create instance of 'irrecv'
decode_results results; // create instance of 'decode_results'
void setup()
{
irrecv.enableIRIn(); // Start the receiver
}
void loop()
{
if (irrecv.decode(&results)) // have we received an IR signal?
{
switch(results.value)
{
case 0xFFA857: // VOL+ button pressed
small_stepper.setSpeed(500); //Max seems to be 500
Steps2Take = 2048; // Rotate CW
small_stepper.step(Steps2Take);
delay(2000);
break;
case 0xFF629D: // VOL- button pressed
small_stepper.setSpeed(500);
Steps2Take = -2048; // Rotate CCW
small_stepper.step(Steps2Take);
delay(2000);
break;
}
irrecv.resume(); // receive the next value
digitalWrite(8, LOW);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
digitalWrite(11, LOW);
}
}/* --end main loop -- */
I have attached a couple of pictures as well, I can mock up a diagram if necessary. My main issue is on how to incorporate the IR code within the working one. Any feedback and/or advice would be great.
Thanks
