Send SMS using Arduino - c

I am currently working on a project. I tried different sample testing code to send sms to my current number but it won't sent any.
Should my SIM 800L GSM module sim and my phone number have the same carrier?
I even followed the other people's advices on using a 3.7v power supply.
Library already included.
Correct RX-TX TX-RX, VCC, RST pins.
Below is a sample code from what I have been following.
#include <Sim800l.h>
#include <SoftwareSerial.h> //is necesary for the library!!
Sim800l Sim800l; //to declare the library
char* text;
char* number;
bool error; //to catch the response of sendSms
void setup(){
Sim800l.begin(); // initializate the library.
text="Testing Sms"; //text for the message.
number="2926451386"; //change to a valid number.
error=Sim800l.sendSms(number,text);
// OR
//Sim800l.sendSms("+540111111111","the text go here")
}
void loop(){
//do nothing
}
This should be sending a text message to a phone number but I am not receiving any.

Related

Arduino error: 'I2C_MODE' was not declared in this scope

I'm making a program where a buzzer activates if the accelerometer is tilted a certain number of degrees. I'm getting an error that says "'I2C_MODE' was not declared in this scope." I'm using a Grove Beginner Kit, so all of the parts are automatically connected to each other. I downloaded Seeed_Arduino_LIS3DHTR library from the following link: https://github.com/Seeed-Studio/Seeed_Arduino_LIS3DHTR and used sample code from the Grove Beginner Kit for Arduino Guide that came with the board, so everything should work properly. I'm getting this error and don't want to move further with the project until I figure out what's causing this error.
#include <LIS3DHTR.h>
//Gravity Acceleration
#include "LIS3DHTR.h"
#ifdef SOFTWAREWIRE
#include <SoftwareWire.h>
SoftwareWire myWire(3, 2);
LIS3DHTR<SoftwareWire> LIS(I2C_MODE); //IIC This is what the error
#define WIRE myWire
#else
#include <Wire.h>
LIS3DHTR<TwoWire> LIS(I2C_MODE);//IIC THIS IS WHERE THE ERROR OCCURS
#define WIRE Wire
#endif
void setup() {
Serial.begin(9600);
while (!Serial) {};
LIS.begin(WIRE); //IIC init
delay(100);
LIS.setOutputDataRate(LIS3DHTR_DATARATE_50HZ);
}
void loop() {
if (!LIS) {
Serial.println("LIS3DHTR didn't connect.");
while (1);
return;
}
//3 axis
Serial.print("x:"); Serial.print(LIS.getAccelerationX()); Serial.prin
t(" ");
Serial.print("y:"); Serial.print(LIS.getAccelerationY()); Serial.prin
t(" ");
Serial.print("z:"); Serial.println(LIS.getAccelerationZ());
delay(500);
}
The docs you linked have a different instantiation than what you have!
Try passing Wire to the .begin method rather than to LIS (which presumably does exist in Wire.h and likely also exists in SoftwareWire.h)
Plausibly putting LIS.begin() in setup() is needed, though it doesn't seem to matter from their examples
LIS3DHTR<TwoWire> LIS; //IIC
LIS.begin(Wire, 0x19)

Fingerprint module Command packets doesn't send response to smt32f4

