Code
Code
code:-
void setup() {
Serial.begin(9600);
void loop() {
Serial.println("Hello, World!");
delay(1000);
2.LED INTERFACE
// Define the pin where the LED is connected
void setup() {
pinMode(ledPin, OUTPUT);
void loop() {
digitalWrite(ledPin, HIGH);
delay(1000);
// Turn the LED off by making the voltage LOW
digitalWrite(ledPin, LOW);
delay(1000);
void setup() {
Serial.begin(9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
void loop() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Read the echoPin, which is HIGH for the duration of the pulse
Serial.print("Distance: ");
Serial.print(distance);
Serial.println(" cm");
delay(500);
#include <Adafruit_MS_PWMServoDriver.h>
#include <utility/imumaths.h>
void setup() {
Serial.begin(9600);
pwm.begin();
delay(500);
void loop() {
runMotorForward();
delay(delayTime);
runMotorBackward();
delay(delayTime);
stopAllMotors();
delay(delayTime);
void runMotorForward() {
void runMotorBackward() {
void stopAllMotors() {
b.main code
#include <Wire.h>
#include <Adafruit_MS_PWMServoDriver.h>
// Define motor control pins (adjust based on your motor shield setup)
const int motorSpeed = 4095; // Max speed (0-4095 for the Adafruit Motor Shield)
void setup() {
Serial.begin(9600);
pwm.begin();
pinMode(leftSensorPin, INPUT);
pinMode(rightSensorPin, INPUT);
delay(500);
void loop() {
moveForward();
turnRight();
turnLeft();
} else {
stopAllMotors();
delay(delayTime);
void moveForward() {
pwm.setPWM(motor1Forward, 0, motorSpeed);
pwm.setPWM(motor1Backward, motorSpeed, 0);
pwm.setPWM(motor2Forward, 0, motorSpeed);
void turnRight() {
pwm.setPWM(motor1Backward, 0, motorSpeed);
pwm.setPWM(motor2Forward, 0, motorSpeed);
void turnLeft() {
pwm.setPWM(motor1Forward, 0, motorSpeed);
pwm.setPWM(motor2Backward, 0, motorSpeed);
void stopAllMotors() {
pwm.setPWM(motor1Forward, 0, 0);
pwm.setPWM(motor1Backward, 0, 0);
pwm.setPWM(motor2Forward, 0, 0);
pwm.setPWM(motor2Backward, 0, 0);
6.AI GLOVE
a.FLEXSENSOR
const int flexSensorPin = A0; // Analog pin connected to the flex sensor
void setup() {
Serial.begin(9600); // Initialize serial communication at 9600 bps
void loop() {
`#include <DFRobotDFPlayerMini.h>
#include "mp3tf16p.h"
void setup() {
Serial.begin(9600);
mp3.initialize();
mp3.playTrackNumber(1, 30);
void loop() {
10 - TX
11 - RX
#include "mp3tf16p.h"
void setup() {
Serial.begin(9600);
mp3.initialize();
mp3.playTrackNumber(3, 30);
void loop() {
10 - RX
11 - TX
#include <DFRobotDFPlayerMini.h>
#include "mp3tf16p.h"
const int flexPin1 = A1; // Pin for the first flex sensor
const int flexPin2 = A2; // Pin for the second flex sensor
const int flexPin3 = A3; // Pin for the third flex sensor
const int flexPin4 = A4; // Pin for the fourth flex sensor
void setup() {
Serial.begin(9600);
mp3.initialize();
void loop() {
int flexValue1 = analogRead(flexPin1); // Read value from the first flex sensor
int flexValue2 = analogRead(flexPin2); // Read value from the second flex sensor
int flexValue3 = analogRead(flexPin3); // Read value from the third flex sensor
int flexValue4 = analogRead(flexPin4); // Read value from the fourth flex sensor
Serial.println(flexValue1);
Serial.println(flexValue2);
Serial.println(flexValue3);
Serial.println(flexValue4);
void setup() {
void loop() {
int sensorValue = digitalRead(waterSensorPin); // Read the value from the water sensor
if (sensorValue == HIGH) {
// Water detected
Serial.println("Water detected!");
} else {
// No water detected
b.ULTRA SONIC
const int trigPin = 9; // Digital pin connected to the TRIG pin of the sensor
const int echoPin = 10; // Digital pin connected to the ECHO pin of the sensor
void setup() {
void loop() {
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
Serial.print("Distance: ");
Serial.print(distance);
Serial.println(" cm");
delay(500); // Wait for 500 milliseconds before taking the next reading
c.main code
#include <DFRobotDFPlayerMini.h>
#include "mp3tf16p.h"
long duration;
int distance;
// MP3 Player
void setup() {
Serial.begin(9600);
pinMode(waterLevelPin, INPUT);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
mp3.initialize();
void loop() {
waterLevelValue = analogRead(waterLevelPin);
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
Serial.print(waterLevelCm);
Serial.println(" cm");
Serial.print("Distance: ");
Serial.print(distance);
Serial.println(" cm");
if (waterLevelCm >10) {
}
// Delay before next iteration
a. Pluse sensor
#include <PulseSensorPlayground.h> // Include the PulseSensor library
const int pulsePin = A0; // Analog pin connected to the pulse sensor
const int threshold = 550; // Threshold for detecting heartbeat (might need
adjustment)
PulseSensorPlayground pulseSensor;
void setup() {
void loop() {
if (pulseSensor.sawStartOfBeat()) {
if (bpm > 0) {
// Print the original BPM and the mapped value to the Serial Monitor
Serial.print("BPM: ");
Serial.print(bpm);
Serial.println(mappedValue);
b.Lcd interface
Serial.print("Temperature: ");
Serial.print(temp);
Serial.println(" °C");
#include <LiquidCrystal_I2C.h>
// Constants for Pulse Sensor
const int pulsePin = A1; // Pulse Sensor analog output connected to analog pin A1
// LCD setup
LiquidCrystal_I2C lcd(0x27, 16, 2); // set the LCD address to 0x27 for a 16 chars and
2 line display
void setup() {
Serial.begin(9600);
// Initialize LCD
lcd.init();
lcd.backlight();
lcd.clear();
void loop() {
// Map the sensor value to a BPM range (adjust these values based on your
sensor)
Serial.print(sensorValue);
Serial.println(bpmValue);
// Now read the temperature sensor
Serial.print("Temperature: ");
Serial.print(temp);
Serial.println(" °C");
// Display on LCD
lcd.setCursor(0, 0);
lcd.print("Pulse: ");
lcd.print(bpmValue);
lcd.print(" BPM");
lcd.setCursor(0, 1);
lcd.print("Temp: ");
lcd.print(temp);
lcd.print(" C");
lcd.clear();
const int trigPin = A1; // Trig pin of the ultrasonic sensor (connected to A1)
const int echoPin = A0; // Echo pin of the ultrasonic sensor (connected to A0)
long duration;
int distance_cm;
void setup() {
void loop() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
// Set the trigPin high for 10 microseconds to send the ultrasonic pulse
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Read the echoPin (A0), which returns the duration of the pulse in microseconds
Serial.print("Distance: ");
Serial.print(distance_cm);
Serial.println(" cm");
// Check if the distance is below 30 cm
digitalWrite(relayPin, HIGH);
} else {
digitalWrite(relayPin, LOW);
AF_DCMotor motor1(1,MOTOR12_1KHZ);
AF_DCMotor motor2(2,MOTOR12_1KHZ);
AF_DCMotor motor3(3,MOTOR34_1KHZ);
AF_DCMotor motor4(4,MOTOR34_1KHZ);
Servo myservo;
int distance=250;
int speedSet=0;
boolean goesForward=false;
void setup() {
myservo.attach(10);
myservo.write(90);
delay(2000);
distance=readDistance();
delay(100);
moveForward();
void loop() {
int dist_R = 0;
int dist_L = 0;
delay(100);
if(distance<=25){
moveStop();
delay(100);
moveBackward();
delay(200);
moveStop();
delay(100);
dist_R = right_Distance();
delay(100);
dist_L = left_Distance();
delay(100);
moveStop();
else{
turnRight();
moveStop();
else{
moveForward();
distance = readDistance();
int left_Distance(){
myservo.write(170);
delay(500);
delay(100);
myservo.write(90);
return dist;
delay(100);
int right_Distance(){
myservo.write(10);
delay(500);
myservo.write(90);
return dist;
delay(100);
int readDistance(){
int cm = ultra_sonic.ping_cm();
cm=250;
return cm;
void moveStop() {
motor1.run(RELEASE);
motor2.run(RELEASE);
motor3.run(RELEASE);
motor4.run(RELEASE);
void moveForward() {
if(!goesForward)
goesForward=true;
motor1.run(FORWARD);
motor2.run(FORWARD);
motor3.run(FORWARD);
motor4.run(FORWARD);
for (speedSet = 0; speedSet < Max_Speed; speedSet +=2) // slowly bring the
speed up to avoid loading down the batteries too quickly
motor1.setSpeed(speedSet);
motor2.setSpeed(speedSet);
motor3.setSpeed(speedSet);
motor4.setSpeed(speedSet);
delay(5);
void moveBackward() {
goesForward=false;
motor1.run(BACKWARD);
motor2.run(BACKWARD);
motor3.run(BACKWARD);
motor4.run(BACKWARD);
for (speedSet = 0; speedSet < Max_Speed; speedSet +=2) // slowly bring the
speed up to avoid loading down the batteries too quickly
motor1.setSpeed(speedSet);
motor2.setSpeed(speedSet);
motor3.setSpeed(speedSet);
motor4.setSpeed(speedSet);
delay(5);
}
void turnRight() {
motor1.run(FORWARD);
motor2.run(FORWARD);
motor3.run(BACKWARD);
motor4.run(BACKWARD);
delay(500);
motor1.run(FORWARD);
motor2.run(FORWARD);
motor3.run(FORWARD);
motor4.run(FORWARD);
void turnLeft() {
motor1.run(BACKWARD);
motor2.run(BACKWARD);
motor3.run(FORWARD);
motor4.run(FORWARD);
delay(500);
motor1.run(FORWARD);
motor2.run(FORWARD);
motor3.run(FORWARD);
motor4.run(FORWARD);
void setup() {
Serial.begin(115200);
WiFi.begin(ssid, password);
delay(500);
Serial.print(".");
Serial.println("");
Serial.println("Connected to WiFi");
Serial.println(WiFi.localIP());
void loop() {
#include <DFRobotDFPlayerMini.h>
#include "mp3tf16p.h"
const int flexPin1 = A0; // Pin for the first flex sensor
const int flexPin2 = A1; // Pin for the second flex sensor
const int flexPin3 = A2; // Pin for the third flex sensor
const int flexPin4 = A3; // Pin for the fourth flex sensor
Serial.begin(9600);
mp3.initialize();
void loop() {
int flexValue1 = analogRead(flexPin1); // Read value from the first flex sensor
int flexValue2 = analogRead(flexPin2); // Read value from the second flex sensor
int flexValue3 = analogRead(flexPin3); // Read value from the third flex sensor
int flexValue4 = analogRead(flexPin4); // Read value from the fourth flex sensor
Serial.println(flexValue1);
Serial.println(flexValue2);
Serial.println(flexValue3);
Serial.println(flexValue4);
} else {
}
if (flexValue4 > 800 &&
#include <DFRobotDFPlayerMini.h>
#include "mp3tf16p.h"
const int flexPin1 = A0; // Pin for the first flex sensor
const int flexPin2 = A1; // Pin for the second flex sensor
const int flexPin3 = A2; // Pin for the third flex sensor
const int flexPin4 = A3; // Pin for the fourth flex sensor
bool mode = true; // true for Mode 1 (LED), false for Mode 2 (Sound)
void setup() {
Serial.begin(9600);
mp3.initialize();
void loop() {
Serial.println(flexValue1);
Serial.println(flexValue2);
Serial.println(flexValue3);
Serial.println(flexValue4);
if (flexValue1 > 800 && flexValue2 > 800 && flexValue3 > 800 && flexValue4 > 800) {
if (mode) {
} else {
else {
if (flexValue1 > 800 && !(flexValue2 > 800 || flexValue3 > 800 || flexValue4 > 800)) {
mp3.playTrackNumber(1, 30);
delay(500);
}
if (flexValue2 > 800 && !(flexValue1 > 800 || flexValue3 > 800 || flexValue4 > 800)) {
mp3.playTrackNumber(2, 30);
delay(500);
if (flexValue3 > 800 && !(flexValue1 > 800 || flexValue2 > 800 || flexValue4 > 800)) {
mp3.playTrackNumber(3, 30);
delay(500);
if (flexValue4 > 800 && !(flexValue1 > 800 || flexValue2 > 800 || flexValue3 > 800)) {
mp3.playTrackNumber(4, 30);
delay(500);
#include <DFRobotDFPlayerMini.h>
#include "mp3tf16p.h"
bool mode = true; // true for Home Automation, false for DFPlayer Mini mode
void setup() {
Serial.begin(9600);
mp3.initialize();
void loop() {
Serial.println(flexValueBulb);
Serial.println(flexValueMotor);
Serial.println(flexValueBuzzer);
Serial.println(flexValueLed);
if (flexValueBulb > flexThreshold && flexValueMotor > flexThreshold && flexValueBuzzer >
flexThreshold && flexValueLed > flexThreshold) {
unsigned long currentTime = millis();
if (mode) {
if (!bulbState) {
Serial.println("Bulb ON");
} else {
Serial.println("Bulb OFF");
}
// Motor control with flex sensor
if (!motorState) {
Serial.println("Motor ON");
} else {
Serial.println("Motor OFF");
if (!buzzerState) {
Serial.println("Buzzer ON");
} else {
Serial.println("Buzzer OFF");
}
if (!ledState) {
Serial.println("LED ON");
} else {
Serial.println("LED OFF");
else {
delay(500);
delay(500);
delay(500);
delay(500);
#include "mp3tf16p.h"
#include <RH_ASK.h>
#include <SPI.h>
MP3Player mp3(10, 11); // DFPlayer Mini: RX=10, TX=11
// Flex sensors
void setup() {
Serial.begin(9600);
if (!driver.init()) {
while (1);
Serial.println("Transmitter Ready");
mp3.begin();
void loop() {
mp3.playTrackNumber(1, 30);
delay(500);
mp3.playTrackNumber(2, 30);
delay(500);
mp3.playTrackNumber(3, 30);
delay(500);
mp3.playTrackNumber(4, 30);
delay(500);
driver.waitPacketSent();
#include <RH_ASK.h>
#include <SPI.h>
void setup() {
Serial.begin(9600);
if (!driver.init()) {
Serial.println("ASK Receiver Init Failed");
while (1);
Serial.println("Receiver Ready");
pinMode(relayPinBulb, OUTPUT);
pinMode(relayPinMotor, OUTPUT);
pinMode(buzzerPin, OUTPUT);
pinMode(ledPin, OUTPUT);
void loop() {
uint8_t buf[RH_ASK_MAX_MESSAGE_LEN];
// Receive message
if (driver.recv(buf, &buflen)) {
buf[buflen] = '\0';
Serial.println((char *)buf);
void homeAutomation() {
while (true) {
digitalWrite(relayPinBulb, HIGH);
bulbState = true;
Serial.println("Bulb ON");
delay(500);
digitalWrite(relayPinMotor, HIGH);
motorState = true;
Serial.println("Motor ON");
delay(500);
}
if (flexValueBuzzer > 800 && !buzzerState) {
digitalWrite(buzzerPin, HIGH);
buzzerState = true;
Serial.println("Buzzer ON");
delay(500);
digitalWrite(ledPin, HIGH);
ledState = true;
Serial.println("LED ON");
delay(500);