Start a new topic

SW-420 display information in nextion

Hi! How to get information from nekstion SW-420 sensor?

  

// Arduino code is available to download - link below the video

/* Vibration sensor connected to Arduino pins as follows:
 Arduino            Vibration Sensor
   D9                    DOut
   GND                   GND
   +5V                   VCC     
   
   D13                Indication LED   
*/

//int ledPin = 13;
int EP =9;

void setup(){
//  pinMode(ledPin, OUTPUT);
  pinMode(EP, INPUT); //set EP input for measurment
  Serial.begin(9600); //init serial 9600
  Serial.println("----------------------Vibration demo------------------------");
}
void loop(){
  long measurement =TP_init();
  delay(1000);
  Serial.print("measurment = ");
  Serial.println(measurement);
  if (measurement > 1000){
//    digitalWrite(ledPin, HIGH);
  }
  else{
//    digitalWrite(ledPin, LOW); 
  }
}

long TP_init(){
  delay(10);
  long measurement=pulseIn (EP, HIGH);  //wait for the pin to get HIGH and returns measurement
  return measurement;
}

  


Sorry Vladimir70


I am not understanding your question. 


Please try to clarify what you are asking.

Posting Instructable SW-420 code does not make your question more clear.


aBbW-ksSTUEg2BoOuu70ds4_ZeNDUAOnzQ.jpg


You will need IteadLib Arduino Nextion Library located

https://github.com/itead/ITEADLIB_Arduino_Nextion


The Nextion would accept t155.txt="1156" and t155.txt="101331" over serial

convert message to string

use SendCommand()


You will need to learn the IteadLib


But more important,

when measurement > 1000 .. vibration has occurred - set an alarm

when measurement < 1000 .. no vibration - clear an alarm


It would make more sense if when measurement > 1000 then send t155.bco=32768  // turn button RED





Where is the mistake?

 

int EP =9;
#include <Nextion.h>
SoftwareSerial nextion(2, 3);// Nextion TX to pin 2 and RX to pin 3 of Arduino

Nextion myNextion(nextion, 9600);

void setup(){

  pinMode(EP, INPUT); 
  Serial.begin(9600); 
  Serial.println();
}
void loop(){
  long measurement =TP_init();
  delay(100);
  Serial.print("measurment = ");
  Serial.println(measurement);
  if (measurement > 1000){
//    digitalWrite(ledPin, HIGH);
  }
  else{
//    digitalWrite(ledPin, LOW); 
  }
}

long TP_init(){
  delay(10);
  long measurement = pulseIn(EP, HIGH);
  
  return measurement;
long h = pulseIn(EP, HIGH);
myNextion.setComponentText("t155", String(h));  
}

 

Sorry, I am not an Arduino guru.


try adding at line 6

char buffer[12] = {0};


try replacing line 31 with

itoa(measurement,buffer,10)


try replacing line 32 with

myNextion.SendCommand("t155"+buffer);


I am not 100% certain

 Thinking it might be closer to this

#include <SoftwareSerial.h>

int EP =9;
SoftwareSerial nextion(2, 3);// Nextion TX to pin 2 and RX to pin 3 of Arduino


void setup(){
  pinMode(EP, INPUT); 
  Serial.begin(9600); 
  Serial.println();
  nextion.begin(9600);
}

void loop(){
  long measurement =TP_init();
  delay(100);
  Serial.print("measurement = ");
  Serial.println(measurement);
  itoa(measurement,buffer,10);


  if (measurement > 1000){
//    digitalWrite(ledPin, HIGH);
   nextion.print("t155.txt=\""+buffer+"\"");
   nextion.write(0xFF);
   nextion.write(0xFF);
   nextion.write(0xFF);
 }
  else{
//    digitalWrite(ledPin, LOW); 
   nextion.print("t155.txt=\"\"");
   nextion.write(0xFF);
   nextion.write(0xFF);
   nextion.write(0xFF);
 }
}

long TP_init(){
  delay(10);
  long measurement = pulseIn(EP, HIGH);
  return measurement;
}

 


 

itoa(measurement,buffer,10);

 

'buffer' was not declared in this scope

try for line 5

char buffer[10] = {0};


 

  nextion.print("t155.txt=\""+buffer+"\"");

 invalid operands of types 'const char [11]' and 'char [10]' to binary 'operator+'

 Thank you, my friend for your help!

#include <SoftwareSerial.h>
#include <Nextion.h>
int EP =9;
SoftwareSerial nextion(2, 3);// Nextion TX to pin 2 and RX to pin 3 of Arduino
Nextion myNextion(nextion, 9600); 
char buffer[10] = {0};

void setup(){
  pinMode(EP, INPUT); 
  Serial.begin(9600); 
  Serial.println();
  nextion.begin(9600);
}

void loop(){
  long h4 = pulseIn (EP, HIGH);
  long measurement =TP_init();
  delay(100);
  Serial.print("measurement = ");
  Serial.println(measurement);
  itoa(measurement,buffer,10);


  if (measurement > 1000){
//    digitalWrite(ledPin, HIGH);
   myNextion.setComponentText("t155", String(h4));
   nextion.write(0xFF);
   nextion.write(0xFF);
   nextion.write(0xFF);
 }
  else{
//    digitalWrite(ledPin, LOW); 
  myNextion.setComponentText("t155", String(h4));
   nextion.write(0xFF);
   nextion.write(0xFF);
   nextion.write(0xFF);
 }
}

long TP_init(){
  delay(10);
  long measurement = pulseIn(EP, HIGH);
  return measurement;
}

 

How to make? If the T155, for example, more than 5000 --- Page 12 that pops up

c7rgnn4T72fWTJQrcytYslUQuwceJIQwUQ.jpg


Login or Signup to post a comment