Arduino Deprecated conversion from string constant to 'char*' [-Wwrite-strings] - arduino

I am getting this deprecated conversion error when I compile/verify or upload my codes to the Arduino board.
#define SENSOR 3
#define BUZZER 4
#define RELAY 5
#define MOTOR 6
char phonenumber[] = "+639278832517";
//char phonenumber[] = "+639166390471";
uint8_t vibrationData = 0;
uint8_t isArmed = 1;
float latitude, longitude, speed_kph, heading, altitude;
long randNumber;
void setup() {
Serial.begin(115200);
pinMode(RELAY, OUTPUT);
pinMode(MOTOR, OUTPUT);
pinMode(BUZZER, OUTPUT);
digitalWrite(RELAY, HIGH);
digitalWrite(MOTOR, HIGH);
digitalWrite(BUZZER, HIGH);
randomSeed(analogRead(A0));
attachInterrupt(digitalPinToInterrupt(SENSOR), vibrationISR, RISING);
setupFona();
disarm();
Serial.println("Setup done!");
latitude = 14.7042209;
longitude = 121.0369513;
deleteMessages();
}
void vibrationISR() {
if(!isArmed) return;
if(vibrationData == 2) return;
vibrationData = 1;
}
void loop() {
if(isArmed) {
if(vibrationData > 0) {
vibrationData = 2;
digitalWrite(BUZZER, LOW);
Serial.println("Vibration Detected");
if(sendSMS(phonenumber, "Vibration sensor triggered")) {
Serial.println("Send notification success!");
} else {
Serial.println("Send notification failed");
}
delay(1000);
digitalWrite(BUZZER, HIGH);
vibrationData = 0;
}
}
String response = readSMS(phonenumber);
if(response.equals("!#disarm")) {
disarm();
} else if(response.equals("!#arm")) {
arm();
} else if(response.equals("!#on")) {
motorOn();
} else if(response.equals("!#off")) {
motorOff();
} else if(response.equals("!#gps")) {
sendGPS();
}
}
void sendGPS() {
if(getGPS(&latitude, &longitude, &speed_kph, &heading, &altitude)) {
Serial.println("Got GPS fix");
} else {
randNumber = random(300);
if (randNumber % 2 == 0) {
latitude += 0.0001;
longitude += 0.0001;
} else {
latitude -= 0.0001;
longitude -= 0.0001;
}
Serial.println("Cannot get GPS fix");
Serial.print(latitude, 6); Serial.print(","); Serial.println(longitude, 6);
}
String message = "!#location:" + String(latitude, 6) + "," + String(longitude, 6);
Serial.println(message);
int messageLen = message.length();
char messageArray[messageLen + 1];
message.toCharArray(messageArray, messageLen + 1);
if(sendSMS(phonenumber, messageArray)) {
Serial.println("Send GPS success!");
} else {
Serial.println("Send GPS failed");
}
}
void arm() {
Serial.println("Arm");
isArmed = 1;
digitalWrite(RELAY, HIGH);
digitalWrite(MOTOR, HIGH);
if(sendSMS(phonenumber, "System is armed")) {
Serial.println("Send Arm notification success!");
} else {
Serial.println("Send Arm notification failed");
}
}
void disarm() {
Serial.println("Disarm");
isArmed = 0;
digitalWrite(RELAY, LOW);
if(sendSMS(phonenumber, "System is disamred")) {
Serial.println("Send Disarm notification success!");
} else {
Serial.println("Send Disarm notification failed");
}
}
void motorOn() {
Serial.println("Motor On");
digitalWrite(MOTOR, LOW);
if(sendSMS(phonenumber, "Motor is now on")) {
Serial.println("Send Motor On notification success!");
} else {
Serial.println("Send Motor On notification failed");
}
}
void motorOff() {
Serial.println("Motor Off");
digitalWrite(MOTOR, HIGH);
if(sendSMS(phonenumber, "Motor is now off")) {
Serial.println("Send Motor Off notification success!");
} else {
Serial.println("Send Motor Off notification failed");
}
}
Error logs:
E:\smart-motorcycle\smart-motorcycle.ino:145:47: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
if(sendSMS(phonenumber, "Motor is now off")) {
^
This codes has been tested before but after importing the project from another laptop this errors appeared.

Your sendSMS probably looks like this
void sendSMS(char *phonenumber, char *message);
This should be const char * when you are passing string literals.
void sendSMS(const char *phonenumber, const char *message);
note that you don't get a warning on the phone number as the array is not a pointer to const memory.
char phonenumber[] = "+639278832517";

Related

Arduino Anti-Theft System

I have an arduino anti-theft sistem.
The problem is the function void disarm()
//define Variables
#include <LiquidCrystal_I2C.h>
#include <Keypad.h>
#include <RTClib.h>
//LCD
#define I2C_ADDR 0x27
#define LCD_COLUMNS 20
#define LCD_LINES 4
LiquidCrystal_I2C lcd(I2C_ADDR, LCD_COLUMNS, LCD_LINES);
RTC_DS1307 rtc;
// Definire PINI
const int ledPin4 = 4;
const int ledPin5 = 5;
int lastButtonstate = LOW;
int lastState;
int button = 3;
// PIR
int pir = 2; // choose the input pin (for PIR sensor)
int pirState = LOW; // we start, assuming no motion detected
int val = 0;
//Senzor dist
#define trigerPin 9
#define echoPin 10
long duration, distance;
// Arm/Disarm
bool isArmed = false;
//tastatura si parola
char password[5] ="1234"; //create a password
int pozisyon = 0; //keypad position
const byte rows = 4; //number of the keypad's rows and columns
const byte cols = 4;
char keyMap [rows] [cols] = { //define the cymbols on the buttons of the keypad
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
byte rowPins [rows] = {14, 15, 16, 17}; //pins of the keypad
byte colPins [cols] = {18, 19, 20, 21};
Keypad myKeypad = Keypad( makeKeymap(keyMap), rowPins, colPins, rows, cols);
void setup() {
Serial.begin(9600);
rtc.begin();
pinMode(trigerPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(pir, INPUT);
//Setup for LEDs
pinMode(ledPin4, OUTPUT);
pinMode(ledPin5, OUTPUT);
// Pin Mode Buton
lastState = digitalRead(button);
//Setup for LCD
lcd.init();
lcd.backlight();
lcd.setCursor(5,0);
lcd.print(" Sistem ");
lcd.setCursor(2,1);
lcd.print(" anti-efractie ");
delay(1000);
lcd.clear();
}
void loop() {
int currState = digitalRead(button);
if(currState != lastState && currState == HIGH) {
if(!isArmed) {
arm();
}
else if(isArmed) {
disarm();
}
}
lastState = currState;
pirsenzor();
distsenzor();
delay(100);
}
//=================================FUNCTII & SENZORI=================================
void arm() {
if(!isArmed) {
// Armare si cerere parola
lcd.clear();
lcd.print("Armare sistem");
delay(1000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Introduceti codul:");
delay(50);
int attempts = 0;
do {
char whichKey = myKeypad.getKey();
if (whichKey != NO_KEY) {
lcd.setCursor(pozisyon, 1);
lcd.print("*");
password[pozisyon] = whichKey;
pozisyon++;
}
if (pozisyon == 4) {
// Verificare parola corecta
if(strcmp(password, "1234") == 0) {
digitalWrite(ledPin5, HIGH);
delay(300);
digitalWrite(ledPin5, LOW);
delay(300);
digitalWrite(ledPin5, HIGH);
delay(300);
digitalWrite(ledPin5, LOW);
delay(300);
digitalWrite(ledPin5, HIGH);
delay(300);
digitalWrite(ledPin5, LOW);
lcd.clear();
lcd.setCursor(5, 0);
lcd.print("Sistem armat");
delay(3000);
lcd.clear();
isArmed = true;
break;
}
else {
// Verificare parola incorecta
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Parola Incorecta!");
delay(1000);
lcd.clear();
pozisyon = 0;
attempts++;
if(attempts == 1)
{
lcd.clear();
break;
}
continue;
}
}
} while (!isArmed);
}
}
void disarm() {
if(isArmed) {
// Dezarmare si cerere parola
lcd.clear();
lcd.print("Dezarmare sistem");
Serial.println("Sunt aici");
delay(1000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Introduceti codul:");
delay(50);
int attempts = 0;
do {
char whichKey = myKeypad.getKey();
if (whichKey != NO_KEY) {
lcd.setCursor(pozisyon, 1);
lcd.print("*");
password[pozisyon] = whichKey;
pozisyon++;
}
if (pozisyon == 4) {
// Verificare parola corecta
if(strcmp(password, "1234") == 0) {
Serial.println("Am trecut de asta");
digitalWrite(ledPin4, HIGH);
delay(300);
digitalWrite(ledPin4, LOW);
delay(300);
digitalWrite(ledPin4, HIGH);
delay(300);
digitalWrite(ledPin4, LOW);
delay(300);
digitalWrite(ledPin4, HIGH);
delay(300);
digitalWrite(ledPin4, LOW);
lcd.clear();
lcd.setCursor(5, 0);
lcd.print("Sistem dezarmat");
Serial.println("Am facut asta");
delay(3000);
isArmed = false;
lcd.clear();
break;
}
else {
// Verificare parola incorecta
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Parola Incorecta!");
delay(1000);
lcd.clear();
pozisyon = 0;
attempts++;
if(attempts == 3)
{
lcd.clear();
break;
}
}
}
} while (isArmed);
}
}
// Senzor PIR
void pirsenzor() {
distsenzor();
val = digitalRead(pir); // read input value
if (val == HIGH && !isArmed && distance <= 250) {
digitalWrite(ledPin4, HIGH);
delay(300);
digitalWrite(ledPin4, LOW);
delay(300);
digitalWrite(ledPin4, HIGH);
delay(300);
digitalWrite(ledPin4, LOW); // turn LED ON
if (pirState == LOW) {
lcd.setCursor(0, 0);
lcd.print("Motion detected at");
lcd.setCursor(0, 1);
lcd.print(distance);
lcd.print(" m ");
pirState = HIGH;
}
} else {
digitalWrite(ledPin4, LOW); // turn LED OFF
if (pirState == HIGH) {
lcd.clear();
pirState = LOW;
}
}
}
//Senzor distanta
void distsenzor() {
digitalWrite(trigerPin, LOW); // ensure trigger is low
delayMicroseconds(2);
digitalWrite(trigerPin, HIGH); // send a 10us high to trigger
delayMicroseconds(10);
digitalWrite(trigerPin, LOW);
duration = pulseIn(echoPin, HIGH); //Measure the duration of the echo pulse
distance = (duration / 2) / 29.1; //Calculate the distance using the speed of sound
if (distance >= 400 || distance <= 2) { //Check if the distance is out of range
}
}
Everything is good I push the button to arm the system, the system ask to introduce the password everything is ok but when disarm function is called the function bypass password verification step.
A mention I have a pushbutton with a double function (arm/disarm system).
Sorry for my bad english :).
a suggestion or a solution please.
When you arm the system with
isArmed = true;
you should also reset
pozisyon = 0;
because pozisyon == 4 is used as an indicator that a password has been entered

Arduino Uno and HC-05: Not showing any output on serial monitor

Arduino Uno - HC-05
Connections are: TX-RX, RX-TX, LED-D13, 5V-5V+
For this project, we can supply power to the Arduino through any +5V power source. You can use a USB port from your computer to power the Arduino, but in this project I used my laptop.
while (Serial.available()) is returning 0 and Serial.read() is returning -1.
Need Help!
Used Bluetooth voice recognition tool from playstore-"Arduino Voice Control"
#include <SoftwareSerial.h> //Replace (' ') with (< >)
SoftwareSerial BLU(0,1);
String voice;
int Green = 13; //Connect To Pin #13
//int Yellow = 2; //Connect To Pin #2
//int Red = 3; //Connect To Pin #3
void allon() {
//digitalWrite(Red, HIGH);
//digitalWrite(Yellow, HIGH);
Serial.print("start");
digitalWrite(Green, HIGH);
}
void alloff() {
//digitalWrite(Red, LOW);
//digitalWrite(Yellow, LOW);
digitalWrite(Green, LOW);
}
void setup() {
Serial.begin(9600);
BLU.begin(9600);
//pinMode(Red, OUTPUT);
//pinMode(Yellow, OUTPUT);
pinMode(Green, OUTPUT);
}
void loop() {
//Serial.print("start loop");
//Serial.print(Serial.available());
while (Serial.available()) { //Check if there is an available byte to read
//Serial.print("start");
delay(10); //Delay added to make thing stable
char c = Serial.read(); //Conduct a serial read
//Serial.print(Serial.read());
if (c == '#') {
break; //Exit the loop when the # is detected after the word
}
//Serial.print(c);
voice += c;
//Serial.print(voice+"\n");
}
if (voice.length() > 0) {
Serial.print("Start");
Serial.print(voice);
if (voice == "*turn on all LED") {
allon();
}
else if (voice == "*turn off all LED") {
alloff();
}
/*else if(voice == "*switch on red") {
digitalWrite(Red,HIGH);
}
else if(voice == "*switch on yellow") {
digitalWrite(Yellow,HIGH);
}*/
else if(voice == "*switch on green") {
digitalWrite(Green,HIGH);
}
/*else if(voice == "*switch off red") {
digitalWrite(Red,LOW);
}
else if(voice == "*switch off yellow") {
digitalWrite(Yellow,LOW);
}*/
else if(voice == "*switch off green") {
digitalWrite(Green,LOW);
}
voice=""; //Reset variable
}
}
You need to check for the app output first. If you already know it then mention that in comment otherwise do the following for printing app output first:-
const int LED = 5;
void setup() {
Serial.begin(9600);
pinMode(LED, OUTPUT);
}
void loop() {
while(Serial.available()>0){
switchstate = Serial.read();
Serial.print(switchstate); // First check what output are you getting from the application
Serial.print("\n");
delay(15);
if(switchstate == '1'){ // Compare your app output accordingly
digitalWrite(5, HIGH);
}
else if(switchstate == '0'){
digitalWrite(5, LOW);
}
}
}

How to merge two arduino programs on Bluetooth and Fingerprint?

Bluetooth and fingerprint are not responding simultaneously.
Bluetooth is used for controlling "Find me alarm" and Fingerprint is used to control the open and close motors.
The bluetooth is used to trigger the buzzer to make a buzzing sound. The fingerprint is used to control the four motors which is used to open and close the door
How to merge these two programs?
Fingerprint :
#include <FPS_GT511C3.h>
#include <SoftwareSerial.h>
FPS_GT511C3 fps(5, 4);
int buttonstate = 0;
void setup()
{
Serial.begin(9600);
delay(100);
fps.Open();
fps.SetLED(true);
pinMode(8,OUTPUT);
pinMode(9,OUTPUT);
pinMode(10,OUTPUT);
pinMode(11,OUTPUT);
pinMode(13,INPUT);
pinMode(16,OUTPUT);
pinMode(17,OUTPUT);
pinMode(18,OUTPUT);
pinMode(19,OUTPUT);
}
void loop()
{
buttonstate=digitalRead(13);
if (fps.IsPressFinger())
{
fps.CaptureFinger(false);
int id = fps.Identify1_N();
if (id <200)
{
Serial.print("Verified ID:");
Serial.println(id);
digitalWrite(8,HIGH);
digitalWrite(9,LOW);
digitalWrite(10,HIGH);
digitalWrite(11,LOW);
delay(1000);
digitalWrite(8,LOW);
digitalWrite(9,LOW);
digitalWrite(10,LOW);
digitalWrite(11,LOW);
delay(100);
digitalWrite(16,HIGH);
digitalWrite(17,LOW);
digitalWrite(18,HIGH);
digitalWrite(19,LOW);
}
else
{
Serial.println("Finger not found");
}
}
else
{
Serial.println("Please press finger");
}
if(buttonstate == HIGH)
{
digitalWrite(8,LOW);
digitalWrite(9,HIGH);
digitalWrite(10,LOW);
digitalWrite(11,HIGH);
delay(1000);
digitalWrite(8,LOW);
digitalWrite(9,LOW);
digitalWrite(10,LOW);
digitalWrite(11,LOW);
delay(100);
digitalWrite(16,LOW);
digitalWrite(17,LOW);
digitalWrite(18,LOW);
digitalWrite(19,LOW);
}
delay(100);
}
Bluetooth :
#include<SoftwareSerial.h>
SoftwareSerial BT(14,15);
String readdatta;
void setup() {
BT.begin(9600);
Serial.begin(9600);
pinMode(12,OUTPUT);
}
void loop() {
char ch;
while(ch!=0)
{
ch=BT.read();
delay(100);
if(ch == '1')
{
digitalWrite(12,HIGH);
}
else
{
digitalWrite(12,HIGH);
}
}
ch = ' ';
}

Arduino: If/Else issues

Situation: I have a webpage that has two buttons on it. One sends to the PubNub channel a JSON string of {"lightRight":"1"} and one sends {"lightRight":"0"}, regardless of what I do in the Arduino Sketch I cannot make it into the "on" portion of the void light function.
I know from the serial output of the arduino that I am receiving communication from the web page. If I flip my boolean values to off then I am able to get the "LED HIGH" output but then no longer can I get the "led low".
The code I am trying to adapt can be found here.
https://gist.github.com/ianjennings/ada8fb1a91a486a0c73e
It is very possible I have hacked out to much code from the examples that is why I am including it, but running the stock code I cannot seem to get this to work.
I am not a developer, so I am very sorry if I do not call things as their proper terms. I will learn from correction.
#include <PubNub.h>
#include <SPI.h>
#include <EthernetV2_0.h>
#include <string.h>
#include <Servo.h>
byte mac[] = { MAC was here };
byte gateway[] = { Gate was here };
byte subnet[] = { Sub was here };
IPAddress ip(IP was here);
char pubkey[] = "Key was here";
char subkey[] = "Key was here";
char channel[] = "Channel was here";
int lightRight = 5;
int lightRoom = 6;
int lightGarage = 7;
int i;
EthernetClient *client;
#define W5200_CS 3
#define SDCARD_CS 4
void setup()
{
pinMode(SDCARD_CS,OUTPUT);
digitalWrite(SDCARD_CS,HIGH);
Serial.begin(9600);
Serial.println("Serial set up");
while (!Ethernet.begin(mac)) {
Serial.println("Ethernet setup error");
blink(1000, 999999);
delay(1000);
}
Serial.println("Ethernet set up");
PubNub.begin(pubkey, subkey);
Serial.println("PubNub set up");
pinMode(lightRight, OUTPUT);
pinMode(lightRoom, OUTPUT);
pinMode(lightGarage, OUTPUT);
// blink(100, 5);
reset();
}
//void flash(int ledPin)
//{
// for (int i = 0; i < 3; i++) {
// Serial.println("flash");
// digitalWrite(ledPin, HIGH);
// delay(100);
// digitalWrite(ledPin, LOW);
// delay(100);
// }
//}
void loop()
{
Ethernet.maintain();
PubSubClient *client;
Serial.println("waiting for a message (subscribe)");
client = PubNub.subscribe(channel);
if (!client) {
Serial.println("subscription error");
return;
}
String messages[10];
boolean inside_command = false;
int num_commands = 0;
String message = "";
char c;
while (client->wait_for_data()) {
c = client->read();
if(inside_command && c != '"') {
messages[num_commands] += c;
}
if(c == '"') {
if(inside_command) {
num_commands = num_commands + 1;
inside_command = false;
} else {
inside_command = true;
}
}
message += c;
}
client->stop();
for (i = 0; i < num_commands; i++){
int colonIndex = messages[i].indexOf(':');
String subject = messages[i].substring(0, colonIndex);
String valueString = messages[i].substring(colonIndex + 1, messages[i].length());
boolean value = false;
if(valueString == "1") {
value = true;
}
if(subject == "lightRight") {
light(lightRight, value);
}
if(subject == "lightRoom") {
light(lightRoom, value);
}
if(subject == "lightGarage") {
light(lightGarage, value);
}
if(subject == "blink") {
blink(100, valueString.toInt());
}
Serial.println(subject);
Serial.println(value);
}
Serial.print(message);
Serial.println();
delay(2000);
}
void light(int ledPin, boolean on) {
if(on) {
digitalWrite(ledPin, HIGH);
Serial.println("LED HIGH");
} else {
digitalWrite(ledPin, LOW);
Serial.println("led low");
}
}
void reset() {
Serial.println("Void reset");
light(lightRight, false);
light(lightRoom, false);
light(lightGarage, false);
}
void on() {
Serial.println("Void on");
light(lightRight, true);
light(lightRoom, true);
light(lightGarage, true);
}
void off() {
Serial.println("Void off");
light(lightRight, false);
light(lightRoom, false);
light(lightGarage, false);
}
void blink(int delayn, int count) {
for (int j=0; j <= count; j++){
on();
delay(delayn);
off();
delay(delayn);
}
}
That example expects the PubNub publish to be "lightRight:1" and not {"lightRight": "1"}.

processing arduino connection difficulty

i am trying to send char's from processing to arduino, but arduino only recognizes 2 of them,
the problem is with the '2' char
when i press the 's' key the processing code is sending the '2' char because i can see the arduino rx led lighting but the motor does nothing,
with the '1' or '0' chars i have no problem,
i switched the '2' in the arduino code to correspond to drive_forward and then to drive_reverse, but the one that had '2' char assigned to it did not work in both cases,
as i said the '1'and '0' char are sent and received well
i guess it is something in the arduino code, but i don't know what
arduino code:
int motor1 = 4;
int motor2 = 5;
char val;
// --------------------------------------------------------------- Setup
void setup() {
Serial.begin(9600);
// Setup motors
pinMode(motor1, OUTPUT);
pinMode(motor2, OUTPUT);
}
// ---------------------------------------------------------------- Loop
void loop() {
if (Serial.available()>0)
{ // If data is available to read,
val = Serial.read(); // read it and store it in val
}
if (val == '2'){
drive_forward();
}
if (val == '1'){
drive_reverse();
}
if (val == '0'){
motor_stop();
}
}
// --------------------------------------------------------------------------- Drive
void motor_stop(){
digitalWrite(motor1, LOW);
digitalWrite(motor2, LOW);
}
void drive_forward(){
digitalWrite(motor1, HIGH);
digitalWrite(motor2, LOW);
delay(15);
digitalWrite(motor1, LOW);
digitalWrite(motor2, LOW);
delay(15);
}
void drive_reverse(){
digitalWrite(motor2, HIGH);
digitalWrite(motor1, LOW);
delay(15);
digitalWrite(motor2, LOW);
digitalWrite(motor1, LOW);
delay(15);
}
processing code:
import processing.serial.*;
Serial myPort;
void setup()
{
size(200,200);
myPort = new Serial(this, Serial.list()[2], 9600);
}
void draw() {
}
void keyPressed() {
if (key == 'w' || key == 'W')
{
myPort.write('1');
println("1");}
if (key == 's' || key == 'S')
{
myPort.write('2');
println("2");}
}
void keyReleased() {
myPort.write('0');
println("0");
}
As #tailedmouse said, send data as integer.
Processing code:
//skipped some code
void keyPressed() {
if (key == 'w' || key == 'W') {
myPort.write(1);
}
if (key == 's' || key == 'S') {
myPort.write(2);
println("2");
}
}
void keyReleased() {
myPort.write(0);
println("0");
}
Arduino code:
//skipped some code.
void loop() {
if (Serial.available()>0) {
// If data is available to
read, val = Serial.read();
// read it and store it in val
}
if (val == 2) {
drive_forward();
}
if (val == '1') {
drive_reverse();
}
if (val == '0') {
motor_stop();
}
}

Resources