This circuit is designed to collect data from an industrial pressure sensor and a GPS module, receive signals from an IR receiver, and display information on an LCD screen. The data is logged to an SD card for record-keeping. The system's operation can be controlled using a rocker switch. An Arduino UNO R4 WiFi serves as the central microcontroller unit, interfacing with the various sensors, the display, and the SD card module. The circuit is powered by a battery pack connected through a Micro USB to Cable (2 Pin).
/*
* This Arduino sketch reads data from a pressure sensor, GPS module, and IR receiver.
* It displays the distance from the ground and temperature on an LCD screen.
* The data is also logged to an SD card along with GPS information.
* The system can be turned on and off using a rocker switch.
*/
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <SD.h>
#include <SPI.h>
#include <SoftwareSerial.h>
// Pin definitions
const int pressureSensorPin = A0;
const int irReceiverPin = 4;
const int rockerSwitchPin = 8;
const int chipSelect = 10;
const int gpsRxPin = 0;
const int gpsTxPin = 1;
// LCD setup
LiquidCrystal_I2C lcd(0x27, 16, 4);
// GPS setup
SoftwareSerial gpsSerial(gpsRxPin, gpsTxPin);
void setup() {
// Initialize serial communication
Serial.begin(9600);
gpsSerial.begin(9600);
// Initialize LCD
lcd.begin();
lcd.backlight();
// Initialize SD card
if (!SD.begin(chipSelect)) {
Serial.println("SD card initialization failed!");
return;
}
Serial.println("SD card initialized.");
// Initialize pins
pinMode(pressureSensorPin, INPUT);
pinMode(irReceiverPin, INPUT);
pinMode(rockerSwitchPin, INPUT);
}
void loop() {
// Check if the rocker switch is on
if (digitalRead(rockerSwitchPin) == HIGH) {
// Read pressure sensor value
int pressureValue = analogRead(pressureSensorPin);
float distance = calculateDistance(pressureValue);
float temperature = readTemperature();
// Read GPS data
String gpsData = readGPSData();
// Display data on LCD
lcd.setCursor(0, 0);
lcd.print("Dist: ");
lcd.print(distance);
lcd.print(" cm");
lcd.setCursor(0, 1);
lcd.print("Temp: ");
lcd.print(temperature);
lcd.print(" C");
// Log data to SD card
logDataToSD(distance, temperature, gpsData);
}
delay(1000); // Delay for 1 second
}
float calculateDistance(int sensorValue) {
// Convert sensor value to distance (example conversion)
return sensorValue * 0.1;
}
float readTemperature() {
// Placeholder for temperature reading logic
return 25.0; // Example temperature
}
String readGPSData() {
String gpsData = "";
while (gpsSerial.available()) {
char c = gpsSerial.read();
gpsData += c;
}
return gpsData;
}
void logDataToSD(float distance, float temperature, String gpsData) {
File dataFile = SD.open("datalog.txt", FILE_WRITE);
if (dataFile) {
dataFile.print("Distance: ");
dataFile.print(distance);
dataFile.print(" cm, Temperature: ");
dataFile.print(temperature);
dataFile.print(" C, GPS: ");
dataFile.println(gpsData);
dataFile.close();
} else {
Serial.println("Error opening datalog.txt");
}
}
This code is responsible for the operation of the Arduino UNO R4 WiFi in the circuit. It initializes the connected components, reads sensor data, displays information on the LCD, and logs data to the SD card. The code includes functions for calculating distance from the pressure sensor reading, reading temperature (placeholder), reading GPS data, and logging data to the SD card. The system's operation can be toggled using the rocker switch.