In file included from c:\Users\pgnan\OneDrive\Documents\Arduino\libraries\libraries\Adafruit_ADXL345/Adafruit_ADXL345_U.h:36,
from C:\Users\pgnan\OneDrive\Desktop\5 PROJECTS\esp32_car_manoj\esp32_car_manoj.ino:13:
c:\Users\pgnan\OneDrive\Documents\Arduino\libraries\libraries\Adafruit_BusIO/Adafruit_I2CDevice.h:10:36: error: 'TwoWire' has not been declared
Adafruit_I2CDevice(uint8_t addr, TwoWire *theWire = &Wire);
^~~~~~~
c:\Users\pgnan\OneDrive\Documents\Arduino\libraries\libraries\Adafruit_BusIO/Adafruit_I2CDevice.h:30:3: error: 'TwoWire' does not name a type; did you mean 'TwoWire_h'?
TwoWire *_wire;
^~~~~~~
TwoWire_h
c:\Users\pgnan\OneDrive\Documents\Arduino\libraries\libraries\Adafruit_BusIO/Adafruit_I2CDevice.h:10:56: error: 'Wire' was not declared in this scope
Adafruit_I2CDevice(uint8_t addr, TwoWire *theWire = &Wire);
^~~~
c:\Users\pgnan\OneDrive\Documents\Arduino\libraries\libraries\Adafruit_BusIO/Adafruit_I2CDevice.h:10:56: note: suggested alternative: 'WiFi'
Adafruit_I2CDevice(uint8_t addr, TwoWire *theWire = &Wire);
^~~~
WiFi
exit status 1
Compilation error: exit status 1
#define BLYNK_TEMPLATE_ID "TMPL3a8ZSDJWe"
#define BLYNK_TEMPLATE_NAME "ESP32 IOT EV CAR"
#define BLYNK_AUTH_TOKEN "93FbW2otNFylcf2D0kDVgsIuukwLamyJ"
#include <WiFi.h>
#include <WiFiClientSecure.h>
#include <BlynkSimpleEsp32.h>
#include <DHT.h>
#include <MQ135.h> // Include MQ135 library
#include <Adafruit_Sensor.h>
#include <Adafruit_ADXL345_U.h>
#include <UniversalTelegramBot.h>
char auth[] = "93FbW2otNFylcf2D0kDVgsIuukwLamyJ";
char ssid[] = "IOT";
char pass[] = "1230987654321";
int IN1 = 13;
int IN2 = 12;
int IN3 = 14;
int IN4 = 27;
#define echoPin 5 // attach pin GPIO 18 ON ESP32 to pin Echo of HC-SR04
#define trigPin 4 // attach pin GPIO 5 ON ESP32 to pin Trig of HC-SR04
#define DHTPIN 33 // Pin where the DHT11 is connected
#define DHTTYPE DHT11 // DHT 11
#define MQ135PIN 32 // Pin where the MQ135 is connected
#define FIRE_PIN 18 // Pin where the fire detection sensor is connected
#define CRASH_PIN 15 // Pin where the crash switch is connected
#define ADXL345_ADDRESS (0x53) // I2C address for the ADXL345 accelerometer
#define BOT_TOKEN "7177790916:AAEJPS__PSGZfSAt0YYTQ3VCUghy9rl55BM"
#define CHAT_ID "5131145538"
long duration; // variable for the duration of sound wave travel
float distance; // variable for the distance measurement
#define BOT_MTBS 1000 // mean time between scan messages
unsigned long bot_lasttime; // last time messages' scan has been done
float temperatureC;
float temperatureF;
float humidity;
String orientation; // Declaring orientation as a global variable
WiFiClientSecure secured_client;
UniversalTelegramBot bot(BOT_TOKEN, secured_client);
DHT dht(DHTPIN, DHTTYPE);
MQ135 gasSensor = MQ135(MQ135PIN); // Use MQ135 library
Adafruit_ADXL345_Unified accel = Adafruit_ADXL345_Unified(12345); // Some unique ID for accelerometer
void setup() {
Serial.begin(115200); /* Set the baudrate to 115200 */
pinMode(IN1, OUTPUT);
pinMode(IN2, OUTPUT);
pinMode(IN3, OUTPUT);
pinMode(IN4, OUTPUT);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(FIRE_PIN, INPUT);
pinMode(CRASH_PIN, INPUT_PULLUP); // Internal pull-up resistor for the switch
dht.begin();
// Initialize accelerometer
if (!accel.begin(ADXL345_ADDRESS)) {
Serial.println("Could not find a valid ADXL345 sensor, check wiring!");
while (1);
}
Blynk.begin(auth, ssid, pass, "blynk.cloud", 8080);
secured_client.setCACert(TELEGRAM_CERTIFICATE_ROOT); // Add root certificate for api.telegram.org
}
BLYNK_WRITE(V1) { // Forward button
int buttonState = param.asInt();
if (buttonState == 1) {
// Move Forward
digitalWrite(IN2, HIGH);
digitalWrite(IN4, HIGH);
} else {
// Stop
digitalWrite(IN1, LOW);
digitalWrite(IN2, LOW);
digitalWrite(IN3, LOW);
digitalWrite(IN4, LOW);
}
delay(50);
}
BLYNK_WRITE(V2) { // Backward button
int buttonState = param.asInt();
if (buttonState == 1) {
// Move Backward
digitalWrite(IN1, HIGH);
digitalWrite(IN3, HIGH);
} else {
// Stop
digitalWrite(IN1, LOW);
digitalWrite(IN2, LOW);
digitalWrite(IN3, LOW);
digitalWrite(IN4, LOW);
}
delay(50);
}
BLYNK_WRITE(V3) { // Left button
int buttonState = param.asInt();
if (buttonState == 1) {
// Turn Left
digitalWrite(IN2, HIGH);
digitalWrite(IN3, HIGH);
} else {
// Stop turning
digitalWrite(IN1, LOW);
digitalWrite(IN2, LOW);
digitalWrite(IN3, LOW);
digitalWrite(IN4, LOW);
}
delay(50);
}
BLYNK_WRITE(V4) { // Right button
int buttonState = param.asInt();
if (buttonState == 1) {
// Turn Right
digitalWrite(IN1, HIGH);
digitalWrite(IN4, HIGH);
} else {
// Stop turning
digitalWrite(IN1, LOW);
digitalWrite(IN2, LOW);
digitalWrite(IN3, LOW);
digitalWrite(IN4, LOW);
}
delay(50);
}
void loop() {
Blynk.run();
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = duration * 0.034 / 2;
Serial.print("Distance: ");
Serial.println(distance);
Blynk.virtualWrite(V5, distance); // Send distance data to Blynk
delay(50);
if (distance <= 10) {
Serial.println("Object is behind Robot");
} else {
Serial.println("Object is not behind Robot");
}
// Read temperature and humidity from DHT sensor
float temperature = dht.readTemperature();
float humidityValue = dht.readHumidity(); // Read humidity separately
if (!isnan(temperature) && !isnan(humidityValue)) {
Serial.print("Temperature: ");
Serial.println(temperature);
Serial.print("Humidity: ");
Serial.println(humidityValue);
// Update global variables
temperatureC = temperature;
temperatureF = temperature * 9 / 5 + 32;
humidity = humidityValue;
// Send data to Blynk
Blynk.virtualWrite(V6, temperatureC);
Blynk.virtualWrite(V7, temperatureF);
Blynk.virtualWrite(V8, humidity);
} else {
Serial.println("Failed to read from DHT sensor!");
}
float gasValue = gasSensor.getPPM(); // Use MQ135 library method to get PPM value
Serial.print("Gas Value: ");
Serial.println(gasValue);
int fireStatus = digitalRead(FIRE_PIN);
Serial.print("Fire Status: ");
//Serial.println(fireStatus);
if (fireStatus == HIGH) {
Serial.println("Fire Detected");
} else {
Serial.println("No Fire Detected");
}
int crashStatus = digitalRead(CRASH_PIN);
//Serial.print("Crash Status: ");
//Serial.println(crashStatus);
if (crashStatus == LOW) {
Serial.println("Crash Detected");
} else {
Serial.println("No Crash Detected");
}
// Read data from the ADXL345 accelerometer
sensors_event_t event;
accel.getEvent(&event);
// Calculate the angle using the accelerometer data
float angleX = atan2(event.acceleration.x, event.acceleration.z) * RAD_TO_DEG;
float angleY = atan2(event.acceleration.y, event.acceleration.z) * RAD_TO_DEG;
// Determine orientation as text
if (angleX > 45 && angleX < 135)
{
orientation = "Back";
}
else if (angleX < -45 && angleX > -135)
{
orientation = "Front";
}
else if (angleY > 45 && angleY < 135)
{
orientation = "Right";
}
else if (angleY < -45 && angleY > -135)
{
orientation = "Left";
}
else if (angleX >= 135 || angleX <= -135 || angleY >= 135 || angleY <= -135)
{
orientation = "Flip";
}
else
{
orientation = "Normal";
}
Serial.print("Orientation: ");
Serial.println(orientation);
// Check if it's time to scan for new messages from the Telegram bot
if (millis() - bot_lasttime > BOT_MTBS) {
int numNewMessages = bot.getUpdates(bot.last_message_received + 1);
while (numNewMessages) {
Serial.println("got response");
handleNewMessages(numNewMessages);
numNewMessages = bot.getUpdates(bot.last_message_received + 1);
}
bot_lasttime = millis();
}
}
void handleNewMessages(int numNewMessages) {
Serial.print("handleNewMessages ");
Serial.println(numNewMessages);
for (int i = 0; i < numNewMessages; i++) {
String chat_id = String(bot.messages[i].chat_id);
if (chat_id != CHAT_ID ) {
bot.sendMessage(chat_id, "Unauthorized user", "");
} else {
String text = bot.messages[i].text;
if (text == "/data") {
// Respond with all sensor readings
String msg = "sensor readings.\n";
msg += "Temperature in Celsius: " + String(temperatureC) + "°C\n";
msg += "Temperature in Fahrenheit: " + String(temperatureF) + "°F\n";
msg += "Humidity: " + String(humidity) + "%\n";
msg += "Gas value: " + String(gasSensor.getPPM()) + "\n";
int fireStatus = digitalRead(FIRE_PIN);
msg += "Fire status: " + String(fireStatus == HIGH ? "Detected" : "Not Detected") + "\n";
int crashStatus = digitalRead(CRASH_PIN);
msg += "Crash status: " + String(crashStatus == LOW ? "Detected" : "Not Detected") + "\n";
msg += "Distance: " + String(distance) + "cm\n";
msg += "Orientation: " + orientation + "\n";
bot.sendMessage(chat_id, msg, "");
}
if (text == "/tempC") {
String msg = "Temperature is ";
msg += msg.concat(temperatureC);
msg += "C";
bot.sendMessage(chat_id, msg, "");
}
if (text == "/tempF") {
String msg = "Temperature is ";
msg += msg.concat(temperatureF);
msg += "F";
bot.sendMessage(chat_id, msg, "");
}
if (text == "/humidity") {
String msg = "Humidity is ";
msg += msg.concat(humidity);
msg += "%";
bot.sendMessage(chat_id, msg, "");
}
if (text == "/gas") {
String msg = "Gas value is ";
msg += msg.concat(gasSensor.getPPM());
bot.sendMessage(chat_id, msg, "");
}
if (text == "/fire") {
int fireStatus = digitalRead(FIRE_PIN);
if (fireStatus == HIGH) {
bot.sendMessage(chat_id, "Fire Detected", "");
} else {
bot.sendMessage(chat_id, "No Fire Detected", "");
}
}
if (text == "/crash") {
int crashStatus = digitalRead(CRASH_PIN);
if (crashStatus == LOW) {
bot.sendMessage(chat_id, "Crash Detected", "");
} else {
bot.sendMessage(chat_id, "No Crash Detected", "");
}
}
if (text == "/distance") {
String msg = "Distance is ";
msg += msg.concat(distance);
msg += "cm";
bot.sendMessage(chat_id, msg, "");
}
if (text == "/orientation") {
bot.sendMessage(chat_id, "Orientation is " + orientation, "");
}
if (text == "/start") {
String welcome = "sensor readings.\n";
welcome += "/data : all sensor data \n";
welcome += "/tempC : Temperature in Celsius \n";
welcome += "/tempF : Temperature in Fahrenheit\n";
welcome += "/humidity : Humidity\n";
welcome += "/gas : Gas value\n";
welcome += "/fire : Fire status\n";
welcome += "/crash : Crash status\n";
welcome += "/distance : Distance\n";
welcome += "/orientation : Orientation\n";
bot.sendMessage(chat_id, welcome, "Markdown");
}
}
}
}