Dustbin code
#include<Servo.h>
int echo=5;
int trig =4;
long duration;
int distance;
Servo myservo;
void setup()
{
pinMode(trig, OUTPUT);
pinMode(echo,INPUT);
[Link](3);
[Link](9600);
void loop()
{
digitalWrite(trig ,LOW);
delayMicroseconds(2);
digitalWrite(trig ,HIGH);
delayMicroseconds(10);
digitalWrite(trig ,LOW);
duration=pulseIn(echo,HIGH);
distance= 0.0343*duration/2;
[Link](distance);
if(distance <100){
for (int i=0;i<=90;i++){
[Link](i);
delay(100);
}
for (int i=100;i>0;i--){
[Link](i);
delay(10);
}
}
}
Speed detector code
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// Initialize the I2C LCD with the default address (usually 0x27 or 0x3F)
LiquidCrystal_I2C lcd(0x27, 16, 2);
#define SENSOR_1_PIN 2 // Pin for first IR sensor (INT0)
#define SENSOR_2_PIN 3 // Pin for second IR sensor (INT1)
volatile unsigned long timeSensor1 = 0;
volatile unsigned long timeSensor2 = 0;
volatile bool sensor1Triggered = false;
volatile bool sensor2Triggered = false;
const float distanceBetweenSensors = 0.1; // Distance between sensors in meters
float speed = 0; // Speed in meters per second (m/s)
void sensor1ISR() {
if (!sensor1Triggered) { // Ensure only the first trigger is recorded
timeSensor1 = micros(); // Record the time of sensor 1 trigger
sensor1Triggered = true;
}
}
void sensor2ISR() {
if (!sensor2Triggered) { // Ensure only the first trigger is recorded
timeSensor2 = micros(); // Record the time of sensor 2 trigger
sensor2Triggered = true;
}
}
void setup() {
// Initialize the LCD
[Link]();
[Link]();
[Link](0, 0);
[Link]("Speed Gun");
delay(2000); // Show the title for 2 seconds
[Link]();
pinMode(SENSOR_1_PIN, INPUT);
pinMode(SENSOR_2_PIN, INPUT);
// Attach interrupt for sensor 1 (INT0) and sensor 2 (INT1)
attachInterrupt(digitalPinToInterrupt(SENSOR_1_PIN), sensor1ISR, RISING);
attachInterrupt(digitalPinToInterrupt(SENSOR_2_PIN), sensor2ISR, RISING);
}
void loop() {
if (sensor1Triggered && sensor2Triggered) {
sensor1Triggered = false;
sensor2Triggered = false;
unsigned long timeDifference = abs(timeSensor2 - timeSensor1); // Time in microseconds
[Link]();
if (timeDifference > 0) {
speed = distanceBetweenSensors / (timeDifference / 1000000.0); // Convert µs to
seconds
[Link](0, 0);
[Link]("Speed:");
[Link](0, 1);
[Link](speed, 2); // Display speed with 2 decimal places
[Link](" m/s");
} else {
[Link](0, 0);
[Link]("Invalid Reading!");
}
}
}
Smart irragtion system
// Pin configuration
const int sensorPin = A0; // Soil moisture sensor analog pin
const int relayPin = 7; // Relay control pin
// Threshold value (adjust based on your sensor readings)
int threshold = 500; // Lower = wetter soil, Higher = drier soil
void setup() {
pinMode(relayPin, OUTPUT);
digitalWrite(relayPin, HIGH); // Relay OFF initially (active LOW)
[Link](9600);
}
void loop() {
int sensorValue = analogRead(sensorPin);
[Link]("Soil Moisture: ");
[Link](sensorValue);
if (sensorValue > threshold) {
// Soil is dry → turn pump ON
digitalWrite(relayPin, LOW);
[Link]("Pump ON");
} else {
// Soil is wet → turn pump OFF
digitalWrite(relayPin, HIGH);
[Link]("Pump OFF");
}
delay(1000); // 1-second delay between readings
}
Wiring Guide:
Soil Moisture Sensor:
o VCC → 5V
o GND → GND
o AO → A0 (Arduino analog pin)
Relay Module:
o VCC → 5V
o GND → GND
o IN → Pin 7 (Arduino digital pin)
Pump: Connect through relay’s NO (Normally Open) and COM terminals.
📌 Tips for Best Results:
Calibrate threshold by checking your sensor’s readings in dry and wet soil.
Use a separate power supply for the pump to avoid damaging the Arduino.
Add a flyback diode if using a mechanical relay for safety.
Rain alarm sensor
#include <Servo.h>
// Initialize Servo and Pin
Servo myservo;
int rainSensor = A0; // Rain sensor analog pin
int sensorValue = 0;
int servoPin = 9;
void setup() {
[Link](servoPin);
pinMode(rainSensor, INPUT);
[Link](9600);
[Link](0); // Initial position
}
void loop() {
// Read analog value (0-1023)
sensorValue = analogRead(rainSensor);
[Link](sensorValue);
// If rain is detected (threshold can be adjusted)
if (sensorValue < 600) {
[Link](90); // Turn servo to 90 degrees
delay(500);
} else {
[Link](0); // Return to 0 degrees
delay(500);
}
delay(100);
}
Components & Wiring
Rain Sensor Module: VCC to 5V, GND to GND, AO to A0.
Servo Motor: Red to 5V, Brown/Black to GND, Orange/Yellow (Signal) to D9.
Functionality: The sensor outputs lower values when wet, triggering the if condition, as
shown in the Techatronic.
Key Adjustments
Threshold: Adjust if (sensorValue < 600) based on testing (lower value = more water
needed).
Sensitivity: Turn the potentiometer on the sensor module to adjust detection sensitivity.
Health monitoring system
// Arduino sketch for health monitoring using MAX30100 and LCD I2C
// Hardware: Arduino Uno, MAX30100 Pulse Oximeter & Heart Rate sensor, I2C 16x2 LCD
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include "MAX30100_PulseOximeter.h"
// Initialize I2C LCD (address 0x27; 16 columns, 2 rows)
LiquidCrystal_I2C lcd(0x27, 16, 2);
// Initialize MAX30100 Pulse Oximeter
PulseOximeter pox;
// Time tracking for updates
uint32_t tsLastReport = 0;
void setup() {
[Link](115200);
[Link]();
// Initialize LCD
[Link]();
[Link]();
[Link](0, 0);
[Link]("Health Monitor");
// Initialize MAX30100 sensor
if (![Link]()) {
[Link]("FAILED to initialize MAX30100 sensor!");
[Link](0, 1);
[Link]("Sensor Error!");
while (1);
} else {
[Link]("MAX30100 initialized.");
}
// Set the pulse oximeter to measure continuously
[Link](MAX30100_LED_CURR_7_6MA);
}
void loop() {
// Update sensor readings
[Link]();
// Print readings every second
if (millis() - tsLastReport > 1000) {
tsLastReport = millis();
float heartRate = [Link](); // Heart rate in BPM
float spO2 = pox.getSpO2(); // Blood oxygen saturation in %
// Display on Serial Monitor
[Link]("Heart Rate: ");
[Link](heartRate);
[Link](" BPM, SpO2: ");
[Link](spO2);
[Link](" %");
// Display on LCD
[Link]();
[Link](0, 0);
[Link]("HR: ");
if (heartRate > 0) [Link](heartRate); else [Link]("--");
[Link](" BPM");
[Link](0, 1);
[Link]("SpO2: ");
if (spO2 > 0) [Link](spO2); else [Link]("--");
[Link](" %");
}
}
Key Points:
1. Libraries:
MAX30100_PulseOximeter for heart rate and SpO2 readings.
LiquidCrystal_I2C for LCD control.
2. Hardware Connections:
MAX30100 VCC → 3.3V, GND → GND, SCL → A5, SDA → A4 (for Arduino Uno).
LCD VCC → 5V, GND → GND, SCL → A5, SDA → A4.
3. LCD Address: 0x27 is common, but use an I2C scanner if unsure.
4. Sensor Calibration: Let the finger rest on the sensor for a few seconds for stable readi
ngs.
5. Error Handling: The code halts if the sensor fails to initialize, avoiding misleading read
ings.
Example Output:
LCD:
HR: 72 BPM
SpO2: 97 %
Serial Monitor:
Heart Rate: 72 BPM, SpO2: 97 %
This code provides a basic health monitoring setup. You can extend it to record data, trigger
alarms, or connect via Bluetooth for more advanced applications.
Change the line that specifies the architecture from architecture=avr to architecture=avr,e
sp8266 or architecture=* to include all architectures. This can help silence the warning wit
hout affecting
Smart dustbin
#include <Servo.h> // Include Servo library
// Pin definitions
const int trigPin = 9; // Ultrasonic sensor trigger pin
const int echoPin = 8; // Ultrasonic sensor echo pin
const int servoPin = 3; // Servo motor control pin
Servo lidServo; // Servo object for dustbin lid
// Distance threshold in centimeters
const int openDistance = 20; // Open lid if object is within 20 cm
const int openAngle = 90; // Lid open position
const int closedAngle = 0; // Lid closed position
// Function to measure distance using ultrasonic sensor
long getDistance() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
long duration = pulseIn(echoPin, HIGH, 30000); // Timeout after 30ms
if (duration == 0) return -1; // No reading
long distance = duration * 0.034 / 2; // Convert to cm
return distance;
}
void setup() {
[Link](9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
[Link](servoPin);
[Link](closedAngle); // Start with lid closed
delay(500);
}
void loop() {
long distance = getDistance();
[Link]("Distance: ");
[Link](distance);
if (distance > 0 && distance <= openDistance) {
// Open lid
[Link](openAngle);
delay(3000); // Keep lid open for 3 seconds
[Link](closedAngle);
delay(500);
}
delay(200); // Small delay to avoid rapid triggering
}
Component Pin Arduino Connection
Servo Motor Yellow Wire Digital Pin 3
Servo Motor Red Wire 5V
Servo Motor Black Wire GND
Ultrasonic
Sensor VCC pin 5V
Ultrasonic
Sensor GND pin GND
Ultrasonic
Sensor Trig pin Digital Pin 9
Ultrasonic
Sensor Echo pin Digital Pin 8
9V Battery Positive Vin
9V Battery Negative GND
WHEEL CHAIR
/*joystic car control project.
* [Link]
*/
#include <AFMotor.h>
#define x A0
#define y A1
#define Speed 180
AF_DCMotor motor1(3);
AF_DCMotor motor2(1);
void setup() {
[Link](9600);
[Link](Speed);
[Link](Speed);
}
void loop() {
int X = analogRead(x);
int Y = analogRead(y);
[Link](X);
[Link]("\t");
[Link](Y);
if (X >= 800) {
[Link](BACKWARD);
[Link](BACKWARD);
} else if (X <= 200) {
[Link](FORWARD);
[Link](FORWARD);
} else if (Y >= 800) {
[Link](FORWARD);
[Link](BACKWARD);
} else if (Y <= 200) {
[Link](BACKWARD);
[Link](FORWARD);
} else {
[Link](RELEASE);
[Link](RELEASE);
}
}
Bluetooth control car
Got it — you want Arduino code for a Bluetooth-controlled car using an Arduino Uno, a motor driver shield,
and 4 DC motors.
I’ll give you a clean, working example that you can adapt for your setup.
⚙️Assumptions for this code:
Motor driver shield: L293D-based Arduino Motor Shield (commonly used).
Bluetooth module: HC-05 or HC-06 connected to Arduino pins 0 (RX) and 1 (TX) or via
SoftwareSerial.
4 DC motors: Two on the left side, two on the right side (wired in pairs to motor shield outputs).
Arduino Code Example
Cpp
Copy code
#include <AFMotor.h> // Adafruit Motor Shield library
// Create motor objects (M1, M2, M3, M4 on shield)
AF_DCMotor motor1(1);
AF_DCMotor motor2(2);
AF_DCMotor motor3(3);
AF_DCMotor motor4(4);
char command;
void setup() {
[Link](9600); // Bluetooth module baud rate
[Link]("Bluetooth Car Ready");
}
void loop() {
if ([Link]() > 0) {
command = [Link]();
[Link](command);
switch (command) {
case 'F': // Forward
[Link](200);
[Link](200);
[Link](200);
[Link](200);
[Link](FORWARD);
[Link](FORWARD);
[Link](FORWARD);
[Link](FORWARD);
break;
case 'B': // Backward
[Link](200);
[Link](200);
[Link](200);
[Link](200);
[Link](BACKWARD);
[Link](BACKWARD);
[Link](BACKWARD);
[Link](BACKWARD);
break;
case 'L': // Left
[Link](150);
[Link](150);
[Link](150);
[Link](150);
[Link](BACKWARD);
[Link](BACKWARD);
[Link](FORWARD);
[Link](FORWARD);
break;
case 'R': // Right
[Link](150);
[Link](150);
[Link](150);
[Link](150);
[Link](FORWARD);
[Link](FORWARD);
[Link](BACKWARD);
[Link](BACKWARD);
break;
case 'S': // Stop
[Link](RELEASE);
[Link](RELEASE);
[Link](RELEASE);
[Link](RELEASE);
break;
}
}
}
📌 How it works:
The Bluetooth app sends single-character commands (F, B, L, R, S).
The Arduino reads these commands via Serial and controls the motors accordingly.
setSpeed() values range from 0–255 (you can adjust for speed control).
If you want, I can also give you two alternative versions:
1. Using L298N driver without shield
2. Using PWM for smooth speed control