so, i am curently working on a project that requires arduino to connect with node mcu. but everytime i compile the code it turns out to be an error. can someone explain what i did wrong ? it will be so helpfull because the deadline is this saturday, thanks in advice!
heres the code
#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>
#include <SoftwareSerial.h>
#include <Servo.h> //servo library
Servo servo;
SoftwareSerial s(3,4);
const int en = 2, rw = 1, rs = 0, d4 = 4, d5 = 5, d6 = 6, d7 = 7, bl = 3;
const int i2c_addr = 0x27;
LiquidCrystal_I2C lcd(i2c_addr, en, rw, rs, d4, d5, d6, d7, bl, POSITIVE);
int trigPin = 5;
int echoPin = 6;
int servoPin = 7;
int led= 10;
long duration, dist, average;
long aver[3]; //array for average
int data;
void setup() {
lcd.begin(16,2);
s.begin(9600);
Serial.begin(9600);
servo.attach(servoPin);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
servo.write(0); //close cap on power on
delay(100);
servo.detach();
}
void measure() {
digitalWrite(10,HIGH);
digitalWrite(trigPin, LOW);
delayMicroseconds(5);
digitalWrite(trigPin, HIGH);
delayMicroseconds(15);
digitalWrite(trigPin, LOW);
pinMode(echoPin, INPUT);
duration = pulseIn(echoPin, HIGH);
dist = (duration/2) / 29.1; //obtain distance
}
void sensor() {
for (int i=0;i<=2;i++) { //average distance
measure();
aver[i]=dist;
delay(10); //delay between measurements
}
dist=(aver[0]+aver[1]+aver[2])/3;
if ( dist<10 ) {
//Change distance as per your need
servo.attach(servoPin);
delay(1);
servo.write(0);
delay(800);
for (int i=0;i<=2;i++) { //average distance
measure();
aver[i]=dist;
delay(10); //delay between measurements
}
dist=(aver[0]+aver[1]+aver[2])/3;
if ( dist<10 ) {
//Change distance as per your need
servo.attach(servoPin);
delay(1);
servo.write(150);
delay(800);
servo.detach();
}
Serial.print(dist);
}}
void baru(){
s.write("s");
data=s.read();
if (data == 1){
lcd.clear();
lcd.setCursor(0,0);
lcd.print(" MINYAK JELANTAH");
lcd.setCursor(0,1);
lcd.print(" KOSONG 0% ");
}
if (data == 2){
lcd.clear();
lcd.setCursor(0,0);
lcd.print(" MINYAK JELANTAH");
lcd.setCursor(0,1);
lcd.print(" TERISI 25% ");
}
if (data == 3){
lcd.clear();
lcd.setCursor(0,0);
lcd.print(" MINYAK JELANTAH");
lcd.setCursor(0,1);
lcd.print(" TERISI 50% ");
}
if (data == 4){
lcd.clear();
lcd.setCursor(0,0);
lcd.print(" MINYAK JELANTAH");
lcd.setCursor(0,1);
lcd.print(" TERISI 75% ");
}
if (data == 5){
lcd.clear();
lcd.setCursor(0,0);
lcd.print(" MINYAK JELANTAH");
lcd.setCursor(0,1);
lcd.print(" PENUH 100% ");
}
Serial.println(data);
}
void loop() {
measure();
sensor();
baru();
}
and heres the error
C:\Users\Fayyaza\AppData\Local\Temp\ccEVPhes.ltrans0.ltrans.o:(.rodata+0x6): undefined reference to Print::write(unsigned char const*, unsigned int)' C:\Users\Fayyaza\AppData\Local\Temp\ccEVPhes.ltrans0.ltrans.o:(.rodata+0x2a): undefined reference to Print::write(unsigned char const*, unsigned int)'
C:\Users\Fayyaza\AppData\Local\Temp\ccEVPhes.ltrans0.ltrans.o:(.rodata+0x3e): undefined reference to Print::write(unsigned char const*, unsigned int)' c:/program files (x86)/arduino/hardware/tools/avr/bin/../lib/gcc/avr/7.3.0/../../../../avr/lib/avr5/crtatmega328p.o:(.init9+0x0): undefined reference to main'
collect2.exe: error: ld returned 1 exit status
exit status 1
Error compiling for board Arduino Uno.