Adc Programs
Adc Programs
Adc Programs
https://www.circuitbasics.com/how-to-set-up-uart-communication-for-
arduino/
ADC INPUT DATA READ OPERATION
int dValue, analogInputV;
void setup() {
Serial.begin(9600);
}
void loop() {
dValue = analogRead(A0);
Serial.print("Digital value: ");
Serial.print(dValue);
delay(1000);
}
MAP FUNCTION
delay(1000);
}
In the LM35 temperature sensor, 10 mV denotes 1 degree centigrade. So if the voltage value divided
by 10 it will give us output in degree centigrade.
int a = analogRead(A0);
a = a * 4.887;
temperature = a / 10;
int a = analogRead(A0);
a = a * 3.2235;
temperature = a / 10;
//actual Analog to digital converted Value OR Digital Value
int a = analogRead(A0);
// actual Analog Value OR Input Voltage at A0
Vout = a * 4.887;
// actual source voltage
Vin = a * (3000 + 1000) / 1000;
When there is more water (moisture level will be higher), the soil will conduct
more electricity which means that there will be less resistance.
Dry soil conducts electricity poorly, so when there will be less water (moisture
level will be lower), then the soil will conduct less electricity which means that
there will be more resistance.
As soil moisture sensor can be used in both modes analog and digital. Let first
connect it in Analog mode and then we will use it in Digital mode.
void setup() {
Serial.begin(9600);
Serial.println("Reading From the Sensor ...");
delay(2000);
}
void loop() {
output_value = analogRead(sensor_pin);
delay(200);
Serial.print("Moisture : ");
Serial.print(output_value);
Serial.println("%");
delay(1000);
}
void setup() {
pinMode(led_pin, OUTPUT);
pinMode(sensor_pin, INPUT);
}
void loop( ) {
sensor_output = digitalRead(sensor_pin);
if (sensor_output == HIGH) {
digitalWrite(led_pin, HIGH);
}
else {
digitalWrite(led_pin, LOW);
}
delay(1000);
}
ULTRASONIC SENSOR
/ defining pins and variables
long duration;
int distance, led = 3;
const int trigPin = 8, echoPin = 7;
// setup pin mode and begins serial communication with baud rate 9600
void setup() {
pinMode(led, OUTPUT);
digitalWrite(led, LOW);
delay(100);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
Serial.begin(9600);
}
void loop() {
// calling a user defined function "calculateDistance()" which returns distance in
integer form
distance = calculateDistance();
// if distance is less than 2 and greater than 400 print message "Out of Range"
else if (distance < 2 || distance > 400) {
Serial.println("Out of range");
}
}
/* defining a function calculateDistance() of int type, which means it must return the
value of int type.
then set trigger Pin LOW for 2 microseconds, so that no noise present initially
then set trigger Pin HIGH for 10 us, so that ultrasonic sensor transmit a sound wave
of 40KHz for 10 us as in datasheet
then set trigger Pin LOW and immediately without delay call a function pulseIn and
make echo Pin high which returns time and stored in variable duration
then convert it by speed formula and returns the distance where function
calculateDistance() called
*/
int calculateDistance() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = duration * 0.034 / 2;
return distance;
}
DAC PROGRAMS
Build a simple DAC for your Arduino | Arduino Project Hub
Arduino DAC Tutorial: Interfacing MCP4725 12-Bit Digital-to-Analog Converter with Arduino
(circuitdigest.com)