Search This Blog

Saturday, 22 April 2023

interfacing ph sensor with arduino


You will need to connect the pH sensor to the Arduino board and configure the pins accordingly. Refer to the documentation of your pH sensor for more information on how to do this.

Note that this is just a sample code and may need to be modified depending on your specific requirements.


// Libraries

#include <LiquidCrystal.h>     // Liquid Crystal library for display

#include <Wire.h>              // I2C protocol library

#include <SparkFun_PH_EC_Salinity.h> // pH sensor library


// Objects

LiquidCrystal lcd(12, 11, 5, 4, 3, 2); // LCD pins

PH_EC_Salinity ph;           // pH sensor object


// Variables

float pHValue = 0.0;         // pH value variable


void setup() {

  // Initialize LCD

  lcd.begin(16, 2);

  lcd.clear();

  lcd.setCursor(0,0);

  lcd.print("pH Sensor Test");

  

  // Initialize pH sensor

  ph.begin();

}


void loop() {

  // Read pH value

  pHValue = ph.getPH();

  

  // Display pH value on LCD

  lcd.setCursor(0,1);

  lcd.print("pH: ");

  lcd.print(pHValue, 2);

  

  // Wait for 1 second

  delay(1000);

}


To use this code, you will need to install the following libraries:

Friday, 21 April 2023

DC motor, working and explanation

A DC (direct current) motor is a type of electrical machine that converts electrical energy into mechanical energy. It operates on the principle of Lorentz force, which is the interaction between a magnetic field and an electric current. A DC motor consists of two main parts: a stator (stationary part) and a rotor (rotating part).

The stator of a DC motor contains a set of electromagnets arranged in a circular pattern around the rotor. These electromagnets are powered by a DC power supply, which creates a magnetic field. The rotor, on the other hand, contains a set of conductors that are arranged to form a loop. When a current is passed through these conductors, they experience a force due to the interaction with the magnetic field, which causes the rotor to rotate.

The direction of rotation of the rotor is determined by the direction of the current in the conductors, as well as the polarity of the magnetic field created by the stator. To ensure continuous rotation, the current in the conductors needs to be reversed every half-cycle, which is achieved by using a commutator.


A commutator is a mechanical device that consists of a set of copper segments connected to the conductors of the rotor. As the rotor rotates, the segments come into contact with brushes (made of carbon or graphite), which are connected to the power supply. The commutator reverses the direction of the current in the conductors every time they pass through the neutral point of the magnetic field, which ensures that the rotor continues to rotate in the same direction.

DC motors are widely used in a variety of applications, such as electric vehicles, industrial machinery, and household appliances. They are simple, reliable, and efficient, making them a popular choice for many different types of devices.

IR (infrared ) sensor

 An IR sensor, short for Infrared sensor, is a device that is capable of detecting infrared radiation or heat. It can measure the amount of infrared radiation emitted by an object and convert it into an electrical signal, which can be used for various purposes. IR sensors are widely used in a variety of applications, including remote controls, security systems, and temperature sensors.



How does an IR sensor work?

An IR sensor works by detecting the amount of infrared radiation emitted by an object. Every object emits some level of infrared radiation, which can be detected by an IR sensor. An IR sensor typically consists of an IR emitter and an IR receiver. The emitter emits a beam of infrared radiation, which is then reflected back by the object being detected. The receiver then detects the reflected infrared radiation and converts it into an electrical signal.



Types of IR sensors

There are two main types of IR sensors: active and passive.

Active IR sensors emit infrared radiation and then detect the radiation that is reflected back. This type of IR sensor is commonly used in proximity sensors, which can detect the presence of an object and measure the distance between the sensor and the object.

Passive IR sensors, on the other hand, detect the infrared radiation emitted by an object. This type of IR sensor is commonly used in temperature sensors and motion detectors.

Applications of IR sensors

IR sensors have a wide range of applications. Some of the most common applications include:

  1. Remote controls: IR sensors are commonly used in remote controls for TVs, DVD players, and other electronic devices. The sensor detects the infrared radiation emitted by the remote control and uses it to control the device.

  2. Security systems: IR sensors are commonly used in security systems to detect the presence of intruders. The sensor detects the infrared radiation emitted by a person's body heat and triggers an alarm if the person is detected.

  3. Temperature sensors: IR sensors can be used to measure the temperature of an object without touching it. This makes them ideal for use in applications where contact with the object is not possible or desirable.

  4. Proximity sensors: IR sensors can be used to detect the presence of an object and measure the distance between the sensor and the object. This makes them ideal for use in robotics and automation applications.

Conclusion

IR sensors are versatile devices that can be used in a variety of applications. They work by detecting the amount of infrared radiation emitted by an object and converting it into an electrical signal. IR sensors can be used in remote controls, security systems, temperature sensors, and proximity sensors, among other applications. As technology continues to advance, we can expect to see even more applications for IR sensors in the future.

obstacle avoidance robot using arduino

 Here is the code for making a obstacle avoidance robot using :-

1) l298n motor driver 
2) arduino (any)
3)servo  motor (optional)
4) 2 or 4 dc motors and wheels
5)jumper cables if (needed )
6) breadboard if (needed) 



// Motor driver pins

int ENA = 3; int ENB = 5; int IN1 = 2; int IN2 = 4; int IN3 = 6; int IN4 = 7; // Servo pin int servoPin = 9; // Ultrasonic sensor pins int trigPin = 10; int echoPin = 11; // Distance variables long duration; int distance; void setup() { // Set motor driver pins as outputs pinMode(ENA, OUTPUT); pinMode(ENB, OUTPUT); pinMode(IN1, OUTPUT); pinMode(IN2, OUTPUT); pinMode(IN3, OUTPUT); pinMode(IN4, OUTPUT); // Set servo pin as output pinMode(servoPin, OUTPUT); // Set ultrasonic sensor pins pinMode(trigPin, OUTPUT); pinMode(echoPin, INPUT); // Start serial communication Serial.begin(9600); } void loop() { // Rotate servo to scan area for obstacles for (int i = 0; i <= 180; i += 5) { int angle = map(i, 0, 180, 0, 179); digitalWrite(servoPin, HIGH); delayMicroseconds(500 + angle * 5); digitalWrite(servoPin, LOW); delay(30); duration = pulseIn(echoPin, HIGH); distance = duration * 0.034 / 2; if (distance < 30) { // If obstacle detected, stop and turn digitalWrite(ENA, LOW); digitalWrite(ENB, LOW); digitalWrite(IN1, LOW); digitalWrite(IN2, LOW); digitalWrite(IN3, LOW); digitalWrite(IN4, LOW); delay(500); digitalWrite(ENA, HIGH); digitalWrite(ENB, HIGH); digitalWrite(IN1, HIGH); digitalWrite(IN2, LOW); digitalWrite(IN3, LOW); digitalWrite(IN4, HIGH); delay(1000); } } // Move forward if no obstacles detected digitalWrite(ENA, HIGH); digitalWrite(ENB, HIGH); digitalWrite(IN1, HIGH); digitalWrite(IN2, LOW); digitalWrite(IN3, HIGH); digitalWrite(IN4, LOW); delay(500); }

This code uses a servo motor to scan the area for obstacles and an ultrasonic sensor to measure the distance to any obstacles. If an obstacle is detected within 30 cm, the robot stops and turns for 1 second before continuing to move forward. If no obstacles are detected, the robot moves forward. The L298N motor driver is used to control the two motors.





interfacing ph sensor with arduino

You will need to connect the pH sensor to the Arduino board and configure the pins accordingly. Refer to the documentation of your pH se...