First let me explain what I am programming. I have created an Arduino Line Follower that also implements using an IR controller and receiver to control its speed and to change lanes between the line it is following. The line follower uses 3 photoresistors as the line sensors, an L298n H-bridge to drive the 2 motors of the robot, and the IR controller and receiver with all components being fixed to a aluminium chassis with nuts bolts and plastic spacers. I wired up the three photoresistors to PWM pins 8, 10, and 6 on the Arduino Nano and I wired up my H-bridge using pins that can be seen in my code below. I also got the Hexadecimal codes for the buttons I was using on the IR controller and wrote the code for using the buttons, obviously using the Hexadecimals I had gotten from the test I had done. When it came to finally testing the code I had written for the line follower with IR control I encountered the warning:
C:\Users\User\OneDrive\Technology\Technology Project\Alpha_Velocita_Mk2_Line_Following\Alpha_Velocita_Mk2_Line_Following.ino:21:16: warning: overflow in implicit constant conversion [-Woverflow]
C:\Users\User\OneDrive\Technology\Technology Project\Alpha_Velocita_Mk2_Line_Following\Alpha_Velocita_Mk2_Line_Following.ino:22:16: warning: overflow in implicit constant conversion [-Woverflow]
C:\Users\User\OneDrive\Technology\Technology Project\Alpha_Velocita_Mk2_Line_Following\Alpha_Velocita_Mk2_Line_Following.ino:23:16: warning: overflow in implicit constant conversion [-Woverflow]
C:\Users\User\OneDrive\Technology\Technology Project\Alpha_Velocita_Mk2_Line_Following\Alpha_Velocita_Mk2_Line_Following.ino:24:16: warning: overflow in implicit constant conversion [-Woverflow]
C:\Users\User\OneDrive\Technology\Technology Project\Alpha_Velocita_Mk2_Line_Following\Alpha_Velocita_Mk2_Line_Following.ino:25:18: warning: overflow in implicit constant conversion [-Woverflow]
These where all the lines in which I had put the Hexadecimals. Here is the actual code:
#include <IRremote.h>
#include <IRremoteInt.h>
//Define the sensor
#define RS 8
#define LS 10
#define MS 6
//Define the right motor
#define LM1 4
#define LM2 5
#define enR 3
//Define the left motor
#define RM1 12
#define RM2 7
#define enL 9
//IR CONTROLLER SETUP//
const int RECV_PIN = 11;
IRrecv irrecv(RECV_PIN);
decode_results results;
const int US = 0xFF629D; // UP SPEED
const int DS = 0xFFA857; //DOWN SPEED
const int LL = 0xFF22DD; //LEFT LANE
const int RL = 0xFFC23D; //RIGHT LANE
const int STOP = 0xFF02FD;
//Speed settings for line follower
int speeds[] = {0, 90, 130, 170, 220};
const int SpdMax = sizeof(speeds) / sizeof(int);
int spdIndex;
void setup()
{
Serial.begin(9600);
irrecv.enableIRIn();
pinMode(RS, INPUT);
pinMode(LS, INPUT);
pinMode(MS, INPUT);
pinMode(LM1, OUTPUT);
pinMode(LM2, OUTPUT);
pinMode(RM1, OUTPUT);
pinMode(RM2, OUTPUT);
pinMode(enL, OUTPUT);
pinMode(enR, OUTPUT);
digitalWrite(enL, HIGH);
digitalWrite(enR, HIGH);
delay(500);
}
void loop() {
if(irrecv.decode(&results)) {
int code = results.value;
switch (code) {
case US:
if (SpdMax > spdIndex)
spdIndex++;
break;
case DS:
if (0 < spdIndex)
spdIndex--;
break;
case LL:
TurnLeft ();
delay(750);
lineFollow();
break;
case RL:
TurnRight ();
delay(750);
lineFollow();
break;
case STOP:
Stop ();
break;
}
irrecv.resume();
}
}
//Defining the lineFollow command.
void lineFollow(){
if((digitalRead(RS)==LOW)&&(digitalRead(LS)==LOW)&&(digitalRead(MS)==HIGH))
{
MoveForward();
}
if((digitalRead(RS)==HIGH)&&(digitalRead(LS)==HIGH)&&(digitalRead(MS)==HIGH))
{
Stop();
}
if((digitalRead(RS)==LOW)&&(digitalRead(LS)==HIGH))
{
TurnLeft();
}
if((digitalRead(RS)==HIGH)&&(digitalRead(LS)==LOW))
{
TurnRight();
}
}
//Define conditions to move forward
void MoveForward()
{
digitalWrite(LM1, HIGH);
digitalWrite(LM2, LOW);
digitalWrite(RM1, LOW);
digitalWrite(RM2, HIGH);
analogWrite(enL, speeds[spdIndex]);
analogWrite(enR, speeds[spdIndex]);
delay(20);
}
//Define conditions to stop
void Stop()
{
digitalWrite(LM1, LOW);
digitalWrite(LM2, LOW);
digitalWrite(RM1, LOW);
digitalWrite(RM2, LOW);
analogWrite(enL, 0);
analogWrite(enR, 0);
delay(20);
}
//Define Turn Left
void TurnLeft()
{
digitalWrite(LM1, HIGH);
digitalWrite(LM2, LOW);
digitalWrite(RM1, LOW);
digitalWrite(RM2, LOW);
analogWrite(enL, speeds[spdIndex]);
analogWrite(enR, 0);
delay(20);
}
//Define Turn Right
void TurnRight()
{
digitalWrite(LM1, LOW);
digitalWrite(LM2, LOW);
digitalWrite(RM1, LOW);
digitalWrite(RM2, HIGH);
analogWrite(enL, 0);
analogWrite(enR, speeds[spdIndex]);
delay(20);
}
If somebody could please help me with this warning / error and tell me why it happened I would appreciate it. I am fairly new to Arduino but have gained some experience by doing this programming. If you notice any other problems or have advice on my code I would also really be thankful. I want to learn as much as I can.