Hı everyone
I am currently working on fingerprint module(fpm10).I read so many datasheet but every datasheet have different command packets I referenced R305 datasheet after that I wrote a Code for command packet to send STM32 but fpm10 doesnt send response to stm32.This is my verifypassword command packet Module send my receive my command packet but doesnt response.I debuged my cod and ı havent get any error
uint16_t FP_Verify_Password[16]={0xEF,0x01,0xFF,0xFF,0xFF,0xFF,0x01,0x00,0x07,0x13,0x00,0x00,0x00,0x00,0x00,0x05};
void Finger_Get_img(void)
{
delay_ms(500);
if(my_finger==true)
{
//only one time will be apply
for(i=6 ; i<=13 ; i++)
checksum+=FP_Verify_Password[i];
FP_Verify_Password[14]=checksum&0xFF00;
FP_Verify_Password[15]=checksum&0x00FF;
}
for(i=0;i<16;i++)
{
// USART_SendData(USART2,FP_Pack_Head[i]);
delay_ms(50);
USART_Finger(USART1,FP_Verify_Password[i]);
delay_ms(50);
USART_Finger(USART6,FP_Verify_Password[i]);
delay_ms(50);
}
delay_ms(2000);
// GPIO_ResetBits(GPIOG,GPIO_Pin_13);
my_finger=false;
}
Bluetooth and Finger print module config
//fingerprint module configurations
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1,ENABLE);
USART_InitStruct.USART_BaudRate=57600;
USART_InitStruct.USART_HardwareFlowControl=USART_HardwareFlowControl_None;
USART_InitStruct.USART_Mode=USART_Mode_Rx|USART_Mode_Tx;
USART_InitStruct.USART_Parity=USART_Parity_No;
USART_InitStruct.USART_StopBits=USART_StopBits_1;
USART_InitStruct.USART_WordLength=USART_WordLength_8b;
USART_Init(USART1,&USART_InitStruct);
USART_Cmd(USART1,ENABLE);
USART_ITConfig(USART1,USART_IT_RXNE,ENABLE);
//bluetooth module configurations
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC,ENABLE);
GPIO_PinAFConfig(GPIOC,GPIO_PinSource6,GPIO_AF_USART6);
GPIO_PinAFConfig(GPIOC,GPIO_PinSource7,GPIO_AF_USART6);
GPIO_InitStruct.GPIO_Mode=GPIO_Mode_AF;
GPIO_InitStruct.GPIO_OType=GPIO_OType_PP;
GPIO_InitStruct.GPIO_Pin=GPIO_Pin_6|GPIO_Pin_7;
GPIO_InitStruct.GPIO_PuPd=GPIO_PuPd_UP;
GPIO_InitStruct.GPIO_Speed=GPIO_Speed_100MHz;
GPIO_Init(GPIOC,&GPIO_InitStruct);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART6,ENABLE);
USART_InitStruct.USART_BaudRate=9600;
USART_InitStruct.USART_HardwareFlowControl=USART_HardwareFlowControl_None;
USART_InitStruct.USART_Mode=USART_Mode_Rx|USART_Mode_Tx;
USART_InitStruct.USART_Parity=USART_Parity_No;
USART_InitStruct.USART_StopBits=USART_StopBits_1;
USART_InitStruct.USART_WordLength=USART_WordLength_8b;
USART_Init(USART6,&USART_InitStruct);
USART_Cmd(USART6,ENABLE);
This my command packet

Sound Sensor RGB LED coding

So we connected a sound sensor to our board to light up our LED light when sound is heard, it kinda works but there some hiccups.
We tried messing with the code for a while but no matter what we do the senor will only react to loud even when we put in a threshold. If you see in the picture, it it only displaying "loud" noise to the display and cant seem be able to go to the other condition we set in our threshold. We configure the sensor with our screw driver but nothing seem to work. Our code is below & before we continue on, we wanted to know if there a problem with it that can fix out the issue,thanks you
ALSO the sound sensor is a "ko9A01"
PS: we use "energia" to code this.
#include <msp430.h>
#include <Wire.h>
int soundsensor = 2;
int led = 3;
void setup()
{
Serial.begin(9600);
Serial.println("Begin Test");
pinMode(soundsensor,OUTPUT);
pinMode(led,OUTPUT);
}
void loop()
{
int sensorValue = digitalRead(soundsensor);
Serial.println(sensorValue);
delay(250);
if (sensorValue == 1)
{
Serial.print("LOUD");
digitalWrite(led,HIGH);
}
else
{
Serial.print("QUIET");
digitalWrite(led,LOW);
}
}
EDIT: NOW With the help of Brydon we change the output to input and change it to this we change it to this and now we get this new error voi
void setup()
{
Serial.begin(9600);
Serial.println("Begin Testing");
pinMode(soundsensor,INPUT);
}
and it only show
"begin test":
0 and wont move from there
You have the sound sensor configured as an OUTPUT in the setup.
I assume you want it to be an input? That would be the case if you're reading values from it.
I can't tell what sensor you have - but with more information on the sensor, we can read the documentation and help you configure the inputs appropriately (ie a threshold)

ESP8266 unwanted delay using client.readStringUntil(), with Microsoft SQL server

My goal is to read the number of button press within a period(30s), upload it to a Microsoft SQl table using a php script. On the table, there is another column which adds in accumulated sum of the presses, which will be echo-ed back by the php script, and be read by the ESP8266 board.
So everything went through: I can read the count, upload it, read the accumulated sum back. The issue is it always takes ~5s in order to get a value back from the server. Attached is my troubleshooting:Serial Windows
It takes almost instantly to connect to the server(~100ms) but 5s to read the data that be echo-ed.
My guess was the php script takes time to run to the line where it echo out the value, but same delay(~5s) happens even if I tried a simple script(just echo).
Is this how the server behaves (not giving out the data right away) or is this how Arduino code (client.readStringUntil()) behaves?
Here is my code:
#include <SPI.h>
#include <ESP8266WiFi.h>
// Wifi Connection config
const char* ssid = "------";
const char* password = "------";
WiFiServer server(80);
IPAddress dbserver(10,1,1,138);
void setup_wifi()
{
delay(10);
// We start by connecting to a WiFi network
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
}
void setup()
{
Serial.begin(115200);
// Connect to WiFi network
setup_wifi();
}
void loop ()
{
WiFiClient client;
const int httpPort = 80;
bool conn = client.connect(dbserver,httpPort);
if (!conn) {
Serial.println("connection failed");
return;
}
else {
// call php script on the server(echo 1 value)
client.print("GET /test10.php HTTP/1.1");
client.println("Host: 10.1.1.138");
client.println("Connection: close");
client.println(); // Empty line
// Read from the server
Serial.println(millis()); // millis start reading
unsigned long timeout = millis();
while (client.available()==0){
if (millis()-timeout >1000){
Serial.println(">>> Client Timeout !");
client.stop();
}
}
Serial.println(millis()); // millis get the data stream
while (client.available()){
String line = client.readStringUntil('\r');
Serial.println(String(millis()) + " >>> "+line); // millis get each
// data line
}
delay(10);
client.stop(); // Closing connection to server
Serial.println("done");
}
delay(30000);
}
And is there any other way to fetch the data from the server to an ESP8266 module?
Thank you,
-Danny-
[SOLVED]: I need to set the Timeout parameter for the readStringUntil() function.
readStringUntil() is a blocking function. I will wait until it sees a char ('\r' in your case) or the timeout exceeds.
Just need to add client.setTimeout as:
WifiClient client;
client.setTimeout(10);
Still not sure if this practice is recommended, and how smaller should I go to for timeout?
Another solution would be using freeRTOS, and put the webserver in a separate task.
Then it can wait forever until a request is coming in.

serial.println(String) prints "#" instead of the string

i'm just trying to recieve a string using a serial and to send this string back. So when i send a string to an arduino over a serial the arduino should automaticly send this string back.
i created this code:
String test;
void setup(){
Serial.begin(9600);
Serial.setTimeout(2);
test = "null";
}
void loop(){
if(Serial.available()){
test = Serial.readString();
}
Serial.println(test);
}
I guess it is not that difficult to understand. However now the arduino will always print a "#" instead of the variable test. My connected serial device is a bluetooth modul. (hc-06)
What did i do wrong?
Thank you!
(i also ran this code in the arduino emulator 123D Circuits. There it worked just fine)
You need change your code. Move println into if statement.
Try increase timeout interval, 2ms is not enough, good value (at 9600) lies above 10ms. Theoretically timeout should be at least 3.5 characters long and for current speed this equals ~0,4 ms. But in practice higher values are used.
String test;
void setup(){
Serial.begin(9600);
Serial.setTimeout(10);// or more
test = "null";
}
void loop(){
if(Serial.available()){
test = Serial.readString();
Serial.println(test);// moved into if
}
}
Update: Another simple solution to return characters back looks like:
void loop(){
if(Serial.available()) Serial.write(Serial.read());
}
Update 2: Had similar issue with BLE module HM10 (clone, not official). It was sending about 15 dummy bytes prior to any array. And i didn't solve it. But if weired bytes always the same you can make a simple trick using String.remove():
if(Serial.available()){
test = Serial.readString();
test.remove(0,5);
// test.remove - add code to remove last character
Serial.println(test);
}
Also try another terminal.

Resources